【问题标题】:CLLocation Region Monitoring behaves differently in iOS 5.1 and iOS 6CLLocation 区域监控在 iOS 5.1 和 iOS 6 中的行为不同
【发布时间】:2013-02-15 03:11:41
【问题描述】:

更新:我正在 iOS5.1 中寻找解决此问题的方法。目前,我有证据表明这个问题实际上是已知的。但是,我认为这与更新的 xcode 有关,而不是 iOS5.1 实际上区域监控不起作用。

下面的简单代码在 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");
}

【问题讨论】:

    标签: ios5 ios6 core-location cllocationmanager


    【解决方案1】:

    将这个问题搁置一周后,我觉得我有足够的证据表明 iOS5.1 中的区域监控被破坏了。是时候结束这个问题了。

    【讨论】:

      猜你喜欢
      • 2014-09-13
      • 1970-01-01
      • 2013-11-20
      • 2018-05-21
      • 2011-07-17
      • 1970-01-01
      • 2015-12-09
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多