美文网首页iOS-OC初级iOS干货
本地推送 UILocalNotification 的 sound

本地推送 UILocalNotification 的 sound

作者: iStig | 来源:发表于2015-02-10 10:38 被阅读1836次

http://stackoverflow.com/questions/4188848/uilocalnotification-custom-sound

                    [[UIApplication sharedApplication] cancelAllLocalNotifications];
                    UILocalNotification *push = [[UILocalNotification alloc] init];
                    push.fireDate  = [NSDate dateWithTimeInterval:1 sinceDate:[NSDate date]];
                    push.alertBody = [NSString stringWithFormat:@"%@",bl.text];
                    //push.soundName = UILocalNotificationDefaultSoundName;//能够播放系统默认提示音;
                    //push.soundName = [[NSBundle mainBundle] pathForResource:@"pushSound" ofType:@"wav"];//用该方式获取的文件无法正常播放
                    push.soundName = @"push.wav";//文件保存在source目录下(放到其他工程目录下也是可行的)
                    NSDictionary * dic = @{@"major":bl.major,@"minor":bl.minor,@"x":bl.x,@"y":bl.y};
                    push.userInfo = dic;
                    [[UIApplication sharedApplication] scheduleLocalNotification:push];

//push.soundName = [[NSBundle mainBundle] pathForResource:@"pushSound" ofType:@"wav"];//用该方式获取的文件无法正常播放 push.soundName = @"pushSound.wav";//文件保存在source目录下(放到其他工程目录下也是可行的)

1.注意:音频文件时长需要小于30秒的。。
2.扩展思考下:能否使用Doucument目录下自己录制生成的音频文件来作为推送提示音

相关文章

网友评论

  • zhangferry:好吧,真是好难 :sweat:
  • zhangferry:楼主实现了吗,在document目录下的音频文件作为推送声音
    iStig:@勇闯天涯茉莉花茶 不好意思 没有用的 估计苹果 只能提前编译到xcode中才行

本文标题:本地推送 UILocalNotification 的 sound

本文链接:https://www.haomeiwen.com/subject/mdujxttx.html