在appDelegate的默认- (void)applicationDidBecomeActive:(UIApplication *)application {
方法中,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。
这似乎是一个常见的用例,我们一直点击通知,将我们带到应用程序的特定部分,但没有找到任何好的资源。
提前感谢您的任何建议。
您必须根据您实现的通知在AppDelegate.m
文件中使用didReceiveLocalNotification
或didReceiveNotificationResponse
委托方法
对于 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