【问题标题】:Geofencing didEnterRegion,didExitRegion function not Calling in iphone 5S iOS8.1地理围栏didEnterRegion,didExitRegion函数未在iphone 5S iOS8.1中调用
【发布时间】:2015-02-15 17:50:30
【问题描述】:

我调试了一整天,委托确实被调用了。

- (void)locationManager:(CLLocationManager *)manager didEnterRegion:(CLRegion *)region

这是我调用监视器的标准代码。使用 CoreLocation.framework。

[locationManager startMonitoringForRegion:geofence];

并在我的 plist 中注册了这些。

<key>NSLocationAlwaysUsageDescription</key>
<string>Lugang</string>
<key>NSLocationWhenInUseUsageDescription</key>
<string>Lugang</string>

启用后台应用刷新,但我没有在其中看到我的应用。

我曾尝试在 LocationManager 的实例中打印我的受监控区域,并且有我的受监控区域。

NSLog(@"%@" ,locationManager.monitoredRegions);

并且 regionMonitoringAvailable 为真。

NSLog(@"%d" , [CLLocationManager regionMonitoringAvailable] );

在 iOS 8 中,我要求 requestAlwaysAuthorization

[locationManager requestAlwaysAuthorization];

我尝试了三种状态,前台应用,后台应用,应用未激活。这些状态都没有调用。

-(void)locationManager:(CLLocationManager *)manager didFailWithError:(NSError *)error

没有发现任何错误。

我试过了

[locationManager requestStateForRegion:geofence];

工作正常。

- (void)locationManager:(CLLocationManager *)manager didDetermineState:(CLRegionState)state forRegion:(CLRegion *)region

确实在我的 requestStateForRegion 中触发。

我不知道是什么让 didEnterRegion 没有被调用,我知道在 iOS 7 及更高版本的设备上工作,但我现在没有这样的设备来作证。

也许 requestStateForRegion 可以满足我的要求,但我仍然无法弄清楚 DidEnterRegion 是如何不起作用的。而且这些都不会触发任何错误消息来告诉开发人员进行调试。

【问题讨论】:

    标签: ios objective-c cllocationmanager


    【解决方案1】:

    我也面临同样的问题,以下是我遵循并获得成功的步骤。

    • locationmanager 中添加地理围栏数组数据后。使用下面的代码。

      for (CLRegion *monitored in [locationManagerGeofence monitoredRegions])
       {
           [locationManagerGeofence stopMonitoringForRegion:monitored];
       }
       self.geofencesArray = [NSMutableArray arrayWithArray:[self buildGeofenceData]];
       if([CLLocationManager regionMonitoringAvailable])
       {
           for (CLRegion *region in self.geofencesArray)
           {
               [locationManagerGeofence startMonitoringForRegion:region desiredAccuracy:kCLLocationAccuracyBest];
           }
       }
       else
       {
           [BB_Global displayAlertWithTitle:@"" message:@"This app requires region monitoring features which are unavailable on this device."];
       }
      
    • 确保您的 wifi 已开启。
    • 检查您对具有以下代表的区域的开始监控。

      -(void)locationManager:(CLLocationManager *)manager didStartMonitoringForRegion:(CLRegion *)region
      {
          NSLog(@"Started monitoring %@ region", region.identifier);
      }
      
    • 使用这两个代理方法进行地理围栏。 1)DidEnter 2)DidExit

    • 通过移动或其他地方测试您的设备(确保将您的地理围栏设置为半径为 100 米的不同位置)。同样,您在 DidEnterDidExit 方法中实现本地通知,因此无需调试。一旦你的方法被调用,本地通知就会被触发。
    • 获得成功:)

    【讨论】:

    • 原来我可能离我所在的地区还不够远,非常感谢!
    • 嘿,任何人都面临这样的问题,例如它在某些设备上不起作用,而不是每个设备。
    猜你喜欢
    • 1970-01-01
    • 2014-09-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-05-08
    • 1970-01-01
    相关资源
    最近更新 更多