iOS 自定义Push声音

应用场景:多套声音,供用户动态选择

实现:

1、server端去修改

2、nativeiOS10后根据iOS使用Notification Service Extension统计iOS 10后的Push到达率
动态下载

3、native端修改

具体来讲:声音文件可以放到app bundle里面,或者如果是从网上下载的话就放在你pp沙盒目录下的Library/Sounds。自定义声音必须少于30秒。如果大于30秒将会用默认的系统的提示音取代。

bundle与沙盒声音重名 播放沙盒中的

当bundle里没有则播放默认声音(iOS 8.4.1版本 播放默认声音)

-(NSString *)libraryPath {
    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSLibraryDirectory, NSUserDomainMask, YES);
    NSString *libraryPath = [paths lastObject];
    //    NSLog(@"%@", libraryPath);
    return libraryPath;
}

- (void)setData {

    NSString *path = [self libraryPath];

    NSString *dataFilePath = [path stringByAppendingPathComponent:@"Sounds"];


    NSFileManager *fileManager = [NSFileManager defaultManager];

    BOOL isDir = NO;

    // fileExistsAtPath 判断一个文件或目录是否有效,isDirectory判断是否一个目录
    BOOL existed = [fileManager fileExistsAtPath:dataFilePath isDirectory:&isDir];

    if ( !(isDir == YES && existed == YES) ) {

        // 在 Document 目录下创建一个 head 目录
        [fileManager createDirectoryAtPath:dataFilePath withIntermediateDirectories:YES attributes:nil error:nil];

        NSString *mp3Path = [[NSBundle mainBundle] pathForResource:@"newOrder_1" ofType:@".mp3"];

        NSString *copyPath = [dataFilePath stringByAppendingPathComponent:@"newOrder.mp3"];;

        NSError *err;

        [fileManager copyItemAtPath:mp3Path toPath:copyPath error:&err];

    }

    NSLog(@"+++++++++++++++++++%@",dataFilePath);

}

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • 网上介绍iOS Push的文章有很多,但是大部分都总结得非常零散,加上之前也一直没好好总结过,对某些地方也不求甚解...
    纸简书生阅读 7,873评论 1 29
  • Swift版本点击这里欢迎加入QQ群交流: 594119878最新更新日期:18-09-17 About A cu...
    ylgwhyh阅读 25,670评论 7 249
  • 六年前,女友安然恶狠狠地对我说: 晚情,今天我在这里跟你发誓,我一定会让那王八蛋后悔,我一定会狠狠报复他。 我一定...
    小团阅读 3,863评论 0 1
  • 这是暗物质,小能熊365天写作计划第四天的写作内容,谢绝转载。 不过他很快发现自己错了,在继续杀掉五个人之后,灰壳...
    黑暗物质阅读 1,488评论 0 0
  • 感冒中医症名为“伤风” 感冒是以恶寒发热,鼻塞喷嚏流涕,咳嗽,头痛,全身不适等为主症一种常见的外感病。 本病的发生...
    问痧堂唐永佳阅读 2,875评论 0 1