当应用程序处于前台和后台时区分推送通知处理程序

发布于 2024-10-01 14:26:11 字数 630 浏览 3 评论 0原文

据说(如果我错了,请纠正我)如果应用程序位于前台,我们必须在“didReceiveRemoteNotification”中处理推送通知,如果应用程序位于后台,当用户点击“视图”时使用“didFinishLaunchingWithOptions”应用程序的按钮。由于我没有电话可以测试,我想知道我是否正确处理了这个问题。

1)当我点击推送通知中的“查看”按钮时,会调用什么?

2)假设我正在前台运行应用程序,并且同时收到推送通知。我会收到推送通知警报吗?如果是这样,如果用户单击“查看”按钮会发生什么?

3)在此线程中如何处理推送通知,如果应用程序已经在运行? 它说:

“alert”键不会直接位于 userInfo 字典下,您需要获取另一个名为“aps”的字典,然后从“aps”字典中获取“alert”或“body”

这是真的吗?

4)我需要当用户单击“视图”按钮时推送到某个视图因此我需要在这两种方法中处理该代码吗

It is said that (correct me if I'm wrong) if the application is in the foreground we have to handle push notifications in the "didReceiveRemoteNotification" and if the application is in the background using "didFinishLaunchingWithOptions" when user taps the "view" button of the app. As I dont have a phone to test I want to know whether I am handling this properly.

1) What will be invoked when I taps on the "View" button in the push notification?

2) Let say I am running the application in the foreground and push notification receives at the same time. Will I be given the push notification alert? If so what will happen if the user click on the View button?

3) In this thread How to handle push notifications if the application is already running? it says:

"alert" key will not be there directly under the userInfo dictionary, you need to get another dictionary with name "aps" and then get the "alert" or "body" from "aps" dictionary"

Is this true?

4) I need to push to a certain view when the user clicks on the View button. Hence do I need to handle that code in both methods?

Thank you

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

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

发布评论

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

评论(1

你另情深 2024-10-08 14:26:11

在此 Apple 视频中,对推送通知调用的方法进行了很好的概述: http ://developer.apple.com/videos/iphone/#video-advanced-pushnotification - 确保您访问并在 iTunes 中下载完整版本。

此直接链接可能有效: http:// developer.apple.com/itunes/?destination=adc.apple.com.3391495696.03391495702.3416205190?i=1378617410

  1. 无论哪种方式,一般的想法是,如果您的应用程序不在前台,请点击您的视图按钮将触发 didFinishLaunchingWithOptions,如果它是前台应用程序,您将收到 didReceiveRemoteNotification。

  2. 我认为您不会收到警报。 didReceiveRemoteNotification 方法将被调用,如果您愿意,将由您决定是否显示 UIAlert。

  3. 是的 - 确实如此。

  4. 是的,但我认为您可以通过创建专门设计来处理您的视图的第三种方法来简化此操作。您可以从 didFinishLaunching(仅当它通过通知启动)和 didReceiveRemoteNotification 中调用此函数。这样,如果您的应用程序需要启动,您可以有时间进行任何其他设置,以便应用程序能够立即运行(加载保存的数据、初始化选项卡栏控制器或其他类似的内容) )。

祝你好运

There's a nice rundown of the methods invoked by a push notification in this Apple vid: http://developer.apple.com/videos/iphone/#video-advanced-pushnotification - make sure you visit download the full version in iTunes.

This direct link might work: http://developer.apple.com/itunes/?destination=adc.apple.com.3391495696.03391495702.3416205190?i=1378617410

  1. Either way, the general idea is that if your app isn't in the foreground, tapping your view button will trigger didFinishLaunchingWithOptions, and if it is the foreground app, you'll get the didReceiveRemoteNotification.

  2. I don't think you'll get the alert. The method didReceiveRemoteNotification will be called, and it'll be up to you to show a UIAlert if you want.

  3. Yes - that's true.

  4. Yes, but I think you can simplify this by creating a third method specifically designed to handle your view. You can call this from both didFinishLaunching (only if it launched via a notification), and didReceiveRemoteNotification. This way, if your app needs to be launched, you can have time to do any other setup you might need to do for the app to work right out of the get-go (load saved data, init tabbar controllers or anything else like that).

Best of luck

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