您好,我正在使用Apple APNS发送RemoteNotification。我发现的问题是:
首先,我想接收RemoteNotification然后跳转其他页面,而不是主页面(第一页)我的代码:
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo {
NSLog(@"remote notification: %@",[userInfo description]);
NSDictionary *apsInfo = [userInfo objectForKey:@"aps"];
NSString *alert = [apsInfo objectForKey:@"alert"];
NSLog(@"Received Push Alert: %@", alert);
NSString *sound = [apsInfo objectForKey:@"sound"];
NSLog(@"Received Push Sound: %@", sound);
NSString *badge = [apsInfo objectForKey:@"badge"];
NSLog(@"Received Push Badge: %@", badge);
application.applicationIconBadgeNumber = [[apsInfo objectForKey:@"badge"] integerValue];
if ([userInfo objectForKey:@"type"])
{
NSString *nsType = [userInfo objectForKey:@"type"];
NSLog(@"Received Push nsType: %@", nsType);
if([[userInfo objectForKey:@"type"] intValue]==1){//chat
[self JumpChatHistoryView];
}else{
[self JumpMessageDetailView];
}
}
application.applicationIconBadgeNumber = 0;
}
我的应用程序进入后台并且没有被系统杀死,当收到RemoteNotification并单击它时,我的代码没问题,它可以跳转到其他视图。但是当我杀了我的应用程序时,当我收到RemoteNotification时,我点击它,它不会跳过其他视图,它只进入主视图,如何解决它。
此外,当我取消LocalNotification时,我可以使用[[UIApplication sharedApplication] cancelLocalNotification:notification];
,但在RemoteNotification,我找不到相同的方法。我该怎么办?
答案 0 :(得分:1)
您必须使用此方法在AppDelegate.m文件中编写代码:
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo
{
NSLog(@"%@", userInfo);
NSString *notiText = [[userInfo valueForKey:@"aps"] valueForKey:@"alert"];
[self JumpChatHistoryView];
}
答案 1 :(得分:0)
我可以回答我的问题1:
(BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary*)launchOptions add
NSDictionary *userInfo =[launchOptions objectForKey:UIApplicationLaunchOptionsRemoteNotificationKey];
if ([userInfo objectForKey:@"type"])
{
NSString *nsType = [userInfo objectForKey:@"type"];
NSLog(@"Received Push nsType: %@", nsType);
if([[userInfo objectForKey:@"type"] intValue]==1){//chat
[self JumpChatHistoryView];
}else{
[self JumpMessageDetailView];
}
}
对于问题2,有时它可以自行取消,有时不能