你能帮我看看如何在 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];
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)