0
更新:我正在寻找iOS5.1中解决此问题的解决方法。目前,我有证据表明这个问题实际上是已知的。但是,我认为它与更新的xcode相关,而不是iOS5.1实际上区域监视不起作用。CLLocation区域监视在iOS 5.1和iOS 6中的行为有所不同
下面的简单代码在iOS5和iOS6之间的行为有所不同。它在iOS6中按预期工作。
但是在iOS5中,didEnterRegion回调仅在第一次输入区域时触发。如果你退出该地区,然后重新进入该地区,它不会被触发。如果关闭并重新启动应用程序,输入区域将不会触发回调。
行为差异在iOS5和iOS6模拟器上出现。在iOS5的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");
}