IOS/Objective-C:在点击通知时将用户定向到应用程序的特定屏幕
IOS/Objective-C: Direct users to specific screen of app on clicking on notification
在 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
我正尝试为本地通知执行此操作,但无法弄清楚如何将用户定向到特定屏幕。 The docs 说您可以检查 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
在 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
我正尝试为本地通知执行此操作,但无法弄清楚如何将用户定向到特定屏幕。 The docs 说您可以检查 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