Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
591 views
in Technique[技术] by (71.8m points)

objective c - 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];
}
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...