你能帮我如何在 iOS 10 中取消本地通知
UNUserNotificationCenter *center = [UNUserNotificationCenter currentNotificationCenter];
[center removeAllPendingNotificationRequests];
[center removePendingNotificationRequestsWithIdentifiers[ CYLInviteCategoryIdentifier ]];
removePendingNotificationRequestsWithIdentifiers
我看不懂
在创建本地通知时,您可以将标识符传递给每个通知。使用相同的标识符来移除本地通知。
创建本地通知的代码:-
NSString *identifier = @"Unique Identifier";
UNNotificationRequest *request = [UNNotificationRequest requestWithIdentifier:identifier content:content trigger:trigger]
[center addNotificationRequest:request withCompletionHandler:^(NSError * _Nullable error) {
if (error != nil) {
NSLog(@"Something went wrong: %@",error);
}
}];
取消通知的代码:-
UNUserNotificationCenter *center = [UNUserNotificationCenter currentNotificationCenter];
NSArray *array = [NSArray arrayWithObjects"Identifier1",@"Identifier2", nil];
[center removePendingNotificationRequestsWithIdentifiers:array];
关于ios - 如何在 objective-c 中取消本地单一通知,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43773383/
欢迎光临 OGeek|极客世界-中国程序员成长平台 (https://ogeek.cn/) | Powered by Discuz! X3.4 |