更新:我正在寻找iOS5.1中此问题的解决方法。目前,我有证据表明这个问题实际上是众所周知的。但是,我认为它与更新的xcode而不是iOS5.1有关,实际上区域监控无法正常工作。
下面的简单代码在iOS5和iOS6之间表现不同。它在iOS6中按预期工作。
但是在iOS5中,只有在第一次输入区域时才会触发didEnterRegion回调。如果退出该区域,然后重新进入该区域,则不会触发该区域。如果您关闭并重新启动应用程序,则进入该区域将不会触发回调。
在iOS5和iOS6模拟器上可以看到行为上的差异。在iOS4的iPhone 4S上看到了破坏的iOS5行为。使用Xcode 4.6。 CoreLocation框架已正确添加,locMan是AppDelegate的属性。为此测试创建了一个干净的新项目。
有人可以找到解决此问题的方法吗?修复需要使用区域监视,而不是主动位置更新。
#import <UIKit/UIKit.h>
#import <CoreLocation/CoreLocation.h>
@interface AppDelegate : UIResponder <UIApplicationDelegate, CLLocationManagerDelegate>
@property (strong, nonatomic) UIWindow *window;
@property (nonatomic, strong) CLLocationManager *locMan;
@end
// AppDelegate implementation file
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
/// LocationManager
self.locMan = [[CLLocationManager alloc] init];
self.locMan.delegate = self;
CLLocationCoordinate2D coordinates = CLLocationCoordinate2DMake(40.0, 40.0);
CLLocationDistance distance = 100.0;
CLRegion *region = [[CLRegion alloc] initCircularRegionWithCenter:coordinates radius:distance identifier:@"hello"];
[self.locMan startMonitoringForRegion:region];
[self.window makeKeyAndVisible];
return YES;
}
-(void)locationManager:(CLLocationManager *)manager didEnterRegion:(CLRegion *)region {
NSLog(@"didEnterRegion");
}
答案 0 :(得分:0)
在将这个问题保持开放一周之后,我觉得我已经有足够的证据证明iOS5.1中的区域监控已被打破。是时候结束这个问题了。