【问题标题】:how to accomplish an alarm clock or notification with my record sound如何用我的录音完成闹钟或通知
【发布时间】:2014-01-23 07:34:27
【问题描述】:

我想完成闹钟或通知等功能。当应用程序在后台启动或未启动时,应用程序可以在我设置的时间到达时发出通知或声音提醒。 我尝试使用 UILocalNotification,但我发现 UILocalNotification 只能使用主包中的声音,不能使用我录制的声音。

【问题讨论】:

    标签: ios push-notification


    【解决方案1】:

    要使用带有自定义声音的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";
    

    有时您需要清理旧通知才能获得具有自定义声音的新通知。

    所以你必须清理项目,从手机中删除应用程序并重新启动手机,然后它才能工作。

    希望这会有所帮助!

    【讨论】:

    • 谢谢!但是声音文件“fireburn.caf”必须在主包中,我想使用 AVAudioRecorder 来录制用户的声音用于 soundName。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-07-17
    • 2016-06-27
    相关资源
    最近更新 更多