Ios 当应用程序未运行(即完全停止)时,用户点击推送通知时,如何打开特定控制器Objective-C
我能够向我的IOS设备发送推送通知。但是,当我单击该通知时,它只会打开应用程序。当我的应用程序位于后台或前台时,它工作正常,我希望该应用程序打开并导航到特定的视图控制器,具体取决于收到的推送通知Ios 当应用程序未运行(即完全停止)时,用户点击推送通知时,如何打开特定控制器Objective-C,ios,objective-c,Ios,Objective C,我能够向我的IOS设备发送推送通知。但是,当我单击该通知时,它只会打开应用程序。当我的应用程序位于后台或前台时,它工作正常,我希望该应用程序打开并导航到特定的视图控制器,具体取决于收到的推送通知 - (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo fetchCompletionHandler:(void (^)(UIBackgroundFetc
- (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);
}
当用户从通知打开应用程序后启动应用程序时。处理基于通知的导航的最佳方法是检查
应用程序中的launchOptions
字典(uquot:didFinishLaunchingWithOptions:)
方法。这应该包含remoteNotification
-键,该键保存推送通知数据
正如在应用程序(uuIdReceiveMemotentification:fetchCompletionHandler:)
方法的讨论部分所述,系统不会自动启动您的应用程序
是否导航到在
downloadDataFromServer
函数中编写的特定VC代码?没有调用push/present方法来执行实际导航。这是其他方法之一吗?@CodeChanger是的,它导航到特定的VCR。请不要在你的头像上使用苹果标志:你不允许使用它。看见