iphone - 当收到 RemoteNotification 时跳转到其他页面并取消位置

标签 iphone ios push-notification apple-push-notifications

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

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

最佳答案

你必须用这个方法在 AppDelegate.m 文件中编写你的代码:

 - (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo 
{
           NSLog(@"%@", userInfo);
           NSString *notiText = [[userInfo valueForKey:@"aps"] valueForKey:@"alert"];
           [self JumpChatHistoryView];
}

关于iphone - 当收到 RemoteNotification 时跳转到其他页面并取消位置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13817095/

相关文章:

push-notification - 将 Google Drive 推送通知设置为永不过期

ios - Firebase 从设备发送推送通知 (IOS)

iphone - 如何读取屏幕以查看哪些像素是白色的

iphone - 如何创建 "0000001"类型数字格式?

ios - 解析动态 JSON 的模型

ios - 无法分配给 UITableViewCell 中的 'accessoryType'

ios - didReceiveRemoteNotification 在单击通知(背景)时不工作,但在应用程序为前台时工作

iphone - 如何从应用程序将音乐文件添加到音乐播放器播放列表

ios - 如何将 UILabel 正好放在 UITableView 下方?

ios - 呈现 SKScene 后取消隐藏 UIButtons 时延迟?