gpt4 book ai didi

iOS 6 : update view after push notification was received, 但应用已关闭

转载 作者:可可西里 更新时间:2023-11-01 05:13:49 24 4
gpt4 key购买 nike

应用程序收到推送通知后,我想更改主 ViewController 上某些按钮的标题。为了实现此行为,我在我的应用程序委托(delegate)中重写了方法 application: didReceiveRemoteNotification: 以使用我想更新为 Root View 的 Controller 重新实例化 UINavigationController Controller ,将按钮的标题设置为我想要的任何内容:

- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo {
UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:self.welcomeViewController];
[self.window setRootViewController:navController];
[self.welcomeViewController.buttonToUpdate setTitle: @"Updated Text" forState: UIControlStateNormal];
}

虽然这可能不是最好的解决方案(也许我可以完全忘记 UIButtons 并让 View Controller 使用 UITableView 并将其行用作按钮?),但它适用于以下场景:

1) 应用在前台。弹出推送通知警报,用户点击确定, View 更新正常。

2) 应用程序在后台/关闭。设备处于锁定模式。推送通知到达,用户解锁设备,加载应用程序, View 也正常更新。

例如,当用户正在使用另一个应用程序并且推送通知到达时,问题似乎会出现,但用户不是通过推送通知而是通过点击应用程序图标打开应用程序。在那种情况下,application: didReceiveRemoteNotification: 似乎没有被调用,并且问题中的 View 永远不会更新。

希望我的解释清楚。我乐于接受关于不同方法的建议,或者如何使用我的方法处理最后一个场景。

谢谢!

最佳答案

摘自 APNS 开发指南:

Let’s review the possible scenarios when the operating delivers a local notification or a remote notification for an application.

The notification is delivered when the application isn’t running in the foreground. In this case, the system presents the notification, displaying an alert, badging an icon, perhaps playing a sound.

As a result of the presented notification, the user taps the action button of the alert or taps (or clicks) the application icon. If the action button is tapped (on a device running iOS), the system launches the application and the application calls its delegate’s application:didFinishLaunchingWithOptions: method (if implemented); it passes in the notification payload (for remote notifications) or the local-notification object (for local notifications).

If the application icon is tapped on a device running iOS, the application calls the same method, but furnishes no information about the notification.

您遇到的行为是点击应用程序图标时的预期行为。在这种情况下,就好像用户正常启动应用程序并且没有推送通知到达。在这种情况下,您显示不同内容的唯一方法(我能想到)是在您的应用程序启动时联系您的服务器并获取一些信息,表明最近向该设备发送了推送通知。

关于iOS 6 : update view after push notification was received, 但应用已关闭,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14944024/

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