swift: 如何从资产目录中获取资产
swift: How do I get an asset from the asset catalog
尝试使用 WatchKit 时
let asset = NSDataAsset(name:"ASSET-NAME")
XCode 抛出以下错误 Use of unresolved identifier 'NSDataAsset'
那么如何使用 WatchKit 从资产目录中获取(声音)文件?
根据,您可以通过
获取您的音频文件
let filePath = Bundle.main.path(forResource: "fileName", ofType: "m4a")!
let fileUrl = URL(fileURLWithPath: filePath)
let asset = WKAudioFileAsset(URL: fileUrl)
尝试使用 WatchKit 时
let asset = NSDataAsset(name:"ASSET-NAME")
XCode 抛出以下错误 Use of unresolved identifier 'NSDataAsset'
那么如何使用 WatchKit 从资产目录中获取(声音)文件?
根据
let filePath = Bundle.main.path(forResource: "fileName", ofType: "m4a")!
let fileUrl = URL(fileURLWithPath: filePath)
let asset = WKAudioFileAsset(URL: fileUrl)