我正在发出本地通知。由于UILocalNotification
iOS 10 中不推荐使用 class,因此我使用了UserNotifications.framework
.
当我尝试为通知设置自定义声音时,默认声音一直在播放。
这是我的代码:
- (IBAction)fireLocalNotification:(id)sender {
UNMutableNotificationContent* content = [[UNMutableNotificationContent alloc] init];
content.title = [NSString localizedUserNotificationStringForKey:@"Hello!" arguments:nil];
content.body = [NSString localizedUserNotificationStringForKey:@"Hello_message_body"
arguments:nil];
content.sound = [UNNotificationSound soundNamed:@"sound.mp3"];
// Deliver the notification in five seconds.
UNTimeIntervalNotificationTrigger* trigger = [UNTimeIntervalNotificationTrigger
triggerWithTimeInterval:5 repeats:NO];
UNNotificationRequest* request = [UNNotificationRequest requestWithIdentifier:@"FiveSecond"
content:content trigger:trigger];
// Schedule the notification.
UNUserNotificationCenter* center = [UNUserNotificationCenter currentNotificationCenter];
[center addNotificationRequest:request withCompletionHandler:^(NSError *error){
if(!error){
NSLog(@"Completion handler for notification");
}
}];
}
我的声音很好;sound.mp3 存在于项目包本身中。
更多信息: https ://developer.apple.com/reference/usernotifications/unusernotificationcenter?language=objc