【发布时间】:2015-11-06 03:37:26
【问题描述】:
我有以下代码运行但总是调用 didFailWithError 委托方法。甚至可以在 tvOS 中获取 Apple TV 设备的位置吗?
AppDelegate.h
#import <UIKit/UIKit.h>
#import <CoreLocation/CoreLocation.h>
@interface AppDelegate : UIResponder <UIApplicationDelegate, CLLocationManagerDelegate>
@property (strong, nonatomic) UIWindow *window;
@property (nonatomic, retain) CLLocationManager *locationManager;
@end
AppDelegate.m
@implementation AppDelegate
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
NSLog(@"locationManager requestLocation");
self.locationManager = [[CLLocationManager alloc] init];
self.locationManager.delegate = self;
[self.locationManager requestLocation];
return YES;
}
-(void)locationManager:(CLLocationManager *)manager didFailWithError:(NSError *)error {
NSLog(@"locationManager didFailWithError %@", error);
}
-(void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray<CLLocation *> *)locations {
NSLog(@"locationManager didUpdateLocations");
}
控制台显示:
locationManager didFailWithError 错误域=kCLErrorDomain Code=0 "(null)"
编辑: 我还将 NSLocationWhenInUseUsageDescription 添加到 .plist 并添加了
[self.locationManager requestWhenInUseAuthorization];
代替上面的[self.locationManager requestLocation]。我添加了didChangeAuthorizationStatus 委托方法并将调用移至那里的requestLocation。执行此操作后,使用状态值 kCLAuthorizationStatusNotDetermined 调用了 didChangeAuthorizationStatus,并且没有弹出权限请求要求“不允许”或“允许”,随后对requestLocation 的调用仍然触发didFailWithError。我尝试从 Apple TV 中完全删除该应用程序,认为这可能是一次性弹出窗口,但 requestWhenInUseAuthorization 仍然没有做任何提示许可的操作。
只有在手动进入 Apple TV 设置 - 常规 - 隐私 - 定位服务,然后找到我的应用并手动将设置从“从不”更改为“使用应用程序”。这显然不理想,如果requestWhenInUseAuthorization 真的会提示用户选择会更好。
【问题讨论】:
标签: objective-c tvos apple-tv