如何将文件添加到主包的/ Library / Sounds目录中? [英] How do I add a file to the main bundle's /Library/Sounds directory?
问题描述
根据
xcode - >窗口 - >设备,选择我的应用程序并显示容器,文件夹不存在
要添加一些上下文,我正在为解析推送通知做自定义声音。服务器人告诉我,当向许多用户广播时,为每个用户在有效载荷中发送自定义声音字符串将非常困难。作为解决方法,我试图使用单个声音文件,每次用户选择新声音时都会动态覆盖。
因此声音文件需要是由系统自动检测,并可由应用程序在运行时进行修改。将文件添加到主包不起作用,因为它是只读的。我希望〜/ Library / Sound中的文件可以编辑。
我不知道如何继续这一点。任何帮助将不胜感激。
更新:
我错误地尝试使用
$ b在运行时创建目录$ b
尝试fileManager.createDirectoryAtPath(Library / Sounds,withIntermediateDirectories:true,attributes:nil)
正确的代码应该是
让libraryDir = NSSearchPathForDirectoriesInDomains(NSSearchPathDirectory.LibraryDirectory, NSSearchPathDomainMask.UserDomainMask,true)
let directoryPath =\(libraryDir.first!)/ Sounds
try 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屋!