gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-28 10:19:06 28 4
gpt4 key购买 nike

我有一个奇怪的案例。我的 swift ios 应用程序已连接到 Cloudkit。如果应用程序未运行(后台状态),我每次都会收到我的通知徽章和警报!如果应用程序正在运行,则不会收到任何通知!我知道它没有击中 Remote ,因为我这样做:1.在didReceiveRemoteNotification事件上加断点2. 在插入的 iphone 中运行 xcode3. NSLog("detected 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/37232849/

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