【问题标题】:CLLocationManager does not have allowsBackgroundLocationUpdates member variableCLLocationManager 没有allowBackgroundLocationUpdates 成员变量
【发布时间】:2016-01-15 07:35:01
【问题描述】:

我正在使用我的 iOS8 应用程序并为 iOS9 做好准备。我读到 CLLocationManager 现在有一个名为allowBackgroundLocationUpdates 的成员变量,iOS9 需要将其设置为true。但是,Xcode 不将其识别为 CLLocationManager 的成员。我需要更改什么才能让 Xcode 识别该属性?我正在运行 Xcode 7。

    - (BOOL)isLocationServicesEnabled
    {
        BOOL locationServicesEnabledInstancePropertyAvailable = [self.locationManager respondsToSelector:@selector(locationServicesEnabled)]; // iOS 3.x
        BOOL locationServicesEnabledClassPropertyAvailable = [CLLocationManager respondsToSelector:@selector(locationServicesEnabled)]; // iOS 4.x

        if (locationServicesEnabledClassPropertyAvailable) { // iOS 4.x
            return [CLLocationManager locationServicesEnabled];
         } else if (locationServicesEnabledInstancePropertyAvailable) { // iOS 2.x, iOS 3.x
            return [CLLocationManager locationServicesEnabled];
        } else {
            return NO;
        }
    }

【问题讨论】:

    标签: cordova ios8 ios9 cllocationmanager


    【解决方案1】:

    此功能 (allowsBackgroundLocationUpdates) 仅适用于 iOS 9。请注意,它是 instance 属性,而不是类属性。

    只要您链接到 iOS 8,您就不必担心它,因为即使您在 iOS 9 上运行它也不会影响您。如果您链接到 iOS 9,您必须将此属性设置为 on您持有的每个 CLLocationManager 实例,否则您的后台位置更新将不会发生。

    https://developer.apple.com/library/ios/documentation/CoreLocation/Reference/CLLocationManager_Class/#//apple_ref/occ/instp/CLLocationManager/allowsBackgroundLocationUpdates

    【讨论】:

    • 如何设置这个属性?我试过 CLLocationManagerInstance.allowBackgroundLocaitonUpdates = YES;但它不识别该实例属性。
    • 我不知道科尔多瓦。我只知道如何在 Objective-C 或 Swift 中正常使用。
    • 很抱歉给您带来了困惑。我正在编辑实际的 Objective-C 代码。 Cordova 基本上在 Objective-C 中创建了一个 Xcode 项目,它是一个 Web 视图。这使您可以使用用 javascript 编写的应用程序(视图使用 html 和 css)并将它们转换为移动应用程序。现在我正在尝试编辑 Cordova 项目的 Objective-C 部分。我在原帖中添加了一些代码。
    猜你喜欢
    • 2017-06-01
    • 1970-01-01
    • 2017-01-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-11-20
    • 1970-01-01
    相关资源
    最近更新 更多