在运行 iOS4 的 3G iPhone 上设置本地通知声音
我已使用以下代码在我的应用程序中成功安排了本地通知:
Class cls = NSClassFromString(@"UILocalNotification");
if (cls != nil) {
UILocalNotification *notification = [[cls alloc] init];
notification.fireDate = self.alarmNotificationDate;
notification.timeZone = [NSTimeZone defaultTimeZone];
notification.alertBody = @"Alarm is due";
notification.alertAction = @"Show Alarm";
notification.soundName = @"alarm.mp3";
[[UIApplication sharedApplication] scheduleLocalNotification:notification];
[notification release];
其中 self.alarmNotificationDate 是另一种方法中的 NSDate 分配。
在模拟器中一切正常,但当我在运行 iOS4 的值得信赖的旧 iPhone 3G 上进行测试时,我收到了通知,但仅使用默认声音。
我尝试过不同的声音文件,但没有成功。
任何线索为什么会这样以及如何纠正它?
谢谢
I have successfully scheduled local notifications in my app using the code below:
Class cls = NSClassFromString(@"UILocalNotification");
if (cls != nil) {
UILocalNotification *notification = [[cls alloc] init];
notification.fireDate = self.alarmNotificationDate;
notification.timeZone = [NSTimeZone defaultTimeZone];
notification.alertBody = @"Alarm is due";
notification.alertAction = @"Show Alarm";
notification.soundName = @"alarm.mp3";
[[UIApplication sharedApplication] scheduleLocalNotification:notification];
[notification release];
Where self.alarmNotificationDate is a NSDate assign in another method.
All works fine in the simulator, but when I test on my trusted old iPhone 3G running iOS4 I get the notification, but only with the default sound.
I have tried with different sound files but no success.
Any clue why it could be like this and how to correct it?
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
UILocalNotification 不支持 mp3。它仅支持参考页上提到的格式和容器。
http://developer.apple.com/库/ios/#documentation/NetworkingInternet/Conceptual/RemoteNotificationsPG/IPhoneOSClientImp/IPhoneOSClientImp.html
UILocalNotification does not support mp3. It only supports the formats and containers mentioned on the reference page.
http://developer.apple.com/library/ios/#documentation/NetworkingInternet/Conceptual/RemoteNotificationsPG/IPhoneOSClientImp/IPhoneOSClientImp.html
可能有几个原因:
There could be a couple of reasons:
您是否在文件名和文件名中使用相同的大写/小写编码来拼写声音名称?
Did you spell the name of the sound using the same upper/lower case encoding in both the file name and the filename?