application:didReceiveLocalNotification:
,而developer page并未指出任何替代方案。
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];
我已经使用适当的内容和触发器创建了上面的通知。现在我想在我点击通知时打开应用程序,但我似乎无法弄清楚如何。
答案 0 :(得分:0)
userNotificationCenter:didReceiveNotificationResponse:withCompletionHandler:
如果要执行自定义操作,则需要实现UNUserNotificationCenterDelegate
中的此方法。
- (void)userNotificationCenter:(UNUserNotificationCenter *)center didReceiveNotificationResponse:(UNNotificationResponse *)response withCompletionHandler:(void (^)())completionHandler {
if ([response.actionIdentifier isEqualToString:UNNotificationDefaultActionIdentifier]) {
NSLog(@"app opened");
}
}