1

您好,我正在使用 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并点击它时,我的代码是OK的,它可以跳转其他视图。但是当我杀死我的应用程序时,当我收到RemoteNotification时,我点击它,它没有跳过其他视图,它只进入主视图,如何解决它。

此外,当我取消 LocalNotification 我可以使用[[UIApplication sharedApplication] cancelLocalNotification:notification]; 但在 RemoteNotification 我找不到相同的方法。我该怎么做?

4

2 回答 2

1

您必须使用此方法在 AppDelegate.m 文件中编写代码:

 - (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo 
{
           NSLog(@"%@", userInfo);
           NSString *notiText = [[userInfo valueForKey:@"aps"] valueForKey:@"alert"];
           [self JumpChatHistoryView];
}
于 2012-12-11T09:57:15.680 回答
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,有时它可以自行取消,有时不能

于 2012-12-11T10:14:04.733 回答