ios - 如何使用 Swift 3 从 Facebook SDK 下载照片?
<p><p>在 iOS 应用中下载用户个人资料照片时出现崩溃:</p>
<pre><code>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 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
</code></pre>
<p>发生了什么事?在早期的 Swift 中它可以工作。</p>
<p>与 <a href="https://stackoverflow.com/questions/24231680/loading-downloading-image-from-url-on-swift" rel="noreferrer noopener nofollow">this</a> 得到相同的结果方法:</p>
<pre><code>URLSession.shared.dataTask(with: photoURL) {(dataPhoto, response, error) in
</code></pre></p>
<br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
<p><p>代替</p>
<pre><code>URL(fileURLWithPath: profilePictureURLStr)
</code></pre>
<p>需要像这样构建<strong>URL</strong>:</p>
<pre><code>let photoURL = URL(string: profilePictureURLStr)!
</code></pre></p>
<p style="font-size: 20px;">关于ios - 如何使用 Swift 3 从 Facebook SDK 下载照片?,我们在Stack Overflow上找到一个类似的问题:
<a href="https://stackoverflow.com/questions/39850413/" rel="noreferrer noopener nofollow" style="color: red;">
https://stackoverflow.com/questions/39850413/
</a>
</p>
页:
[1]