Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Region monitoring in ios 7

I should use region monitoring in my iOs app for 6 and 7 version. And if my app was closed then system should open it. It works in iOS 6, but not works in iOS 7. I mean, System does not open my app if app was closed in ios 7.

About closing app, I mean, kill this app from memory.

I use this code:

manager = [CLLocationManager new];

manager.delegate = self;

[manager startUpdatingLocation];

if ([UIDevice isIOS7OrHigher]) {

    CLCircularRegion *reg = [[CLCircularRegion alloc] initCircularRegionWithCenter:CLLocationCoordinate2DMake(56.844947, 53.208852) radius:20.f identifier:@"reg14132"];

    [manager startMonitoringForRegion:reg];

    CLCircularRegion *reg1 = [[CLCircularRegion alloc] initCircularRegionWithCenter:CLLocationCoordinate2DMake( 56.844158,53.20913) radius:20.f identifier:@"reg14131232"];

    [manager startMonitoringForRegion:reg1];

} else {

    CLRegion *reg = [[CLRegion alloc]  initCircularRegionWithCenter:CLLocationCoordinate2DMake(56.844947, 53.208852) radius:20.f identifier:@"reg14132"];

    [manager startMonitoringForRegion:reg];

    CLRegion *reg1 = [[CLRegion alloc] initCircularRegionWithCenter:CLLocationCoordinate2DMake( 56.844158,53.20913) radius:20.f identifier:@"reg14131232"];
    [manager startMonitoringForRegion:reg1];
}

And I use delegate methods for log. Also, I use this code for test

if (launchOptions) {
    UILocalNotification *note = [UILocalNotification new];
    note.alertBody = [NSString stringWithFormat:@"launchOptions = %@", launchOptions];
    [[UIApplication sharedApplication] presentLocalNotificationNow:note];
}
like image 507
alex_izh Avatar asked Feb 15 '23 17:02

alex_izh


1 Answers

This is now the expected behaviour starting with iOS7. In iOS6 and earlier, even if you manually killed the app from the app-switcher, you would still get a notification when the user entered/exited a region. This behaviour has changed with iOS7. If the user has killed the app from the app-switcher, i.e. by swiping up on your app, then they will no longer receive any location-based notifications, including region monitoring notifications. This was confirmed by an Apple Employee in the official Apple developer forums - link here.

The only solution provided by Apple Dev was "Please file bug reports if this change is problematic for you or you would like to see something different."

I personally think this was a terrible decision, as it defeats the purpose of background notifications. You will have to advise your users upgrading from iOS6, as they will continue to expect similar functionality and this change has not been documented anywhere.

EDIT: As @herz below has pointed out, starting in iOS 7.1, the background monitoring functionality has reverted to how it was in iOS 6. Regions will be monitored and your app will receive notifications even when it is killed from the app switcher.

like image 118
zdestiny Avatar answered Feb 24 '23 12:02

zdestiny