OGeek|极客世界-中国程序员成长平台

标题: ios - 即使应用程序关闭,也会在后台检测信标 [打印本页]

作者: 菜鸟教程小白    时间: 2022-12-12 15:56
标题: ios - 即使应用程序关闭,也会在后台检测信标

您好,我正在开发一个带有信标的应用程序,即使应用程序已关闭,我也需要持续扫描信标。有没有可以在后台运行的cordova插件,请给我推荐示例应用教程



Best Answer-推荐答案


后台模式只是部分答案。您需要在 Info.plist 中有一个或两个条目:

enter image description here

然后在您的代码中的某个地方,您需要请求 requestWhenInUseAuthorization 或在您的情况下 requestAlwaysAuthorization。然后您需要在位置管理器委托(delegate)中处理此问题。我是这样做的:

- (void)locationManagerCLLocationManager *)manager  didChangeAuthorizationStatusCLAuthorizationStatus)status {
    if (status == kCLAuthorizationStatusAuthorizedWhenInUse) {

        [self startMonitoringAllRegions];

        [self.locationManager startUpdatingLocation];
    }
    else if (status == kCLAuthorizationStatusNotDetermined) {
        [self.locationManager requestWhenInUseAuthorization];
    }
}

所以在某处我要求开始监视信标区域,然后在此方法中我正在检查我是否有用户的许可,如果没有,我正在请求是否(将显示来自 plist 的字符串) 如果有,我将开始更新用户位置。

希望这会让你继续前进

关于ios - 即使应用程序关闭,也会在后台检测信标,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31902982/






欢迎光临 OGeek|极客世界-中国程序员成长平台 (http://ogeek.cn/) Powered by Discuz! X3.4