![](/img/trans.png)
[英]How to retrieve an image from fbprofilepictureview and store this image into database
[英]Get an image from FBProfilePictureView swift
使用fb登錄時,以下UIView顯示用戶個人資料圖片
@IBOutlet var profilePictureView : FBProfilePictureView
我將如何獲取圖像以便可以在其他地方使用/將其保存到服務器?
這是FBProfilePictureView上的fb文檔(在Objective-C中) https://developers.facebook.com/docs/reference/ios/current/class/FBProfilePictureView這是fb登錄的快捷端口,效果很好。 https://www.snip2code.com/Snippet/68653/This-is-a-swift-port-of-of-official-Fac這是相同的代碼,但是在目標C中, 如何將FBProfilePictureView轉換為UIImage ?
如您鏈接到的答案( https://stackoverflow.com/a/12479572/2274694 )中所述,您可以像對待任何UIView
一樣對待FBProfilePictureView
並遍歷子視圖,以便找到UIImageView
並訪問圖像:
var image:UIImage!
for obj in profilePictureView.subviews {
if obj is UIImageView {
let objImg = obj as UIImageView
image = objImg.image
break
}
}
您也可以使用備用提示
目標C
NSString *userImageURL = [NSString stringWithFormat:@"https://graph.facebook.com/%@/picture?type=large", [FBuser objectID]];
也改變類型
迅速
let avatar = "https://graph.facebook.com/\(user.objectID)/picture?width=640&height=640"
或其他選擇
let url = NSURL.URLWithString("https://graph.facebook.com/\(user.objectID)/picture?width=640&height=640");
let data = NSData(contentsOfURL: url!) //make sure your image in this url does exist, otherwise unwrap in a if let check
yourimagename.image = UIImage(data: data!)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.