iOS 自定义通知声音

官方文档

https://developer.apple.com/library/content/documentation/NetworkingInternet/Conceptual/RemoteNotificationsPG/SupportingNotificationsinYourApp.html#//apple_ref/doc/uid/TP40008194-CH4-SW10

重点提示:
1、格式

  • Linear PCM
  • MA4 (IMA/ADPCM)
  • µLaw
  • aLaw
    2、文件必须写在app bundle 或者沙盒Library/Sounds文件夹中
Place custom sound files in your app bundle or in the Library/Sounds folder of your app’s container directory. Custom sounds must be under 30 seconds when played. If a custom sound is over that limit, the default system sound is played instead.

3、读取文件直接写名字@"name",不用写

[NSBundle mainBundle] pathForResource:<#(nullable NSString *)#> ofType:<#(nullable NSString *)#>

或者沙盒路径。

附带将自己plist文件存入沙盒中代码

/* 写音频文件  */
- (void)writeMusicData {
    NSString *bundlePath = [PPSDKbundle pathForResource:@"voip_call" ofType:@"caf"];
    NSString *libPath = [NSHomeDirectory() stringByAppendingString:@"/Library/Sounds/"];

    NSFileManager *manager = [NSFileManager defaultManager];
    if (![manager fileExistsAtPath:libPath]) {
        NSError *error;
        [manager createDirectoryAtPath:libPath withIntermediateDirectories:YES attributes:nil error:&error];
    }

    NSData *data = [NSData dataWithContentsOfFile:bundlePath];
    BOOL flag = [data writeToFile:[libPath stringByAppendingString:@"voip_call.caf"] atomically:YES];
    if (flag) {
        NSLog(@"文件写成功");
    }else{
        NSLog(@"文件写失败");
    }
}

小礼物走一走,来简书关注我



作者:Jessica124
链接:https://www.jianshu.com/p/a6eba8cfbe40
來源:简书
简书著作权归作者所有,任何形式的转载都请联系作者获得授权并注明出处。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值