我正在编写一个核心位置应用程序,利用 startMonitoringSignificantLocationChanges 方法在适当的时候生成更新,但这不适用于 iPhone 3g 等旧设备。
我希望核心位置功能在设备打开时仍然可以工作,所以我想我可以使用选择器测试来查看设备是否支持该方法,以及它是否不只使用标准核心位置更新方法。尽管此选择器在我的 iphone 3g 上不起作用,但它仍然使用 startMonitoringSignificantLocationChanges,即使它在手机上不起作用。
有什么想法吗?我宁愿不使用设备标识符测试,因为这样就必须针对 future 的每个手机版本进行更新。
@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");
}
最佳答案
if ([CLLocationManager significantLocationChangeMonitoringAvailable]) {
…
}
关于iphone - 检测 iPhone 设备的 Core Location 功能,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3929912/