我要解雇当地的通知。由于UILocalNotification类在iOS 10中不受欢迎,所以我使用了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
发布于 2016-10-24 10:58:21
尝试从设备中删除应用程序,在设备上再次清理和运行应用程序。
有时,资源没有得到适当的更新;我认为这就是您的问题所在。
发布于 2017-06-16 22:54:08
https://stackoverflow.com/questions/40215838
复制相似问题