【发布时间】:2023-03-22 08:40:01
【问题描述】:
我需要从存储中下载 pdf 并将其保存在本地 iOS 设备上,以便可以在“文件”中看到它。
这里的代码取自我正在使用的文档:
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view.
let userID = Auth.auth().currentUser!.uid
print(userID)
// Get a reference to the storage service using the default Firebase App
let storage = Storage.storage()
// Create a storage reference from our storage service
let storageRef = storage.reference()
// Create a reference to the file you want to download
let islandRef = storageRef.child("pdf/sample.pdf")
// Create local filesystem URL
let localURL = URL(string: "pdf/sample.pdf")!
// Download to the local filesystem
let downloadTask = islandRef.write(toFile: localURL) { url, error in
if let error = error {
// Uh-oh, an error occurred!
} else {
// Local file URL for "images/island.jpg" is returned
}
}
}
当我尝试运行这个 ViewController 时,它不会崩溃,但会抛出以下错误:
"The file couldn’t be opened because the specified URL type isn’t supported." UserInfo={NSURL=pdf/sample.pdf}
Firebase 存储中的文件保存在名为 pdf/sample.pdf 的文件夹中。最后,我希望从存储中获取引用并将其传递给RealtimeDatabase,以便用户可以通过在表格视图中查看有关它的详细信息来下载它。
【问题讨论】:
-
如果您选中此NSTransportSecurity,那么您的问题可能会得到解决。
-
@Emon 我在 info.plist 文件中进行了以下更改,我添加了此代码
<key>NSAppTransportSecurity</key> <dict> <key>NSAllowsArbitraryLoads</key><true/> </dict>。不幸的是,它不起作用。 -
你仍然面临同样的错误?
-
@Emon 没有错误,但文件不会下载。
-
现在检查您的网址,是不是您的预期网址?
标签: ios swift firebase firebase-realtime-database