Также во всех примерах, которые я читал об этом, использовался .withSecurityScope при установке закладку, но когда я пытаюсь реализовать их, я получаю сообщение об ошибке, сообщающее, что эту опцию нельзя использовать в iOS.
Код: Выделить всё
Cannot pass immutable value as inout argument: literals are not mutable
Код: Выделить всё
do {
/// Unpacking the Bookmark into our URL
musicUrl = try URL(resolvingBookmarkData: asana.musicBookmark, options: .withSecurityScope, relativeTo: nil, bookmarkDataIsStale: false)
musicSound = try AVAudioPlayer(contentsOf: musicUrl)
musicSound?.play()
musicSound?.numberOfLoops = 10000
} catch {
print("Failed to play Music: \(error.localizedDescription).")
}
Код: Выделить всё
/// We let the User choose a file, which is then returned as result
.fileImporter(isPresented: $chooseMusic, allowedContentTypes: [.item]) {result in
switch result {
case .success(let Fileurl):
let gotAccess = Fileurl.startAccessingSecurityScopedResource()
do {
asana.musicBookmark = try Fileurl.bookmarkData()
} catch {
print("JSONSerialization error:", error)
}
Fileurl.stopAccessingSecurityScopedResource()
case .failure(let error):
print(error)
}
}
Подробнее здесь: https://stackoverflow.com/questions/792 ... ot-compile
Мобильная версия