我有一个核心位置应用程序,我正在编写,利用startMonitoringSignificantLocationChanges方法在适当的时候生成更新,但这不适用于iPhone 3g等旧设备。
我希望核心位置功能在设备打开时仍能正常工作,所以我想我可以使用选择器测试来查看设备是否支持该方法,以及它是否仅使用标准核心位置更新方法。虽然这个选择器在我的iphone 3g上不起作用,但它仍然使用startMonitoringSignificantLocationChanges,即使它在手机上不起作用。
有什么想法吗?我宁愿不使用设备标识符测试,因为它必须针对手机的每个未来版本进行更新。
@interface RootViewController : UITableViewController <CLLocationManagerDelegate> {
CLLocationManager *locationManager;
}
@property (nonatomic, retain) CLLocationManager *locationManager;
@implementation RootViewController
@synthesize locationManager;
if([locationManager respondsToSelector:@selector(startMonitoringSignificantLocationChanges)]) {
[locationManager startMonitoringSignificantLocationChanges];
NSLog(@"Using bg updates");
}
else {
[locationManager startUpdatingLocation];
NSLog(@"Using reg updates");
}
答案 0 :(得分:2)
if ([CLLocationManager significantLocationChangeMonitoringAvailable]) {
…
}