Когда я отправляю push-уведомление, и мое приложение открыто или в фоновом режиме, и я нажимаю на push-уведомление, мое приложение перенаправляет на PushMessagesVc
viewController
(по назначению)
Для этого я использую следующий код:
-(void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo {
UIStoryboard *mainstoryboard = [UIStoryboard storyboardWithName:@"MainStoryboard" bundle:nil];
PushMessagesVc *pvc = [mainstoryboard instantiateViewControllerWithIdentifier:@"PushMessagesVc"];
[self.window.rootViewController presentViewController:pvc
animated:YES
completion:NULL];
}
В приведенном выше коде/сценарии нет проблем, но если приложение закрыто и я нажимаю push-уведомление, приложение не перенаправляет мой PushMessagesVc
viewController
в этом случае, и приложение остается на главном экране.
Для второго сценария я использую следующий код:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
sleep(1);
[[UIApplication sharedApplication] registerForRemoteNotificationTypes:(UIRemoteNotificationTypeAlert | UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeNone)];
[UIApplication sharedApplication].applicationIconBadgeNumber = 1;
NSDictionary *userInfo = [launchOptions valueForKey:@"UIApplicationLaunchOptionsRemoteNotificationKey"];
NSDictionary *apsInfo = [userInfo objectForKey:@"aps"];
if(apsInfo) {
UIStoryboard *mainstoryboard = [UIStoryboard storyboardWithName:@"MainStoryboard" bundle:nil];
PushMessagesVc* pvc = [mainstoryboard instantiateViewControllerWithIdentifier:@"PushMessagesVc"];
[self.window.rootViewController presentViewController:pvc animated:YES completion:NULL];
return YES;
}
return YES;
}
Но в этом случае PushMessagesVc
не появляется.