是否可以接收静默推送通知(“content-available”:“1”)并运行功能以在没有用户的情况下更改NSUserDefaults.standardUserDefaults()
中的数据必须点击通知(通知中心没有通知,因为它是静默推送通知)。 该应用程序根本没有运行(例如用户强制退出)。我已经尝试了下面的代码,它的工作原理是如果应用程序正在运行或在后台运行,但如果应用程序是强制退出(根本不运行),我也希望它能够工作。当应用程序未运行时,通过无声推送通知在后台更新本地数据库
我已启用后台提取和远程通知。
func application(application: UIApplication, didReceiveRemoteNotification userInfo: [NSObject : AnyObject], fetchCompletionHandler completionHandler: (UIBackgroundFetchResult) -> Void) {
handleNotification()
}
//this works, the someData is not a problem
func handleNotification() -> Void{
let defaults = NSUserDefaults.standardUserDefaults()
defaults.setValue(someData, forKey: "key")
defaults.synchronize()
}
当我发送推送通知,如果应用程序是主动或在后台,数据更新,但如果应用程序没有运行在所有的数据不会被更新。
我写道:我有背景获取和远程通知启用。在能力背景模式我检查他们都 – user5132182
我把一切都回( – luk2302
好吧,有可能做这样的事情吗? – user5132182