如何将文件添加到主包的/Library/Sounds 目录? [英] How do I add a file to the main bundle's /Library/Sounds directory?

查看:40
本文介绍了如何将文件添加到主包的/Library/Sounds 目录?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

根据

xcode -> 窗口 -> 设备,选择我的应用程序并显示容器,文件夹不存在

为了添加一些上下文,我正在为解析推送通知做自定义声音.服务器人员告诉我,当向许多用户广播时,在负载中为每个用户发送自定义声音字符串会太困难.作为解决方法,我尝试使用单个声音文件,每次用户选择新声音时都会动态覆盖该文件.

因此声音文件需要由系统自动检测,并且可以在运行时由应用程序修改.将文件添加到主包将不起作用,因为它是只读的.我希望 ~/Library/Sound 中的文件可以编辑.

我现在不知道如何进行.任何帮助将不胜感激.

更新:我错误地尝试在运行时使用

创建目录

 try fileManager.createDirectoryAtPath("Library/Sounds", withIntermediateDirectories: true, attributes: nil)

正确的代码应该是

 let libraryDir = NSSearchPathForDirectoriesInDomains(NSSearchPathDirectory.LibraryDirectory, NSSearchPathDomainMask.UserDomainMask, true)让 directoryPath = "\(libraryDir.first!)/Sounds"试试 fileManager.createDirectoryAtPath(directoryPath, withIntermediateDirectories: true, attributes: nil)

我对自定义声音问题的解决方案.

解决方案

您拥有的链接适用于 Mac!iOS 的正确文档应该是 这里

总而言之,您可以将声音文件作为应用程序包的非本地化资源添加到您的项目中.

According to Apple's documentation, sound file in the ~/Library/Sounds will be search by system when trying to play a sound. How do I add a sound file to this folder?

I tried to write to the folder in runtime, but has no permission. I added a Library/Sounds folder in xcode but it doesn't seems to copy over.

xcode -> window -> devices, select my app and show container, folder is not there

To add some context, I am doing custom sound for parse push notification. The server guy told me that when broadcasting to many users, sending a custom sound string in the payload for each user will be too difficult. As a work around, I am trying to use a single sound file that will be dynamically overwritten each time the user selects a new sound.

Thus the sound file need to be auto detected by the system and can be modified at run time by the app. Adding the file to the main bundle will not work as it is read only. I am hoping that a file in ~/Library/Sound will be editable.

I have no idea how to proceed at this point. Any help will be greatly appreciated.

Update: I incorrectly tried to create a directory at run time by using

        try fileManager.createDirectoryAtPath("Library/Sounds", withIntermediateDirectories: true, attributes: nil)

The correct code should be

        let libraryDir = NSSearchPathForDirectoriesInDomains(NSSearchPathDirectory.LibraryDirectory, NSSearchPathDomainMask.UserDomainMask, true)
        let directoryPath = "\(libraryDir.first!)/Sounds"
        try fileManager.createDirectoryAtPath(directoryPath, withIntermediateDirectories: true, attributes: nil)

My solution to the custom sound problem.

解决方案

the link you have is for Mac! the correct document for iOS should be here

in summary, you can just add the sound file to your project as a nonlocalized resource of the app bundle.

这篇关于如何将文件添加到主包的/Library/Sounds 目录?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆