OGeek|极客世界-中国程序员成长平台

标题: ios - 如何在 objective-c 中取消本地单一通知 [打印本页]

作者: 菜鸟教程小白    时间: 2022-12-13 15:21
标题: ios - 如何在 objective-c 中取消本地单一通知

你能帮我如何在 iOS 10 中取消本地通知

UNUserNotificationCenter *center = [UNUserNotificationCenter currentNotificationCenter];
[center removeAllPendingNotificationRequests];
[center removePendingNotificationRequestsWithIdentifiers[ CYLInviteCategoryIdentifier ]];

removePendingNotificationRequestsWithIdentifiers 我看不懂



Best Answer-推荐答案


在创建本地通知时,您可以将标识符传递给每个通知。使用相同的标识符来移除本地通知。

创建本地通知的代码:-

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|极客世界-中国程序员成长平台 (http://sqlite.in/) Powered by Discuz! X3.4