在 iOS 应用中下载用户个人资料照片时出现崩溃:
let dataPhoto = try! Data(contentsOf: photoURL, options: .mappedIfSafe)
(lldb) po photoURL
▿ https:/scontent.xx.fbcdn.net/v/t1.0-1/p200x200/13418946_10208553701714177_3969269576626117653_n.jpg%3Foh=add39246ec9693ecead0529ecbbbfc53&oe=5862D7ED -- file:///
fatal error: 'try!' expression unexpectedly raised an error: Error Domain=NSCocoaErrorDomain Code=260 "The file “13418946_10208553701714177_3969269576626117653_n.jpg?oh=add39246ec9693ecead0529ecbbbfc53&oe=5862D7ED” couldn’t be opened because there is no such file." UserInfo={NSFilePath=/https:/scontent.xx.fbcdn.net/v/t1.0-1/p200x200/13418946_10208553701714177_3969269576626117653_n.jpg?oh=add39246ec9693ecead0529ecbbbfc53&oe=5862D7ED, NSUnderlyingError=0x170246000 {Error Domain=NSPOSIXErrorDomain Code=2 "No such file or directory"}}: file /Library/Caches/com.apple.xbs/Sources/swiftlang/swiftlang-800.0.46.2/src/swift/stdlib/public/core/ErrorType.swift, line 178
2016-10-04 12:48:14.317003 Movie Buffs[2722:1318691] fatal error: 'try!' expression unexpectedly raised an error: Error Domain=NSCocoaErrorDomain Code=260 "The file “13418946_10208553701714177_3969269576626117653_n.jpg?oh=add39246ec9693ecead0529ecbbbfc53&oe=5862D7ED” couldn’t be opened because there is no such file." UserInfo={NSFilePath=/https:/scontent.xx.fbcdn.net/v/t1.0-1/p200x200/13418946_10208553701714177_3969269576626117653_n.jpg?oh=add39246ec9693ecead0529ecbbbfc53&oe=5862D7ED, NSUnderlyingError=0x170246000 {Error Domain=NSPOSIXErrorDomain Code=2 "No such file or directory"}}: file /Library/Caches/com.apple.xbs/Sources/swiftlang/swiftlang-800.0.46.2/src/swift/stdlib/public/core/ErrorType.swift, line 178
发生了什么事?在早期的 Swift 中它可以工作。
与 this 得到相同的结果方法:
URLSession.shared.dataTask(with: photoURL) {(dataPhoto, response, error) in
代替
URL(fileURLWithPath: profilePictureURLStr)
需要像这样构建URL:
let photoURL = URL(string: profilePictureURLStr)!
关于ios - 如何使用 Swift 3 从 Facebook SDK 下载照片?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39850413/
欢迎光临 OGeek|极客世界-中国程序员成长平台 (https://ogeek.cn/) | Powered by Discuz! X3.4 |