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

发布于 2024-12-06 00:48:19 字数 548 浏览 1 评论 0原文

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

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

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

到目前为止,我已经实现了

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

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

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

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

谢谢

I have 2 iPhones and I'm testing Apple push notifications.

They perfectly work when my app is running in foreground on both devices. But if I close it, by clicking on the Home button, I don't receive the notifications anymore.

The system doesn't show the notification popup. And I think this doesn't depend on my app code...

So far I've implemented

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

and it works great when the app is in foreground.
I've also implemented:

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

but the launchOptions never contain the notification. However, this is correct, I guess, because the last method is invoked when I select a button of a notification alert that I never see...

thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

余厌 2024-12-13 00:48:19

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

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

When you call method - (void)registerForRemoteNotificationTypes:(UIRemoteNotificationType)types you should indicate appropriate type of argument. If you want to display alert when system receive push-notification for your device then you should pass UIRemoteNotificationTypeAlert.

Also you can combine types and pass it in that argument: UIRemoteNotificationTypeAlert | UIRemoteNotificationTypeSound | UIRemoteNotificationTypeBadge.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文