【问题标题】:Detect iPhone device capabilities for Core Location检测核心位置的 iPhone 设备功能
【发布时间】:2010-10-14 03:40:37
【问题描述】:

我正在编写一个核心位置应用程序,它利用 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");
        }

【问题讨论】:

  • 什么是locationController.locationManager?您确定该属性的值不是nil?有什么原因你不只是在这里使用locationManager,就像你在其他方法中所做的那样?
  • 我为这篇文章编写的示例中的错字。我纠正了错字。

标签: iphone objective-c cocoa core-location


【解决方案1】:
if ([CLLocationManager significantLocationChangeMonitoringAvailable]) {
…
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-03-18
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多