ios – 区域监视背景中的信标区域不工作

ios – 区域监视背景中的信标区域不工作,第1张

概述当应用程序处于后台时,我遇到了区域监控问题. 如果应用程序位于前台,则区域进入和退出会被调用,但在后台时则不会被调用(有时它们会触发但非常罕见). 信标区域监控如何适用于iOS 8.1.1?当在背景中处于Beacon接近时,区域是否应立即进入/退出? 我该怎么做才能确保它有效? 背景模式:位置更新或使用蓝牙LE配件必须打开才能使背景信标监控工作吗? GeoFencing在没有这些的情况下为我工作. 当应用程序处于后台时,我遇到了区域监控问题.
如果应用程序位于前台,则区域进入和退出会被调用,但在后台时则不会被调用(有时它们会触发但非常罕见).

信标区域监控如何适用于iOS 8.1.1?当在背景中处于Beacon接近时,区域是否应立即进入/退出?

我该怎么做才能确保它有效?

背景模式:位置更新或使用蓝牙LE配件必须打开才能使背景信标监控工作吗? GeoFencing在没有这些的情况下为我工作.

我已经做了什么:

>为每个地区设置这些:

beaconRegion.notifyOnExit = YES;
beaconRegion.notifyOnEntry = YES;
beaconRegion.notifyEntryStateOndisplay = YES;
>确保设置中的所有内容都有序(应用程序刷新等)

编辑:

我已经创建了一个新项目但它仍然无效.这是代码:

- (BOol)application:(UIApplication *)application dIDFinishLaunchingWithOptions:(NSDictionary *)launchOptions {_locationManager = [[CLLocationManager alloc] init];_locationManager.pausesLocationUpdatesautomatically = NO;_locationManager.desiredAccuracy = 25;_locationManager.delegate = self;[_locationManager requestAlwaysAuthorization];[_locationManager startUpdatingLocation];CLBeaconRegion* reg =[self prepareBeacon:@"here i put my UUID" :446 :2196];[_locationManager startMonitoringForRegion:reg];[_locationManager startRangingBeaconsInRegion:reg];return YES;}-(CLBeaconRegion*)prepareBeacon:(Nsstring*)uuID :(int)maj :(int)min{Nsstring* IDentifIEr = [Nsstring stringWithFormat:@"%@,%d,%d",uuID,maj,min];CLBeaconRegion *beaconRegion = [[CLBeaconRegion alloc] initWithProximityUUID:[[NSUUID alloc] initWithUUIDString:uuID] major:maj  minor:min IDentifIEr:IDentifIEr];beaconRegion.notifyOnExit=YES;beaconRegion.notifyOnEntry=YES;beaconRegion.notifyEntryStateOndisplay = YES;return beaconRegion;}-(voID)locationManager:(CLLocationManager *)manager dIDDetermineState:(CLRegionState)state           forRegion:(CLRegion *)region{}-(voID)locationManager:(CLLocationManager *)manager dIDEnterRegion:(CLRegion *)region{}-(voID)locationManager:(CLLocationManager *)manager dIDExitRegion:(CLRegion *)region{}-(voID)locationManager:(CLLocationManager *)manager dIDChangeAuthorizationStatus:(CLAuthorizationStatus)status{}-(voID)locationManager:(CLLocationManager *)manager dIDRangeBeacons:(NSArray *)beacons inRegion:(CLBeaconRegion *)region{}

一些额外的信息:

>除了创建一个全新的iOS8项目并添加代码之外,我已将NSLocationAlwaysUsageDescription添加到* .pList文件中.
>我在dIDEnterRegion和dIDExitRegion中添加了断点.它在前台工作,在后台无法工作(iPhone在主屏幕或锁定)
>在4S,iOS 8.1.1上进行测试

解决方法 您需要确保已在cclocationManager下调用该方法

- (voID) requestAlwaysAuthorization

与以下行相比,这样可以让您的应用更新前景和背景中的更改,只允许在前台通知您的应用:

- (voID) requestWhenInUseAuthorization

一旦用户响应请求,将使用更新的授权状态调用以下方法:

- (voID) locationManager: (CLLocationManager*) managerdIDChangeAuthorizationStatus: (CLAuthorizationStatus) status

资源:
https://developer.apple.com/library/ios/documentation/CoreLocation/Reference/CLLocationManager_Class/index.html#//apple_ref/occ/cl/CLLocationManager

总结

以上是内存溢出为你收集整理的ios – 区域监视背景中的信标区域不工作全部内容,希望文章能够帮你解决ios – 区域监视背景中的信标区域不工作所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/web/1072440.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-26
下一篇 2022-05-26

发表评论

登录后才能评论

评论列表(0条)

保存