开发者社区> 问答> 正文

如何在App不运行(即完全被杀死)的情况下,当用户点击推送通知时打开特定的控制器目标C

我可以发送推送通知到我的iOS设备。但当我点击那个通知时,它只会打开应用程序。当我的应用程序处于后台或前台时,它工作得非常完美,我希望应用程序打开并导航到特定的视图控制器,具体取决于所收到的推送通知。

(void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo fetchCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler {

    // Print message ID.
    NSLog(@"Message ID: %@", userInfo[@"gcm.message_id"]);
    [[FIRMessaging messaging] appDidReceiveMessage:userInfo];
    NSDictionary *apsDict = [userInfo objectForKey:@"aps"];
    NSString *alertForegroundMessage = [NSString stringWithFormat:@"%@", [apsDict objectForKey:@"alert"]];

    // Pring full message.
    NSLog(@"%@", userInfo);

    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, 20 * NSEC_PER_SEC),
                   dispatch_get_main_queue(), ^{
                       // Check result of your operation and call completion block with the result
                       completionHandler(UIBackgroundFetchResultNewData);

                       NSMutableArray *arrnotification;

                       arrnotification = [userInfo valueForKey:@"aps"];

                   });

    if (application.applicationState == UIApplicationStateActive)
    {

        NSDictionary *userInfo = [[NSDictionary alloc] init];
        [[NSNotificationCenter defaultCenter] postNotificationName:@"downloadDataFromServer" object:self userInfo:userInfo];
          NSLog(@"User Info : %@",userInfo);
         completionHandler(UIBackgroundFetchResultNewData);
    }

    else
    {
        NSLog(@"userInfo->%@", [userInfo objectForKey:@"aps"]);
        NSDictionary *sentObject = [NSDictionary dictionaryWithObjectsAndKeys:noteDict,@"data", nil];
        [[NSNotificationCenter defaultCenter] postNotificationName:@"downloadDataFromServer" object:sentObject];
        completionHandler(UIBackgroundFetchResultNewData);
    }
    completionHandler(UIBackgroundFetchResultNewData);
}

展开
收起
游客5akardh5cojhg 2019-12-11 22:07:19 444 0
0 条回答
写回答
取消 提交回答
问答排行榜
最热
最新

相关电子书

更多
女性移动App安全攻防战 立即下载
汇聚云计算的生态核能——云市场,云上APP Store 立即下载
千万级用户直播App——服务端架构设计和思考 立即下载