本地通知自定义声音在 OS8.3 之后不播放

Local Notification custom sound NOT playing after OS8.3

Apple 将他们的 OS 更新到 8.3 后,我的本地自定义声音就无法播放。

我做的一切都是对的,因为它的工作<=8.2,所以代码应该不是问题,但以防万一我是这样创建我的通知的:

仅供参考,它们为 30 秒或更短

首先我使用 Apples supplied code

将它们转换为 caf 格式

然后我将它添加到我的项目中。我已经验证它在我的资源包中。我还验证了它们已分配给目标。

它仍然没有播放,但在所有以前的 OS 版本中播放。

这是我的日程安排方法:

- (void) scheduleLocalNotification {
NSString *localNotificationSound;
localNotificationSound = [[NSBundle mainBundle] pathForResource:@"Clock" ofType:@".caf"];

UILocalNotification *timerDoneNotification = [[UILocalNotification alloc] init];
timerDoneNotification.soundName = localNotificationSound;
timerDoneNotification.alertBody = @"Time Up!";
timerDoneNotification.alertAction = @"Reset";
timerDoneNotification.fireDate = [NSDate dateWithTimeIntervalSinceNow:secondsLeft];
timerDoneNotification.timeZone = [NSTimeZone defaultTimeZone];
[[UIApplication sharedApplication] scheduleLocalNotification:timerDoneNotification];
}

我没有阅读关于它为何必须是非本地化资源的部分:

You can package the audio data in an aiff, wav, or caf file. Then, in Xcode, add the sound file to your project as a nonlocalized resource of the app bundle.

所以我所做的就是将文件名包装在 stringWithFormat 中,它开始工作 post v8.3

timerDoneNotification.soundName = [NSString stringWithFormat:@"%@", localNotificationSound];