How can I retrieve friend's picture through FBRequest in swift

时光总嘲笑我的痴心妄想 提交于 2019-12-13 01:29:38

问题


var friendRQ: FBRequest = FBRequest(forGraphPath: "me/taggable_friends?fields=name,picture.width(66).height(66)")

    friendRQ.startWithCompletionHandler({ (Connection, results, error) -> Void in
            self.FBData = results.objectForKey("data") as NSMutableArray
            println(self.FBData)
        })

I have no problem on retrieve the name, but picture.

FBData.picture reutrns a NSURL

picture =         {
        data =             {
            height = 68;
            "is_silhouette" = 0;
            url = "https://fbcdn-profile-a.akamaihd.net/hprofile-ak-xpa1/v/t1.0-1/c9.0.68.68/p68x68/10410849_1410555062563816_XXXXX70293207008499_n.jpg?oh=ddd9e2d36cc13bc0095b243097a199b4&oe=54FC0162&__gda__=1427125899_dc78acc5e14b7d25aee153ccf8bb1543";
            width = 68;
        };
    };

how can I show this picture properly in an ImageView?

    var picture: NSURL = FBFriendHelper.sharedInstance.FBData[indexPath.row].picture
    var data: AnyObject? = picture.valueForKey("data")

and then?


回答1:


    var FBpicture: NSURL = FBHelper.sharedInstance.FBData[indexPath.row].picture
    var url: NSURL = NSURL(string: String(FBpicture.valueForKey("data")?.url! as NSString) as String)!
    var picData: NSData = NSData(contentsOfURL: url)!
    cell.FBProfile.image = UIImage(data: picData)

I found the solution of mine code



来源:https://stackoverflow.com/questions/27345072/how-can-i-retrieve-friends-picture-through-fbrequest-in-swift

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!