美文网首页
iOS 自定义通知声音

iOS 自定义通知声音

作者: Jessica124 | 来源:发表于2017-05-26 17:32 被阅读354次

    官方文档

    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(@"文件写失败");
        }
    }
    

    相关文章

      网友评论

          本文标题:iOS 自定义通知声音

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