我们正在开发iPhone应用程序,并且我们已经实现了推送通知功能。当应用程序处于非活动状态时,收到的任何通知都会显示警报,并且徽章图标计数器会递增。当用户点击应用程序的图标或警报时,应用程序将变为活动状态,一切正常。
我们想要的是:在新通知中,每当用户点击应用图标时,它都应该打开特定页面(例如通知页面)。目前,当应用程序变为活动状态时,它会显示上一个先前打开的页面。
如何将应用程序(在前台)重定向到特定页面?
答案 0 :(得分:1)
假设这是您的PayLoad
{"aps":{"alert":"Hai User","type":"center","badge":1,"sound":"default"}}
didReceiveRemoteNotification 方法处理有效负载
-(void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo
{
// this is used for clear the count when user press the notification.
[[UIApplication sharedApplication] setApplicationIconBadgeNumber:0];
[[UIApplication sharedApplication] cancelAllLocalNotifications];
//When notification is pressed on background it comes here
//Get strings based on information on your json payload for example
NSMutableString *notificationType =[[userInfo objectForKey:@"aps"]objectForKey:@"type"];
if([notificationType isEqualToString:@"center"]){
//redirect/push a viewcontroler here , it automatically navigate to your VC.
profileViewController *profile = [[profileViewController alloc] initWithNibName:@"profile ViewController" bundle:nil];
[self.window.rootViewController presentViewController: profile animated:YES completion:NULL];
}
}
来自Apple的通知类型为here
答案 1 :(得分:0)
在你的
里面 - (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo {
[self openNewViewController]; // read the userInfo from the payload and based on that open new controller
}
方法,您可以直接推送/模态/添加查看您想要的页面。
在“didFinishLaunchingWithOptions:”内部检查远程通知有效负载
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
if (launchOptions[UIApplicationLaunchOptionsRemoteNotificationKey]) {
NSDictionary *dict = launchOptions[UIApplicationLaunchOptionsRemoteNotificationKey];
//Call your page here
}
}