我需要幫助附加從firebase下載的圖像,以便我可以使用它來共享UIActivityViewController。我得到正確的圖像,但不確定如何設置數據傳遞以讓它共享。當前設置在「objectsToShare = [self.image!]」上引發「線程1錯誤」。Swift Firebase爲UIActivityViewController附加圖片
let shareAction = UIAlertAction(title: "Share", style: UIAlertActionStyle.default, handler: {(alert: UIAlertAction!) in
var objectsToShare: [AnyObject]?
let titlePost = self.feeds[sender.tag].downloadURL
if let postURL = URL(string: titlePost) {
let postRequest = URLRequest(url: postURL)
self.image?.setImageWith(postURL, placeholderImage: nil, options: SDWebImageOptions.progressiveDownload, completed: { (imageRequest, imageResponse, error) -> Void in
// failure downloading image
print("Error downloading Firebase post image")
print(error)
})
}
objectsToShare = [self.image!]
let activityViewController = UIActivityViewController(activityItems: objectsToShare!, applicationActivities: nil)
// present the view controller
self.present(activityViewController, animated: true, completion: nil)
})
獲得「objectsToShare」爲零。也許我沒有正確下載圖像? –
需要一些時間才能正確加載圖像。當你分配圖像時,可能不是下載。因此,將該代碼移至完成塊,然後對其進行測試。 –