Start location monitoring for all geofences with an in-app callback in swift

I like to start to geofence and I have a call like this to test it:

backendless.geo.startGeofenceMonitoring(geoFenceClientCallback, response: { (AnyObject) -> Void in

            print("ok")

    }) { (fault:Fault!) -> Void in

            print("Fault")


    } 

geoFenceClientCallback is a class following the IGeofenceCallback protocol.

After a while when the app are running (I Guess it is the On Stay event that is triggered since I testing it inside a geofence) it crash with a "*** Terminating app due to uncaught exception of class ‘Fault’

libc++abi.dylib: terminating with uncaught exception of type Fault"

Hi Erik,
Do you have a handler in your code for onStay event?

Only in GeoFenceClientCallback:

class GeoFenceClientCallback: NSObject, IGeofenceCallback {

func geoPointEntered(geofenceName: String, geofenceId: String, latitude: Double, longitude: Double) {

    print("entered")

}

func geoPointStayed(geofenceName: String, geofenceId: String, latitude: Double, longitude: Double) {

    print("stayed")

}



func geoPointExited(geofenceName: String, geofenceId: String, latitude: Double, longitude: Double) {

    print("exited")

}

}

Is it possible for you to send us your project (or some minimal part of it, which can be executed as is) to support@backendless.com, so that we can reproduce this on our side?

Hi Erik,

Unfortunately, we cannot execute “as is” the files you’ve sent.
Please, add the line:

   DebLog.setIsActive(true)

in your project just after backendless.initApp(),
then run your app and send a log to support@backendless.com

Another way is to send your sample project demonstrating the problem, we investigate it and find a solution asap.

Regards,
Slava

Hi, Erik!

Your issue might happen if server onStay action is not configured. The thing is that even through using in-app callback - timeout for onStay event is taken from server.
Try please the following: configure any action for onStay event and repeat your case again.
I have one more question: do you see the result of “geoPointEntered” function execution?
Thank you!
Alex

We recently released latest Backendless SDK with XCode 7.3

You should update libs with CocoaPods (3.0.12 release) or from ios-SDK github (CommLibiOS & backendless).

Then try again your app and let we know how it goes.

I have updated to 3.0.12.

Cant see any callback on the onStay event. I added onStayEvent on serverSide, to get the onStayDuration to be set.

I will try to simulate the onEnter event and see if that works.

<GeoFence> geofenceName:home, onStayDuration:30, type:SHAPE\nnwPoint:<GeoPoint>

Please, provide a log I’ve written about.

2016-03-31 16:34:50.891 Zmart[3135:1088946] LocationTracker -> applicationDidBecomeActive
2016-03-31 16:34:51.936 Zmart[3135:1088946] GeoService -> addFenceMonitoring: callback = <ClientCallback: 0x12fec0cb0>, geoFences = (
“<GeoFence> geofenceName:711_roa, onStayDuration:-1, type:SHAPE\nnwPoint:<GeoPoint> LAT:59.94751805904249, LON:10.64310193061829, distance:0, CATEGORIES:(\n), METADATA:{\n}, objectId = 1B02A58A-E125-76EB-FF98-947B3B802900\nsePoint:<GeoPoint> LAT:59.94724941162492, LON:10.64369738101959, distance:0, CATEGORIES:(\n), METADATA:{\n}, objectId = ECB949AC-0504-B0C8-FF21-D7897D8AC000”,
“<GeoFence> geofenceName:narbutikken_roa, onStayDuration:-1, type:SHAPE\nnwPoint:<GeoPoint> LAT:59.94165248710755, LON:10.64144968986511, distance:0, CATEGORIES:(\n), METADATA:{\n}, objectId = 8FCD19C6-002E-A82A-FF50-38DF3CF19900\nsePoint:<GeoPoint> LAT:59.94132467897507, LON:10.64185738563538, distance:0, CATEGORIES:(\n), METADATA:{\n}, objectId = E44FCE53-73B8-53F9-FFF4-FB6FD6218400”,
“<GeoFence> geofenceName:rema_1000_Roa, onStayDuration:-1, type:SHAPE\nnwPoint:<GeoPoint> LAT:59.93448615130124, LON:10.63861191272736, distance:0, CATEGORIES:(\n), METADATA:{\n}, objectId = F5EB9901-DA04-1B6D-FF94-29D21373DB00\nsePoint:<GeoPoint> LAT:59.93423083598226, LON:10.63923954963684, distance:0, CATEGORIES:(\n), METADATA:{\n}, objectId = 17C20AA5-9298-C85B-FF51-72F3A0D9C900”,
“<GeoFence> geofenceName:Fotballbanen, onStayDuration:-1, type:SHAPE\nnwPoint:<GeoPoint> LAT:59.93830481243524, LON:10.63708305358887, distance:0, CATEGORIES:(\n), METADATA:{\n}, objectId = 7C761507-81D1-89F3-FF28-45499969C300\nsePoint:<GeoPoint> LAT:59.93770018469609, LON:10.63974380493164, distance:0, CATEGORIES:(\n), METADATA:{\n}, objectId = 64038B3A-E07E-C5AB-FF29-EF1E4B32CE00”,
“<GeoFence> geofenceName:Rimi, onStayDuration:30, type:SHAPE\nnwPoint:<GeoPoint> LAT:59.93885241090624, LON:10.63684701919556, distance:0, CATEGORIES:(\n), METADATA:{\n}, objectId = 56FEF996-6945-7E41-FF57-56A5A5A10800\nsePoint:<GeoPoint> LAT:59.93825585479374, LON:10.63963651657104, distance:0, CATEGORIES:(\n), METADATA:{\n}, objectId = FE9AA7CB-1060-C6F8-FF56-7ACB15E15D00”
)
2016-03-31 16:34:51.937 Zmart[3135:1088946] GeoService -> addFenceMonitoring: add listener = GeoFenceMonitoring
ok

And the crash has disappeared?

What goes wrong?

The crash are gone, still no callback when I stay inside a geofence.

I´m not sure what got the crash to disappear. I don´t belive I did any changes on the client side.

I don’t see a log message
“CREATE LocationTracker: sharedLocationTracker = <LocationTracker:”

so, LocationTracker didn’t start.

You could investigate our GeoFence sample (Objective-C). Hope it will be helpful for you how this have to be organized.

And check if your project .plist has all necessary keys (NSLocationAlwaysUsageDescription & ‘Required background modes’):
http://support.backendless.com/public/attachments/9634bbb784639b20a6a2877766c2f4f2.png&lt;/img&gt;

Thanks, that was the missing part. Working perfekt now.