-
不用加什么权限
image.png -
后台保活
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)
}
}
网友评论