How do I add a file to the main bundle's /Library/Sounds directory?

前端 未结 3 653
闹比i
闹比i 2021-02-08 10:57

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

3条回答
  •  执念已碎
    2021-02-08 11:44

    I struggled with this as well. You have to create the Library/Sounds directory programmatically and move your custom sound into it.

    let soundsDirectoryURL = fileManager.urls(for: .libraryDirectory, in: .userDomainMask).first!.appendingPathComponent("Sounds")
    
    //attempt to create the folder
    do {
        try fileManager.createDirectory(atPath: soundsDirectoryURL.path,
                                        withIntermediateDirectories: true, attributes: nil)
    } catch let error as NSError {
        print("Error: \(error.localizedDescription)")
    }
    

提交回复
热议问题