【问题标题】:How to download photo from Facebook SDK with Swift 3?如何使用 Swift 3 从 Facebook SDK 下载照片?
【发布时间】:2016-10-04 10:53:22
【问题描述】:

在 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

【问题讨论】:

    标签: ios facebook-graph-api swift3


    【解决方案1】:

    代替

    URL(fileURLWithPath: profilePictureURLStr)
    

    需要像这样构建URL

    let photoURL = URL(string: profilePictureURLStr)!
    

    【讨论】:

      猜你喜欢
      • 2011-09-10
      • 1970-01-01
      • 2016-05-08
      • 1970-01-01
      • 2017-12-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多