我可以在AppDelegate - application:didReceiveRemoteNotification
方法中使用 PromiseKit 吗?
我正在使用 GCM 从服务器推送通知。一旦应用程序收到通知,我想从服务器获取一些数据,解析它,按摩它,然后使用 Core Data 保存它。
当您在 TableViewController 上向下滑动手动刷新数据时,我正在使用 PromiseKit 将这些步骤链接在一起并且工作正常。但是,当我使用相同的逻辑从服务器刷新推送通知的数据时,行为是不可预测的,有时执行停止在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 的情况下重写代码进行顺序操作。