IOS / Objective-C: направлять пользователей на определенный экран приложения при нажатии на уведомление - PullRequest
0 голосов
/ 04 мая 2018

В методе - (void)applicationDidBecomeActive:(UIApplication *)application { по умолчанию в appDelegate Apple включает комментарий:

      //This may also be a good place to direct someone
 to a certain screen if the app was in background but they just clicked on a notification

Я пытаюсь сделать это для локальных уведомлений, но не могу понять, как перенаправить пользователя на определенный экран. Документы говорят, что вы можете проверить URL, но даже в этом случае я не знаю, как указать NSUrl для экрана в приложении.

Это похоже на общий случай использования, мы постоянно нажимаем на уведомления, которые ведут нас к определенным частям приложения, но не находят хороших ресурсов.

Заранее спасибо за любые предложения.

1 Ответ

0 голосов
/ 04 мая 2018

Вы должны использовать didReceiveLocalNotification или didReceiveNotificationResponse метод делегата в вашем AppDelegate.m файле, в зависимости от того, какое уведомление вы внедрили

Для UILocalNotification:

-(void)application:(UIApplication *)application didReceiveLocalNotification:(UILocalNotification *)notification
{
        // Your redirection code goes here like shown below
        MyViewController *controller = [[UIStoryboard storyboardWithName:@"Main" bundle:nil] instantiateViewControllerWithIdentifier:@"ViewController"];
        [self.window.rootViewController.navigationController pushViewController:controller animated:YES];
}

Для уведомления

- (void)userNotificationCenter:(UNUserNotificationCenter *)center
       didReceiveNotificationResponse:(UNNotificationResponse *)response
       withCompletionHandler:(void (^)(void))completionHandler {

          // Your redirection code goes here like shown below
            MyViewController *controller = [[UIStoryboard storyboardWithName:@"Main" bundle:nil] instantiateViewControllerWithIdentifier:@"ViewController"];
            [self.window.rootViewController.navigationController pushViewController:controller animated:YES];
 }

Для получения дополнительной информации о UNNotification или обработке локальных уведомлений, пожалуйста, обратитесь https://developer.apple.com/library/content/documentation/NetworkingInternet/Conceptual/RemoteNotificationsPG/SchedulingandHandlingLocalNotifications.html

...