我应该在6和7版本的iOs应用程序中使用区域监控。如果我的应用程序被关闭,那么系统应该打开它。它适用于iOS 6,但不适用于iOS 7。我的意思是,如果应用程序在ios 7中关闭,系统就不会打开我的应用程序。
关于关闭应用程序,我的意思是,从内存中删除这个应用程序。
我使用以下代码:
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];
}
我使用委托方法来记录日志。此外,我还使用此代码进行测试。
if (launchOptions) {
UILocalNotification *note = [UILocalNotification new];
note.alertBody = [NSString stringWithFormat:@"launchOptions = %@", launchOptions];
[[UIApplication sharedApplication] presentLocalNotificationNow:note];
}
发布于 2013-11-13 18:11:26
这是从iOS7开始的预期行为。在iOS6和更早的时候,即使您从应用程序切换器中手动关闭了应用程序,当用户输入/退出某个区域时,仍然会收到通知。这种行为使用iOS7改变了。如果用户已经从应用程序切换器中删除了应用程序,即通过在应用程序上滑动,那么他们将不再收到任何基于位置的通知,包括区域监视通知。苹果的一名员工在苹果开发者论坛( link here )上证实了这一点。
Apple提供的唯一解决方案是“如果此更改对您有问题或您希望看到不同的东西,请提交错误报告。”
我个人认为这是一个糟糕的决定,因为它违背了背景通知的目的。您将不得不建议您的用户从iOS6升级,因为他们将继续期待类似的功能,而且这种更改在任何地方都没有文档记录。
EDIT:正如下面@herz所指出的,从iOS 7.1开始,后台监控功能已经恢复到iOS 6中的状态。即使应用程序从应用程序切换器中关闭,也会监视区域,并且应用程序也会收到通知。
https://stackoverflow.com/questions/19857034
复制相似问题