【问题标题】:iOS 15 app not launching in killed state with location changeiOS 15 应用程序未在位置更改时以终止状态启动
【发布时间】:2022-01-14 02:23:21
【问题描述】:

我在我的应用程序SS here中添加了定位背景模式

但是,应用程序仍然无法使用启动选项键启动

UIApplication.LaunchOptionsKey.location

这是我的应用委托代码,

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
    // Override point for customization after application launch.
    addItem(name: "LaunchOptions: \(String(describing: launchOptions))")
    if let launchOptions = launchOptions {
        if launchOptions[UIApplication.LaunchOptionsKey.location] != nil {
            startLocationMonitoring()
        }
    }
    print("LaunchOptions: \(String(describing: launchOptions))")
    return true
}

func startLocationMonitoring() {
    locationManager?.delegate = nil
    locationManager = nil
    locationManager = CLLocationManager()
    locationManager?.delegate = self
    locationManager?.desiredAccuracy = kCLLocationAccuracyBestForNavigation
    locationManager?.distanceFilter = 1.0 // meters
    locationManager?.allowsBackgroundLocationUpdates = true
    locationManager?.activityType = .otherNavigation
    locationManager?.pausesLocationUpdatesAutomatically = false
    authStatusCheck()
    locationManager?.startUpdatingLocation()
}

func locationManager(_ manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) {
    print(locations)
    if let appDelegate = (UIApplication.shared.delegate as? AppDelegate) {
        for location in locations {
            appDelegate.addItem(newLocation: location)
        }
    }
}

addItem 函数将位置变化或日志添加到核心数据中

【问题讨论】:

    标签: swift gps location appdelegate ios15


    【解决方案1】:

    现在您可以在场景委托上获得启动选项。这是一个简单的例子:

    func scene(_ scene: UIScene, willConnectTo session: UISceneSession, options connectionOptions: UIScene.ConnectionOptions) {                
              if let response = connectionOptions.notificationResponse {
                 //get your launch info from here
                 let location = response.notification.request.content.userInfo[UIApplication.LaunchOptionsKey.location]
        ...
              }
            }
    

    【讨论】:

      猜你喜欢
      • 2017-07-30
      • 1970-01-01
      • 1970-01-01
      • 2014-09-06
      • 1970-01-01
      • 2016-09-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多