2015-10-31 105 views
1

步驟,我在我的項目完成:爲什麼FBlogin按鈕委託方法不能調用?

  1. Fb的APPID我創建:

  2. 我在info.plist加入這個關鍵。

  3. sdk全部導入到我的項目中。

  4. appdelegate.m文件

    -(BOOL)application:(UIApplication *)application 
          openURL:(NSURL *)url 
        sourceApplication:(NSString *)sourceApplication 
         annotation:(id)annotation { 
    
        NSString *stringURL = [ url absoluteString]; 
        if([stringURL containsString:@"fb"]) 
        { 
    
         return [[FBSDKApplicationDelegate sharedInstance] application:application 
                       openURL:url 
                    sourceApplication:sourceApplication 
                      annotation:annotation]; 
    
        } 
        else 
        { 
    
         return [GPPURLHandler handleURL:url 
             sourceApplication:sourceApplication 
              annotation:annotation]; 
    
        } 
    } 
    
  5. 我的按鈕類fbsdkloginbutton,委託成功給予視圖 - 控制

6. enter image description here

7.Two按鈕委派方法還實施

-(BOOL)loginButtonWillLogin:(FBSDKLoginButton *)loginButton 
{ 
    return YES; 
} 
-(void)loginButton:(FBSDKLoginButton *)loginButton didCompleteWithResult:(FBSDKLoginManagerLoginResult *)result error:(NSError *)error 

{ 
    if(error) 
    { 
     NSLog(@"==%@",error); 
    } 
    else 
    { 

     NSUserDefaults *pref=[NSUserDefaults standardUserDefaults]; 
     [pref setObject:_txtcity.text forKey:@"CITY"]; 

     [self _loadData]; 

    } 
} 
-(void)loginButtonDidLogOut:(FBSDKLoginButton *)loginButton 
{ 
    NSLog(@"user logged out"); 
    [[FBSDKLoginManager new] logOut]; 
} 

- (void)_loadData { 
// FBSDKGraphRequest *request=[[FBSDKGraphRequest alloc]initWithGraphPath:@"me" parameters:@{ @"fields" : @"id,name,picture.width(100).height(100),email"} tokenString:nil version:nil HTTPMethod:@"GET"]; 
    // For more complex open graph stories, use `FBSDKShareAPI` 
    // with `FBSDKShareOpenGraphContent` 
    /* make the API call */ 
    FBSDKGraphRequest *request = [[FBSDKGraphRequest alloc] 
            initWithGraphPath:@"/me" 
            parameters:@{ @"fields" : @"id,name,picture.width(100).height(100),emailid"} 
            HTTPMethod:@"GET"]; 
//  @{ @"fields" : @"id,name,picture.width(100).height(100),email"} 
    //@{ @"fields" : @"id,name,picture.width(100).height(100)"}] 
    // @{@"fields":@"email,public_profile"} 
    [request startWithCompletionHandler:^(FBSDKGraphRequestConnection *connection, 
              id result, 
              NSError *error) { 
     if(result) 
     { 
      NSLog(@"%@",connection); 
      // Handle the result 
      NSLog(@"%@",result); 
      NSDictionary *userData = (NSDictionary *)result; 
      NSLog(@"====%@",request); 
      NSString *facebookID = userData[@"id"]; 
      name = userData[@"name"]; 
      //     NSString *location = userData[@"location"][@"name"]; 

      email = userData[@"email"]; 
      imgurl = userData[@"picture"][@"data"][@"url"]; 
      NSLog(@"this is email=%@facebookid==%@name==%@picture url%@",email,facebookID,name,imgurl); 
      NSData *Data=[NSData dataWithContentsOfURL:[NSURL URLWithString:imgurl]]; 
      UIImage *image=[UIImage imageWithData:Data]; 
      datas.imgProfilePhoto=image; 
      [email protected]"1"; 
      [self multiform]; 
     } 


    }]; 


} 
+0

請參閱此鏈接可能是你的幫助http://stackoverflow.com/a/30275960/4536708 –

+0

@DharmeshDhorajiya所以你告訴改變我的代碼流? –

+0

@DharmeshDhorajiya它給我錯誤域= com.facebook.sdk.login代碼= 301「操作無法完成。(com.facebook.sdk.login錯誤301.)」 –

回答

1

確保按鈕給出FBSDKLoginButton類中XIB。

+0

是否需要給那個fbsdkloginbutton而不是我在裏面使用touchup方法.. –

+0

因爲當你加載xib時,你必須告訴xcode你想要加載哪個類的元素 –

相關問題