如何根据iPhone中收到的推送通知调用不同的屏幕?

发布于 2024-12-20 08:23:55 字数 177 浏览 4 评论 0原文

我的 iPhone 应用程序有不同的视图控制器,我想根据从后端收到的推送通知来调用它们。例如,如果我有视图控制器“A”和“B”,当用户收到有关“A”中某些活动的消息时,我将启动“A”(例如,请完成“A”中的活动)并且 如果用户收到“请完成“B”中的活动),将启动屏幕“B”。 谁能告诉我这在 iPhone 中是否可行,如果可以的话如何实现?

My iPhone application has different view controllers and I would like to invoke them based on the push notification received from backend. For example if I have view controllers "A" and "B", I would launch "A" when user receives a message regarding some activity in "A" (e.g. Please complete the activity in "A") and
would launch screen "B" if user receives "Please complete the activity in "B").
Can anybody tell me if this is possible in iPhone and if so how?

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

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

发布评论

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

评论(1

捂风挽笑 2024-12-27 08:23:55

当然。您的应用程序委托通过 application:didReceiveRemoteNotification: 方法收到推送通知通知(如果通知到达时应用程序在前台处于活动状态,或者应用程序位于后台并且用户将其带入)通过作用于推送通知到前台)或 application:didFinishLaunchingWithOptions: (如果应用程序既不在后台也不在前台,并且用户通过作用于推送来启动它) 通知)。

在这两种情况下,作为任一方法的参数传递给您的字典都包含通知的有效负载/内容。您可以使用它来识别您的应用程序收到的通知类型,然后通过显示适当的视图控制器来采取相应的操作。

Sure. Your app delegate is notified of a push notification either through the application:didReceiveRemoteNotification: method (if the notification arrives while the app is active in the foreground of if the app is in the background and the user brings it to the foreground by acting on the push notification) or application:didFinishLaunchingWithOptions: (if the app was neither in the background nor in the foreground and the user launches it by acting on the push notification).

In both cases, the dictionary that is passed to you as a parameter of either method contains the notification's payload/contents. You can use it to identify which type of notification your app received and then act accordingly by displaying the appropriate view controller.

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