美文网首页
后台简单保活(非播放音乐、精确定位)

后台简单保活(非播放音乐、精确定位)

作者: 太平洋_cfd2 | 来源:发表于2022-08-15 18:03 被阅读0次
    1. 不用加什么权限


      image.png
    2. 后台保活

    private var  backgroundTask: UIBackgroundTaskIdentifier?
    func applicationDidEnterBackground(_ application: UIApplication) {
            backgroundTask = application.beginBackgroundTask(expirationHandler: { [weak self] in
                guard let self = self else { return }
                
                if let backgroundTask = self.backgroundTask {
                    application.endBackgroundTask(backgroundTask)
                    self.backgroundTask = .invalid
                }
            })
    }
    func applicationWillEnterForeground(_ application: UIApplication) {
            if let backgroundTask = backgroundTask {
                UIApplication.shared.endBackgroundTask(backgroundTask)
            }
    }
    

    参考
    ps: https://juejin.cn/post/6844904041680470023

    相关文章

      网友评论

          本文标题:后台简单保活(非播放音乐、精确定位)

          本文链接:https://www.haomeiwen.com/subject/odjlgrtx.html