我设法回复推送通知,但我不知道如何处理到达应用程序的推送通知的点击,我想告诉应用程序在点击根据通知类型转到特定活动时,而不仅仅是打开应用程序(默认行为)
我知道我可以收到
-(void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo{
NSLog(@"Here I should Recive The notification .... ") ;
//call the commented functions .....
}
在这个函数中,但是当我实现它时,通知不会出现,只是在这个函数中做什么
答案 0 :(得分:1)
尝试按照代码
中的说明处理此次点击- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
//Accept push notification when the app is not open.
if (remoteNotifiInfo) {
[self application:application didReceiveRemoteNotification: remoteNotifiInfo];
}
}
// On click of notification open related screen.
像这样覆盖didReceiveRemoteNotification
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo
{
UIApplicationState state = [[UIApplication sharedApplication] applicationState];
if ( state == UIApplicationStateInactive )
{
//Your actions on notification click
double delayInSeconds = 0.3;
dispatch_time_t popTime = dispatch_time(DISPATCH_TIME_NOW, delayInSeconds * NSEC_PER_SEC);
dispatch_after(popTime, dispatch_get_main_queue(), ^(void){
//code to be executed on the main queue after delay
[[NSNotificationCenter defaultCenter] postNotificationName:@"pushTOEventDetails" object:eventVO];
});
}
}
答案 1 :(得分:0)
如果您想通过点击推送来导航某些特定的ViewController,只需在didReceiveRemoteNotification中添加ViewController导航代码
-(void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo{
NSLog(@"Here I should Receive The notification .... ") ;
//call the commented functions .....
FirstController *firstviewcontroller = [[FirstController alloc] initWithNibName:@"FirstController" bundle:nil];
[self.navigationController pushviewcontroller:firstviewcontroller animated:YES];
}
答案 2 :(得分:0)
只有在应用程序处于活动状态时才会触发该委托方法。如果应用程序未运行,您应该使用委托方法launchOptions
中的application:didFinishLaunchingWithOptions:
获取通知有效负载,并根据有效负载进行导航。