Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

iOS

How to display facebook profile picture on app. I got the login to work fine.

import UIKit import Foundation

class ViewController: UIViewController, FBLoginViewDelegate { //iboutlet

@IBOutlet var fbLoginView : FBLoginView!




override func viewDidLoad() {
    super.viewDidLoad()
    // Do any additional setup after loading the view, typically from a nib.

    self.fbLoginView.delegate = self
    self.fbLoginView.readPermissions = ["public_profile", "email", "user_friends"]


}

func loginViewShowingLoggedInUser(loginView : FBLoginView!) {
    println("User Logged In")
    println("This is where you perform a segue (and or another view).")
}

func loginViewFetchedUserInfo(loginView : FBLoginView!, user: FBGraphUser){
    println("User Name: \(user.name)")



}



func loginViewShowingLoggedOutUser(loginView : FBLoginView!) {
    println("User Logged Out")
}

func loginView(loginView : FBLoginView!, handleError:NSError) {
    println("Error: \(handleError.localizedDescription)")
}


override func didReceiveMemoryWarning() {
    super.didReceiveMemoryWarning()
    // Dispose of any resources that can be recreated.
}

}

//View1 aka login.

View2 is where i would like to display the profile picture :

import UIKit import Foundation

class view2: UIViewController { //iboutlet

@IBOutlet var profilePictureView : FBProfilePictureView!

override func viewDidLoad() {
    super.viewDidLoad()
    println("Second view entered")
    // Do any additional setup after loading the view, typically from a nib.


   }



func loginViewFetchedUserInfo(profilePictureView : FBProfilePictureView!, user: FBGraphUser){


    profilePictureView.profileID = user.objectID
    var url: NSURL = NSURL.URLWithString("https://graph.facebook.com/(user.objectID)/picture?type=normal")
    var data: NSData = NSData.dataWithContentsOfURL(url, options: nil, error: nil)



}


override func didReceiveMemoryWarning() {
    super.didReceiveMemoryWarning()
    // Dispose of any resources that can be recreated.
}

}

5 Answers

Ok let's see

yes

Try using:

FBRequestConnection startWithGraphPath:"/me/picture" ....

func loginViewFetchedUserInfo doesnt seem to be called in view2 how do i force it to be called? user: FBGraphUser var is in view1.swift

func loginViewFetchedUserInfo doesnt seem to be called in view2 how do i force it to be called? user: FBGraphUser var is in view1.swift

func loginViewFetchedUserInfo doesnt seem to be called in view2 how do i force it to be called? user: FBGraphUser var is in view1.swift

loginViewFetchedUserInfo is not call because it's not a FBLoginViewDelegate

i guess i dont fully understand delegate. I assumed since im not using FBLoginView i do not need it. More confused now