我正在为iOS 8实现新的核心位置权限,但我想使用Xcode 5.1.1和iOS 7.1 SDK进行编译和发布。
具体来说,我想调用方法" requestWhenInUseAuthorization"在CLLocationManager上,仅在iOS 8中可用。
这样做有什么风险?这是一个好习惯吗?我可以忽略“未声明的选择器”吗?的警告?
// Warning: Undeclared Selector
SEL requestWhenInUse = @selector(requestWhenInUseAuthorization);
if( [self.sharedLocationManager respondsToSelector:requestWhenInUse] )
{
// Warning: May cause leak because selector is unknown
[self.sharedLocationManager performSelector:requestWhenInUse];
}
[self.sharedLocationManager startUpdatingLocation];
答案 0 :(得分:2)
你的代码很好。要取消警告,请添加
@interface CLLocationManager (iOS8Method)
- (void)requestWhenInUseAuthorization;
@end
然后你可以调用方法
if( [self.sharedLocationManager respondsToSelector:@selector(requestWhenInUseAuthorization)] )
{
[self.sharedLocationManager requestWhenInUseAuthorization];
}
还阅读了这个问题:performSelector may cause a leak because its selector is unknown