【发布时间】:2014-01-23 07:34:27
【问题描述】:
我想完成闹钟或通知等功能。当应用程序在后台启动或未启动时,应用程序可以在我设置的时间到达时发出通知或声音提醒。 我尝试使用 UILocalNotification,但我发现 UILocalNotification 只能使用主包中的声音,不能使用我录制的声音。
【问题讨论】:
标签: ios push-notification
我想完成闹钟或通知等功能。当应用程序在后台启动或未启动时,应用程序可以在我设置的时间到达时发出通知或声音提醒。 我尝试使用 UILocalNotification,但我发现 UILocalNotification 只能使用主包中的声音,不能使用我录制的声音。
【问题讨论】:
标签: ios push-notification
要使用带有自定义声音的UILocalNotification,请使用以下代码:
UILocalNotification *notif = [[cls alloc] init];
[dateComp setDay:j+1];
[dateComp setHour:[[time objectAtIndex:0] integerValue]+offset];
[dateComp setMinute:[[time objectAtIndex:1] integerValue]];
NSLog(@"Year: %i, Month: %i, Day: %i, Time:%i:%i\n",[dateComp year], [dateComp month],
[dateComp day], [dateComp hour], [dateComp minute]);
notif.fireDate = [gregorian dateFromComponents:dateComp];
notif.timeZone = [NSTimeZone defaultTimeZone];
notif.alertBody = [names objectAtIndex: k];
notif.soundName = @"fireburn.caf";
有时您需要清理旧通知才能获得具有自定义声音的新通知。
所以你必须清理项目,从手机中删除应用程序并重新启动手机,然后它才能工作。
希望这会有所帮助!
【讨论】: