UNUserNotificationCenter *center = [UNUserNotificationCenter currentNotificationCenter];
[center requestAuthorizationWithOptions:UNAuthorizationOptionSound completionHandler:^(BOOL granted, NSError * _Nullable error) {
if(granted) {
UNMutableNotificationContent* content = [[UNMutableNotificationContent alloc] init];
UNNotificationSound* sound = [UNNotificationSound soundNamed:self.voiceArray[0]];
content.sound = sound;
UNTimeIntervalNotificationTrigger* tirgger = [UNTimeIntervalNotificationTrigger triggerWithTimeInterval:0.1
repeats:NO];
UNNotificationRequest* rt = [UNNotificationRequest requestWithIdentifier:@"notificationKey" content:content trigger:tirgger];
[[UNUserNotificationCenter currentNotificationCenter] addNotificationRequest:rt
withCompletionHandler:^(NSError* _Nullable error) {
NSLog(@"%@本地推送 :(%@", @"notificationKey", error);
if (self.voiceArray.count > 0) {
[self.voiceArray removeObjectAtIndex:0];
[self setLocalNotification];
}
else {
self.contentHandler(self.bestAttemptContent);
}
}
}];
}];
网友评论