我可以发送推送通知到我的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);
}
版权声明:本文内容由阿里云实名注册用户自发贡献,版权归原作者所有,阿里云开发者社区不拥有其著作权,亦不承担相应法律责任。具体规则请查看《阿里云开发者社区用户服务协议》和《阿里云开发者社区知识产权保护指引》。如果您发现本社区中有涉嫌抄袭的内容,填写侵权投诉表单进行举报,一经查实,本社区将立刻删除涉嫌侵权内容。