如何将设备的系统铃声设置为本地通知声音?

德赫拉吉·古普塔

我想将设备的系统铃声设置为来自我的应用的本地通知声音。我得到了设备中存在的系统铃声列表,但由于在应用程序捆绑包中无法访问铃声路径,因此无法进行设置以进行通知。有什么方法可以获取访问权限并将其设置为通知声音

德赫拉吉·古普塔

经过大量研究,我可以解决我的问题,我只需要将系统/声音复制到Library / Sounds / notification.caf中,如下所示:

NSFileManager* fileManager = [NSFileManager defaultManager];
NSArray *libraryDir = NSSearchPathForDirectoriesInDomains(NSLibraryDirectory, NSUserDomainMask, YES);
NSString *lib = [libraryDir objectAtIndex:0];
NSString *directoryPath = [lib stringByAppendingString:@"/Sounds"];
@try {
    [fileManager createDirectoryAtPath:directoryPath withIntermediateDirectories:TRUE attributes:nil error:nil];
    NSString *systemSoundPath = fromPath; // eg. /System/Library/Audio/UISounds/Tink.caf
    NSString *notificationSoundPath = [directoryPath stringByAppendingString:@"/notification.caf"];
    BOOL fileExist = [fileManager fileExistsAtPath: notificationSoundPath];
    if(fileExist){
        [fileManager removeItemAtPath:notificationSoundPath error:nil];
    }
    [fileManager copyItemAtPath:systemSoundPath toPath:notificationSoundPath error:nil];

} @catch (NSException *exception) {
    NSLog(@"in catch");
} @finally {
    NSLog(@"in catch");
}

请检查它是否对其他人有帮助。

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

将通知声音设置为默认警报铃声

从资产设置本地通知自定义声音

如何获取系统铃声/声音

如何一次在本地通知中将日期数组设置为 fireDate

如何在 Flutter 中为工作日的多天设置本地通知?

本地通知声音没有播放?

如何为离子本机插件“本地通知”设置“ skipLocalNotificationReady”

您如何将设置值设置为null?

如何将铃声模式完全设置为静音?

如何将文件设置为Android 10的铃声?

如何将原始音频文件设置为铃声

如何只为特定日期设置本地通知,时间为 12PM 和 6PM

本地通知IONIC 3中的自定义声音

快速本地通知上缺少徽章和声音

选择本地通知的自定义声音

本地通知的自定义声音不起作用

在Android(使用Java)中,如何设置铃声音量(为指定数字)?

如何设置每隔48小时通知用户一次本地通知?

iOS设置-通知:如果我不使用本地通知,如何删除我的应用程序?

如何为API级别16以上的所有设备发送本地通知?

i2c子系统如何将设备与驱动程序匹配?

如何快速安排相同的本地通知

如何显示多个本地通知?

如何实施计划的本地通知

React Native 如何将时间和日期设置为本地设备?

如何每X分钟设置一次本地通知?

我如何让 datetimepicker 选择用户设置的部署本地通知的时间?

如何在 Ionic 3 中为 iOS 和 Android 的每 3 天本地通知自定义本地通知?

应用程序为前台时如何显示本地通知