繁体   English   中英

使用新通知机制点击本地通知时如何打开应用程序?

[英]How do I open the app when local notification is tapped with the new notification mechanisms?

application:didReceiveLocalNotification: didReceiveLocalNotification application:didReceiveLocalNotification:从iOS10开始不推荐使用, 开发者页面也没有指向任何替代品。

UNNotificationRequest* request = [UNNotificationRequest requestWithIdentifier:@"localnotification"
                                                                      content:content
                                                                      trigger:trigger];


UNUserNotificationCenter* notificationCenter = [UNUserNotificationCenter currentNotificationCenter];
[notificationCenter requestAuthorizationWithOptions:(UNAuthorizationOptionBadge | UNAuthorizationOptionSound | UNAuthorizationOptionAlert)
                                  completionHandler:^(BOOL granted, NSError * _Nullable error) {
                          if (!error) {
                              NSLog(@"request authorization succeeded!");
                          }
                      }];


[notificationCenter addNotificationRequest:request
                     withCompletionHandler:nil];

我已经使用适当的内容和触发器创建了如上所示的通知。 现在我想在我点击通知时打开应用程序,但我似乎无法弄清楚如何。

userNotificationCenter:didReceiveNotificationResponse:withCompletionHandler:

如果要执行自定义操作, UNUserNotificationCenterDelegate需要实现UNUserNotificationCenterDelegate此方法。

- (void)userNotificationCenter:(UNUserNotificationCenter *)center didReceiveNotificationResponse:(UNNotificationResponse *)response withCompletionHandler:(void (^)())completionHandler {
    if ([response.actionIdentifier isEqualToString:UNNotificationDefaultActionIdentifier]) {
        NSLog(@"app opened");
    }
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM