我可以在PromiseKit方法中使用AppDelegate - application:didReceiveRemoteNotification方法吗?
我正在使用GCM从服务器推送通知。一旦应用程序收到通知,我想从服务器获取一些数据,解析它,按摩它,然后使用Core数据保存它。
当您在PromiseKit上手动刷新数据时,我使用TableViewController将这些步骤链接在一起,并使其工作正常。但是,当我使用相同的逻辑在服务器的推送通知上刷新数据时,这种行为是不可预测的,有时在firstly()停止执行,另一些时候它执行两个then块,然后什么也不执行。
基本上,这就是我要做的:
func application( application: UIApplication,
didReceiveRemoteNotification userInfo: [NSObject : AnyObject],
fetchCompletionHandler handler: (UIBackgroundFetchResult) -> Void) {
firstly() {
// fetch data (JSON) from server
}.then {
// Parse the JSON
}.then {
// Sync the db (using Core Data)
}.then {
// Raise local Notification
}.error {
}
}显然,在实现所有didReceiveRemoteNotification之前,该控件似乎存在于Promises方法中。
PromiseKit大师,有什么建议吗?我唯一能想到的就是在没有PromiseKit的情况下重写代码,以便进行顺序操作。
发布于 2016-05-16 13:13:31
PromiseKit是一个异步库。
所有的asynchronously.块都是执行then的方法didReceiveRemoteNotification将在调用块之前返回。
如果您想要进行同步调用,则不应使用约定工具包!
https://stackoverflow.com/questions/35087850
复制相似问题