Hassy
Hassy

Reputation: 5208

GeoFencing on iOS

I am using GeoFencing to set a region and perform some task when user Enters or Leaves the region. Bt it is not working for me, i am using gollowing code

CLLocationCoordinate2D coord = CLLocationCoordinate2DMake(some values,some values);
    CLRegion *region = [[CLRegion alloc]initCircularRegionWithCenter:coord radius:15.0 identifier:@"SF"];
    [locationManager startMonitoringForRegion:region desiredAccuracy:kCLLocationAccuracyBest];

But None of the delegates didEnterRegion and didExitRegion being called when i close the application and the app is monitoring and i move away from that region or enter.

Upvotes: 1

Views: 5303

Answers (4)

Sanauyar Ali
Sanauyar Ali

Reputation: 1

You define a radius of 15m. That is too small. First, try with 50m or more. Look at the map app, if you really have entered that region. Furthermore, I hope you meant "send to background", instead of closing. make sure you have set your app to be allowed to run in background? (via plist)

Upvotes: 0

Brave Heart
Brave Heart

Reputation: 93

First of all increase the radius you are giving for that particular location and check again if it does not work then by following some easy steps provided in this tutorial you can easily implement Geo-Fencing in your app.

Reference: Apple Documentation

Upvotes: 1

AlexWien
AlexWien

Reputation: 28727

You define a radius of 15m. That is too small. First, try with 50m or more. Look at the map app, if you really have entered that region.
Furthermore, I hope you meant "send to background", instead of closing.
make sure you have set your app to be allowed to run in background? (via plist)

Update:

Finally it turned out that you terminated the application. Then of course you will not get any loctaion events anymore.
Solution: Don't terminate it via double click on home button follwed by selecting the white cross, simply close it with one click on home button, then it has chance to run in background.

Update2: Even when the app was terminated, ios relaunches it when it has registered to the location monitoring service: from CllLocationManager Class Reference

If you start this service and your application is subsequently terminated, the system automatically relaunches the application into the background if a new event arrive...

Upvotes: 3

Cintu
Cintu

Reputation: 913

Add CLLocationManagerDelegate in header file. make sure u added

locationManager.delegate = self;

try increasing the radius and check.

Upvotes: 1

Related Questions