【发布时间】:2023-03-03 21:56:01
【问题描述】:
我希望我的应用在用户点击收到的推送通知时推送 NewsViewController。在 didFinishLaunching 我有:
UIUserNotificationType userNotificationTypes = (UIUserNotificationTypeAlert |
UIUserNotificationTypeBadge |
UIUserNotificationTypeSound);
UIUserNotificationSettings *settings = [UIUserNotificationSettings settingsForTypes:userNotificationTypes
categories:nil];
[[UIApplication sharedApplication]
registerUserNotificationSettings:settings];
[application registerUserNotificationSettings:settings];
[application registerForRemoteNotifications];
然后,仍然在 AppDelegate 中,我有:
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo {
[PFPush handlePush:userInfo];
UINavigationController *nav = (UINavigationController *) self.tabBarController.selectedViewController;
NewsViewController *dvController8 = [[NewsViewController alloc] initWithNibName:@"NewsViewController" bundle:[NSBundle mainBundle]];
[nav pushViewController:dvController8 animated:YES];
if (application.applicationState == UIApplicationStateInactive) {
UIAlertView *test = [[UIAlertView alloc] initWithTitle:@"INACTIVE" message:@"INACTIVE" delegate:self cancelButtonTitle:@"OK" otherButtonTitles: nil];
[test show];
[self handleRemoteNotificationWithPayload:userInfo];
}
}
-(void)handleRemoteNotificationWithPayload:(NSDictionary *)payload {
UINavigationController *nav = (UINavigationController *) self.tabBarController.selectedViewController;
NewsViewController *dvController8 = [[NewsViewController alloc] initWithNibName:@"NewsViewController" bundle:[NSBundle mainBundle]];
[nav pushViewController:dvController8 animated:YES];
}
如果用户在应用打开时收到推送,它会转到 NewsViewController。如果当他们点击推送通知时应用程序正在后台运行,它会转到 NewsViewController。但是,如果用户已经从应用程序切换器完全关闭了应用程序,然后点击收到的通知,它会打开应用程序,而不会转到 NewsViewController。我该如何解决这个问题?
【问题讨论】:
-
如果您查看我之前提供的示例,它指出您还需要在
application didFinishLaunchingWithOptions中调用它,我猜您忽略了它。这是一个新手失礼,文档会帮助你。我建议你开始和它交朋友 -
@soulshined 你之前从来没有回复过。当也将其放入
didFinishLaunchingWithOptions时,它会在每次首次启动应用程序时推送该视图控制器,而不仅仅是在收到推送时。 -
那你设置错了。您必须进行条件检查以查看应用程序是由 userInfo 打开还是刚刚打开。你可以通过说
if (userInfo)来做到这一点,这有意义吗? -
这未包含在我的其他答案中。我很抱歉。它应该是给定的。再次。你学到的所有东西都准备好了文档。你真的应该开始做。而且我之前没有收到其他通知。
-
@soulshined 这一定是问题所在。设置推送通知的解析文档没有关于任何 userInfo 标识符。
标签: ios objective-c iphone parse-platform push-notification