transistorsoft / background-geolocation-lt

Advanced Background Geolocation & Geofencing SDK for iOS & Android
Other
48 stars 19 forks source link

onGeofence event not triggering regularly when multiple geofences aded #45

Closed vrushik closed 4 years ago

vrushik commented 5 years ago

Your Environment

homeviewcontroller.swift

import UIKit
import CoreLocation
import TSLocationManager

var bgGeo = TSLocationManager()
     var geofence = TSGeofence()

    override func viewDidLoad() {
        super.viewDidLoad()
bgGeo = TSLocationManager.sharedInstance()
        bgGeo.start()

        bgGeo.onGeofence({ event in
            let arr = event?.toDictionary()!
            let identifier = arr!["identifier"] as? String
            let action = event?.action
            let aDict: CLLocation? = event?.location.location
            let lat: Double? = aDict?.coordinate.latitude
            let longi: Double? = aDict?.coordinate.longitude

            if identifier == "locationUpdate" && (action == "EXIT") {

                self.updateLocationAPIwith(lat!, longi!)

                DispatchQueue.global(qos: .background).async { [weak self] () -> Void in
                    self?.setGeofencewith(lat!, longi!)
                }
            }
                if identifier == "enroute"{
                    if (action == "EXIT"){                        
                                           self.bgGeoEnroute.removeGeofence("enroute", success: {
  if self.bookingDetilas[key_BookingStatus] as! NSInteger != 5{
                            self.showTimerAlert("ENROUTE")
                        }
                                            }, failure: { error in
                                            })
                    }    
            }
              if identifier == "pickup" && action == "ENTER"{if self.bookingDetilas[key_BookingStatus] as! NSInteger == 1 {
                        let bookingId = String(format: "%d", self.bookingDetilas[key_Id] as! NSInteger)
                        self.makeBookingAPICall(bookingId: bookingId, bookingStatus: "5")
                        setValueToUserDefaults(strKey: key_BookingStatusForAcceptedJob, value: 5 as AnyObject)
                    }else if self.bookingDetilas[key_BookingStatus] as! NSInteger == 5{
                        self.showTimerAlert("ARRIVED")
                    }
                }
                else if identifier == "pickup" && action == "EXIT"{
                                    self.bgGeoPickup.removeGeofence("pickup", success: {
                    if  self.bookingDetilas[key_BookingStatus] as! NSInteger == 2 || self.bookingDetilas[key_BookingStatus] as! NSInteger == 4{
                        self.showTimerAlert("POB")
                    }                                    }, failure: { error in
                                    })
                }
            }
        })
        bgGeo.onMotionChange({ tsLocation in
            //            self.centerAndZoom = tsLocation?.location
        })
        bgGeo.onLocation({ location in
        }, failure: { error in
        })
        bgGeo.ready()
}

Expected Behavior

i using geofence in my project to specify my functionalities like, location update when device is moving not on stationary mode. another one is for show notification for specific location's enter and exit state. one geofence is continuously firing and another when some particular location update

Actual Behavior

when i set first geofence with "locationUpdate" identifier and when device is moving it works but when in stationary mode it doesn't fired. and i set another geofences with different identifiers it doesn't work perfectly. not working as expected.

Steps to Reproduce

1. 2. 3. 4.

Context

i am trying to add multiple geofences as my functionality thats simple

  1. when device moving location must update
  2. multiple geofences should work of specific location with different identifiers. as written in Above code the multiple identifiers are used like "pickup","enroute" and "locationUpdate". but when onGeofence is fired didn't get expected output. for e.g i exited from "pickup" and its showing "enroute". in short its like conflicting geofences

    Debug logs

christocracy commented 5 years ago

What is this??

self.bgGeoEnroute
.
.
.
self.bgGeoPickup

You can't create multiple instances of TSLocationManager -- it's a Singleton.

christocracy commented 5 years ago

And you’re not going to update your post to remove my confusion, I suppose?

stale[bot] commented 4 years ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. You may also mark this issue as a "discussion" and I will leave this open.

stale[bot] commented 4 years ago

Closing this issue after a prolonged period of inactivity. Fell free to reopen this issue, if this still affecting you.