gpt4 book ai didi

swift - 应用程序运行时 didReceiveRemoteNotification 未运行(前台)

转载 作者:行者123 更新时间:2023-11-30 12:14:32 30 4
gpt4 key购买 nike

我有一个奇怪的案例。我的 swift ios 应用程序已连接到 Cloudkit。如果应用程序未运行(后台状态),我每次都会收到通知徽章和警报!如果应用程序正在运行,则不会收到任何通知!我知道它没有击中 Remote ,因为我这样做:1.在didReceiveRemoteNotification事件中添加断点2. 在插入的 iPhone 中运行 xcode3. NSLog("检测到didReceiveRemoteNotification"),所以最终代码如下

func application(application: UIApplication, didReceiveRemoteNotification userInfo: [NSObject : AnyObject]){
NSLog("detected didReceiveRemoteNotification")
}

我知道错误不是来自 cloudkit 或 APNS,因为当手机处于后台状态时,我确实收到了警报横幅和徽章。

你能指导我为前台状态正确设置它吗!?

我运行的是 ios v9.3

更新#1我认为文档的措辞很差。它清楚地表明两者都在前台运行,这是我关心的;尽管如此,修复比文档更准确!

Unlike the application:didReceiveRemoteNotification: method, which is called only when your app is running in the foreground, the system calls this method when your app is running in the foreground or background.

最佳答案

您实现了错误的方法。实现:

func application(_ application: UIApplication,
didReceiveRemoteNotification userInfo: [NSObject : AnyObject],
fetchCompletionHandler completionHandler: (UIBackgroundFetchResult) -> Void)

正如文档所解释的:

Unlike the application:didReceiveRemoteNotification: method, ... the system calls this method when your app is running in the foreground or background.

关于swift - 应用程序运行时 didReceiveRemoteNotification 未运行(前台),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45595509/

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