Advertisement
thieumao

Swift - Facebook SDK

May 13th, 2016
120
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Swift 2.31 KB | None | 0 0
  1. import UIKit
  2. import FBSDKCoreKit
  3. import FBSDKLoginKit
  4. import FBSDKShareKit
  5.  
  6. class ViewController: UIViewController, FBSDKLoginButtonDelegate {
  7.  
  8.     override func viewDidLoad() {
  9.         super.viewDidLoad()
  10.        
  11.         var loginButton:FBSDKLoginButton = FBSDKLoginButton()
  12.         loginButton.center = self.view.center
  13.         self.view.addSubview(loginButton)
  14.        
  15.         loginButton.delegate = self
  16.        
  17.         var contentShare:FBSDKShareLinkContent = FBSDKShareLinkContent()
  18.         var button:FBSDKShareButton = FBSDKShareButton()
  19.         button.frame = CGRectMake(200,500,100,50)
  20.        
  21.         var contentURL = NSURL(string: "https://xxx/")
  22.         var imgURL = NSURL(string: "xxx.png")
  23.         contentShare.imageURL = imgURL
  24.         contentShare.contentURL = contentURL
  25.         contentShare.contentTitle = "Tech Blog-"
  26.         contentShare.contentDescription = "Great, do you like this?"
  27.         button.shareContent = contentShare
  28.        
  29.         self.view.addSubview(button)
  30.        
  31.     }
  32.    
  33.     func loginButton(loginButton: FBSDKLoginButton!, didCompleteWithResult result: FBSDKLoginManagerLoginResult!, error: NSError!) {
  34.         print("Login success!")
  35. //        loadProfile()
  36.        
  37. //        // load avatar
  38. //        var hinh = FBSDKProfilePictureView(frame: CGRectMake(view.frame.size.width/2, 100, 100, 100))
  39. //        self.view.addSubview(hinh)
  40.        
  41. //        FBSDKShareDialog *dialog = [[FBSDKShareDialog alloc] init];
  42. //        dialog.fromViewController = self;
  43. //        dialog.content = content;
  44. //        dialog.mode = FBSDKShareDialogModeShareSheet;
  45. //        [dialog show];
  46.     }
  47.    
  48.     func loginButtonDidLogOut(loginButton: FBSDKLoginButton!) {
  49.         print("Logout success!")
  50.     }
  51.    
  52.     func loadProfile(){
  53.         var request:FBSDKGraphRequest = FBSDKGraphRequest(graphPath: "me?fields=id,name,gender", parameters: nil)
  54.         request.startWithCompletionHandler({
  55.             (connection,result,error)-> Void in
  56.             if error != nil {
  57.                 print("Error load Profile")
  58.             } else {
  59.                 print("Result: \(result)")
  60.             }
  61.         })
  62.     }
  63.  
  64.     override func didReceiveMemoryWarning() {
  65.         super.didReceiveMemoryWarning()
  66.         // Dispose of any resources that can be recreated.
  67.     }
  68.  
  69.  
  70. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement