2016-07-22 73 views
0

在我的main.storyboard我有一個UIImage視圖,這只是一個通用的Facebook登錄按鈕。不過,我很困惑,因爲使用這些通用的步驟使UIImageView充當Facebook登錄按鈕

override func viewDidLoad(){ 
{ 
    super.viewDidLoad() 
    var imageView = <# imageView #> 
    let tapGestureRecognizer = UITapGestureRecognizer(target:self, action:Selector("imageTapped:")) 
    imageView.userInteractionEnabled = true 
    imageView.addGestureRecognizer(tapGestureRecognizer) 
} 

func imageTapped(img: AnyObject) 
{ 
// The Action 
} 

我有點失去了,什麼The Action會在這種情況下,我需要通過Facebook的SDK鏈接的一切。

+0

有你安裝FBSDK? – Happiehappie

+0

是的我已經安裝了FBSDK並配置了我的'info.plist',另外我已經導入了FBSDKCoreKit和FBSDKLoginKit – bananibau5

+0

使用自定義按鈕作爲您的概念 –

回答

0
-(void)imgtapped 
{ 
     FBSDKLoginManager *login = [[FBSDKLoginManager alloc] init]; 
    [login 
    logInWithReadPermissions: @[@"public_profile"] 
      fromViewController:self 
        handler:^(FBSDKLoginManagerLoginResult *result, NSError *error) { 
      if (error) { 
       NSLog(@"Process error"); 
      } else if (result.isCancelled) { 
       NSLog(@"Cancelled"); 
      } else { 
       NSLog(@"Logged in"); 
      } 
    }]; 
} 
0

在你imageTapped

func imageTapped() { 
     let manager = FBSDKLoginManager() 
     manager.logInWithReadPermissions(["public_profile"], fromViewController: self, handler: { result, error in 
     if error != nil { 
      print("process error") 
     } else if result.isCancelled { 
      print("cancelled log in") 
     } else { 
      print("logged in") 
     } 
    }) 
}