gpt4 book ai didi

ios - Swift - didReceiveRemoteNotification - PromiseKit

转载 作者:行者123 更新时间:2023-11-29 01:16:46 28 4
gpt4 key购买 nike

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

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

我正在使用 PromiseKit 将步骤链接在一起,当您通过在 TableViewController 上向下滑动手动刷新数据时,它工作正常。然而,当我使用相同的逻辑从服务器推送通知刷新数据时,行为是不可预测的,有时执行停止在 firSTLy(),其他时候它执行几个 then block ,然后什么都没有。

基本上这就是我会做的:

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 block 都是异步执行的。 didReceiveRemoteNotification 方法将在调用 then block 之前返回。

如果你想进行同步调用,你不应该使用promisekit!

关于ios - Swift - didReceiveRemoteNotification - PromiseKit,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35087850/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com