使用swift代码关闭背景模式
问题描述:
我想在我的应用程序设置屏幕中添加一个切换,使用户可以关闭我的应用程序的背景模式。我使用这种方式构建它,并且我没有看到另一种方法将它从设置菜单之外关闭。我错过了什么吗?使用swift代码关闭背景模式
答
我建议你创建一个布尔值,它取决于切换输入保存NSUserDefaults
,你可以写在AppDelegate
func application(application: UIApplication, performFetchWithCompletionHandler completionHandler: (UIBackgroundFetchResult) -> Void) {
if NSUserDefaults.standardUserDefaults().boolForKey("AllowBackgroundFetch"){
func yourcode()
completionHandler(.NewData)
}else{
print("user denied access")
}
}
逻辑