Swift - didReceiveRemoteNotification - PromiseKit

Swift - didReceiveRemoteNotification - PromiseKit

我可以在 AppDelegate - application:didReceiveRemoteNotification 方法中使用 PromiseKit 吗?

我正在使用 GCM 从服务器推送通知。一旦应用程序收到通知,我想从服务器获取一些数据,解析它,处理它,然后使用 Core Data 保存它。

我正在使用 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 {
        }
}

显然,在所有 Promises 完成之前,控件似乎存在 didReceiveRemoteNotification 方法。

PromiseKit 大师,有什么建议吗?唯一能想到的就是不使用PromiseKit重写代码进行顺序操作

PromiseKit 是一个异步库。

你所有的 then 块都是异步执行的。 didReceiveRemoteNotification 方法将 return 在调用 then 块之前。

如果要进行 synch 调用,则不应使用 promisekit!