【发布时间】:2019-02-19 18:47:34
【问题描述】:
在 Apple 坚持让用户在位置管理器的“始终”和“使用时”之间进行选择之前,我有一个运行良好的应用程序。
该应用程序使用 iBeacons 发送玩游戏的邀请并接受。
When "Always" is selected the beacons work fine but when I switch to "When In Use" they don't work at all.
我开始使用“始终”,但更改了以下代码以给用户选择。
在应用程序的 plist 中,我添加了“Privacy-Location Always and When In Use Usage Descriptions 和 Privacy-Location When In Use Usage Description”,并删除了“Privacy-Location Always Usage Description”。
在应用程序的委托中我有这个
- (void)locationManager:(CLLocationManager *)manager
didChangeAuthorizationStatus:(CLAuthorizationStatus)status{
if([CLLocationManager authorizationStatus]==kCLAuthorizationStatusAuthorizedAlways){
NSLog(@"Always");
AlertView2 = [[UIAlertView alloc] initWithTitle:@"Dual player on two devices is enabled."
message:@"To save battery power go to Settings/Privacy/Location Services and choose \"Never\" when not using I'M GAME. Two people can still play on one device when in \"Never\" mode. To recieve invitations to play only when the app is open select \"When In Use\"."
delegate:nil
cancelButtonTitle:@"OK"
otherButtonTitles:nil];
[AlertView2 show];
[[NSUserDefaults standardUserDefaults] setObject:@"YES" forKey:@"accessKey"];
[[NSUserDefaults standardUserDefaults] synchronize];
}
if([CLLocationManager authorizationStatus]==kCLAuthorizationStatusAuthorizedWhenInUse){
NSLog(@"WhenInUse");
AlertView2 = [[UIAlertView alloc] initWithTitle:@"Dual player on two devices is enabled."
message:@"To save battery power go to Settings/Privacy/Location Services and choose \"Never\" when not using I'M GAME. Two people can still play on one device when in \"Never\" mode. To recieve invitations to play while app is in background select \"Always\"."
delegate:nil
cancelButtonTitle:@"OK"
otherButtonTitles:nil];
[AlertView2 show];
[[NSUserDefaults standardUserDefaults] setObject:@"YES" forKey:@"accessKey"];
[[NSUserDefaults standardUserDefaults] synchronize];
}
if([CLLocationManager authorizationStatus]==kCLAuthorizationStatusRestricted){
NSLog(@"restricted");
}
if([CLLocationManager authorizationStatus]==kCLAuthorizationStatusDenied){
NSLog(@"denied");
AlertView2 = [[UIAlertView alloc] initWithTitle:@"Dual player on a single device Only."
message:@"To play on two devices go to Settings Privacy/Location Services and choose \"Always\" or \"When In Use\" for I'M GAME. In \"Always\" you can recieve invites while app is in background, in \"When In Use\" invites only appear when the app is on screen. To preserve battery choose \"Never\" when not using I'M GAME."
delegate:nil
cancelButtonTitle:@"OK"
otherButtonTitles:nil];
[AlertView2 show];
[[NSUserDefaults standardUserDefaults] setObject:@"YES" forKey:@"accessKey"];
[[NSUserDefaults standardUserDefaults] synchronize];
}
if([CLLocationManager authorizationStatus]==kCLAuthorizationStatusNotDetermined){
NSLog(@"undetermined2");
[locationManager requestAlwaysAuthorization];
[locationManager requestWhenInUseAuthorization];
}
}
iBeacon 是否需要将 Privacy-Location 设置为“始终”才能工作?
所以我刚刚发现,在“使用时”中,您无法监控信标区域是否进入或退出,只能找到其范围。所以我想问题是我将如何使用范围向我的用户发送通知。
【问题讨论】:
-
我投票结束这个问题,因为这不是我们在这里发布代码的方式。
-
你需要认真编辑这篇文章。查看How to Ask 和help center,了解有关将帖子编辑为良好标准的更多信息。祝你好运!
标签: objective-c xcode cllocationmanager ibeacon