gpt4 book ai didi

iOS:推送通知仅在应用程序在前台运行时才起作用

转载 作者:行者123 更新时间:2023-11-29 04:58:31 24 4
gpt4 key购买 nike

我有 2 部 iPhone,我正在测试 Apple 推送通知。

当我的应用程序在两台设备上的前台运行时,它们可以完美工作。但如果我通过单击“主页”按钮将其关闭,我将不再收到通知。

系统不显示通知弹出窗口。我认为这不取决于我的应用程序代码...

到目前为止我已经实现了

- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo

当应用程序位于前台时,效果很好。我还实现了:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions

但 launchOptions 从不包含通知。但是,我想这是正确的,因为当我选择我从未见过的通知警报按钮时,会调用最后一个方法...

谢谢

最佳答案

当您调用方法- (void)registerForRemoteNotificationTypes:(UIRemoteNotificationType)types时,您应该指示适当的参数类型。如果您想在系统收到设备的推送通知时显示警报,那么您应该传递UIRemoteNotificationTypeAlert

您还可以组合类型并将其传递到该参数中:UIRemoteNotificationTypeAlert | UIRemoteNotificationTypeSound | UIRemoteNotificationTypeSound | UIRemoteNotificationTypeSound | UIRemoteNotificationTypeSound | UIRemoteNotificationTypeSound UIRemoteNotificationTypeBadge

关于iOS:推送通知仅在应用程序在前台运行时才起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7481000/

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