相关疑难解决方法(0)

didEnterRegion在前台工作,但不在后台或其他VC工作

如果应用程序正在运行且CLLocationManagerDelegate类是前台(即可见),则didEnterRegions触发,我同时获得NSLog以及AlertView.但是,当应用程序在后台时,或者基本上,如果屏幕显示除委托类之外的任何内容,我什么也得不到.

我已经在plist中的"Required background modes"下设置了"App registers for location updates",虽然我不确定是否有必要.

这是我认为相关的代码,虽然我可能是错的(并乐意添加更多).我应该注意viewDidLoad中的所有内容都包含在if中,检查区域监视是否可用并启用.

- (void)viewDidLoad
{
    NSLog(@"MapViewController - viewDidLoad");
    self.locationManager.desiredAccuracy = kCLLocationAccuracyNearestTenMeters;
    self.locationManager.distanceFilter = kCLLocationAccuracyNearestTenMeters;    
    self.locationManager.delegate = self;
    [self.locationManager startMonitoringSignificantLocationChanges];
}

- (void)locationManager:(CLLocationManager *)manager didEnterRegion:(CLRegion *)region
{
    NSLog(@"MapViewController - didEnterRegion");
    NSLog(@"MVC - didEnterRegion - region.radius = %f", region.radius);
    UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"entered region..." message:@"You have Entered the Location." delegate:nil cancelButtonTitle:@"OK"  otherButtonTitles: nil];
    alert.tag = 2;
    [alert show];
}
Run Code Online (Sandbox Code Playgroud)

这是我在AppDelegate.m中获取受监控区域列表的位置:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{

// other code

NSLog(@"LISTING ALL REGIONS MONITORED"); …
Run Code Online (Sandbox Code Playgroud)

cllocationmanager ios region-management clregion

7
推荐指数
1
解决办法
8162
查看次数