我正在处理推送通知数据,然后在基于推送通知自定义数据的调用API之后。当应用程序处于事件和后台状态时,这将正常工作。
但是当应用程序未运行然后单击通知时,我能够从自定义日期获取自定义数据但是,API 不会被调用并且应用程序会卡住。
我检查了 iOS 10 和 11,但无法正常工作
处理推送是这样的。
AppDelegate
func application(_ application: UIApplication, didReceiveRemoteNotification userInfo: [AnyHashable: Any],
fetchCompletionHandler completionHandler: @escaping (UIBackgroundFetchResult) -> Void) {
redirectToScreen(notificaiton: userInfo)
completionHandler(UIBackgroundFetchResult.newData)
}
//Notify through Notification center
func redirectToScreen(notificaiton: [AnyHashable: Any]) {
let dictPayload = notificaiton as NSDictionary
print(dictPayload)
if let type = dictPayload.value(forKey: "type") as? String {
var dict = ["type" : type]
NotificationCenter.default.post(name: NSNotification.Name.init(rawValue: "handlePush"), object: dict)
}
}
HomeViewController
//Notification Observer goes here and call API
let spinner = showLoader(view: self.view) // App goes stuck here and loaded process continuously, response is not getting
Alamofire.request(kURl, method: .post, parameters: param, encoding: URLEncoding.httpBody, headers: nil).authenticate(user: R.string.keys.basicAuthUsername(), password: R.string.keys.basicAuthPassword()).responseSwiftyJSON(completionHandler: {
spinner.dismissLoader()
})
最佳答案
swift 4.0
根据 @TarasChernyshenko 声明,我将发布通知代码放入 DispatchQueue.main.async { }
block 中,现在工作正常。
DispatchQueue.main.async {
NotificationCenter.default.post(name: NSNotification.Name.init(rawValue: "handlePush"), object: dict)
}
关于ios - 单击“已终止”状态下的 Firebase 推送通知时应用程序会卡住,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48984260/