2013-07-06 12 views
5

benim ViewController < FBLoginViewDelegate> için FBLoginView ekliyorum: öğretici göre plistFBLoginView: Oturum gerçekleştirilmez

FBLoginView *loginview = [[FBLoginView alloc] init];  
loginview.frame = CGRectOffset(loginview.frame, 5, 5); 
loginview.delegate = self;  
[self.view addSubview:loginview];  
[loginview sizeToFit]; 

Gerekli tüm alanlar (FacebookAppID, FacebookDisplayName URL Düzenleri) Tüm ayarlanır . Facebook uygulaması da öğreticiye göre yapılandırılmıştır (paket kimliği ayarlanmıştır, Facebook girişi etkinleştirilmiştir).(
)
Ancak oturum açma işlemi hala yapılmamıştır. "Oturum aç" a bastığımda, facebook oturum açarak tarayıcıya yönlendirilirim, ancak bittiğinde, uygulamada oturum açmıyorum (loginViewFetchedUserInfo: kullanıcı: çağrılmadı, "giriş yap" değişmedi "çıkış yapmak" için. Sorun ne olabilir?

cevap

0

Sen uygulamak gerekebilir

(BOOL) uygulaması: (UIApplication *) uygulama handleOpenURL: (NSURL *) url yöntemi

aramayı unutma:

return [FBSession.activeSession handleOpenURL:url]; Uygulanabilir olduğunda,

.

0

@Sergey: Yerel uygulamanızda veya tarayıcıda FBDialog açmak istiyor musunuz? Yerel uygulamanızda açmak isterseniz "FBSessionLoginBehaviorForcingWebView" öğesini kullanın. İşte kullanıyorum benim kodudur:

NSArray *permission = [NSArray arrayWithObjects:kFBEmailPermission,kFBUserPhotosPermission, nil]; 

FBSession *session = [[FBSession alloc] initWithPermissions:permission]; 

[FBSession setActiveSession: [[FBSession alloc] initWithPermissions:permission] ]; 

[[FBSession activeSession] openWithBehavior:FBSessionLoginBehaviorForcingWebView completionHandler:^(FBSession *session, FBSessionState status, NSError *error) { 

    switch (status) { 
     case FBSessionStateOpen: 
      [self yourmethod]; 
      break; 
     case FBSessionStateClosedLoginFailed: { 
      // prefer to keep decls near to their use 
      // unpack the error code and reason in order to compute cancel bool 
      NSString *errorCode = [[error userInfo] objectForKey:FBErrorLoginFailedOriginalErrorCode]; 
      NSString *errorReason = [[error userInfo] objectForKey:FBErrorLoginFailedReason]; 
      BOOL userDidCancel = !errorCode && (!errorReason || [errorReason isEqualToString:FBErrorLoginFailedReasonInlineCancelledValue]); 
      if(error.code == 2) { 
       UIAlertView *errorMessage = [[UIAlertView alloc] initWithTitle:@"FBAlertTitle" 
                     message:@"FBAuthenticationErrorMessage" 
                     delegate:nil 
                  cancelButtonTitle:@"Ok" 
                  otherButtonTitles:nil]; 
       [errorMessage performSelectorOnMainThread:@selector(show) withObject:nil waitUntilDone:YES]; 
       errorMessage = nil; 
      } 
     } 
      break; 
      // presently extension, log-out and invalidation are being implemented in the Facebook class 
     default: 
      break; // so we do nothing in response to those state transitions 
    } 
}]; 
permission = nil; 

veya sonra aşağıdaki kullanmak tarayıcıda açılmasını istiyorum: Ben birinden alınan AppDelegate.m (aşağıdaki uygulamaya sonra

In your .h file 

#import <FacebookSDK/FacebookSDK.h> and add FBLoginViewDelegate delegate 

In you .m file 
    FBLoginView *loginview = [[FBLoginView alloc] init]; 
    loginview.frame = CGRectOffset(loginview.frame, 5, 5); 
    loginview.delegate = self; 
    [self.view addSubview:loginview]; 
    [loginview sizeToFit]; 

// use following delegate methods 

- (void)loginViewShowingLoggedInUser:(FBLoginView *)loginView { 
    // first get the buttons set for login mode 
} 

- (void)loginViewFetchedUserInfo:(FBLoginView *)loginView 
          user:(id<FBGraphUser>)user { 
    // here we use helper properties of FBGraphUser to dot-through to first_name and 
    // id properties of the json response from the server; alternatively we could use 
    // NSDictionary methods such as objectForKey to get values from the my json object 
    NSLog(@"userprofile:%@",user); 
} 
- (void)loginViewShowingLoggedOutUser:(FBLoginView *)loginView { 
    //BOOL canShareAnyhow = [FBNativeDialogs canPresentShareDialogWithSession:nil]; 

} 

- (void)loginView:(FBLoginView *)loginView handleError:(NSError *)error { 
    // see https://developers.facebook.com/docs/reference/api/errors/ for general guidance on error handling for Facebook API 
    // our policy here is to let the login view handle errors, but to log the results 
    NSLog(@"FBLoginView encountered an error=%@", error); 
} 
2

Her şey çalıştı) resmi örneklerinden:

- (void)sessionStateChanged:(FBSession *)session 
         state:(FBSessionState) state 
         error:(NSError *)error 
{ 
    switch (state) { 
     case FBSessionStateOpen: 
      if (!error) { 
       // We have a valid session 
       //NSLog(@"User session found"); 
       [FBRequestConnection 
       startForMeWithCompletionHandler:^(FBRequestConnection *connection, 
                NSDictionary<FBGraphUser> *user, 
                NSError *error) { 
        if (!error) { 
         self.loggedInUserID = user.id; 
         self.loggedInSession = FBSession.activeSession; 
        } 
       }]; 
      } 
      break; 
     case FBSessionStateClosed: 
     case FBSessionStateClosedLoginFailed: 
      [FBSession.activeSession closeAndClearTokenInformation]; 
      break; 
     default: 
      break; 
    } 

    [[NSNotificationCenter defaultCenter] 
    postNotificationName:FBSessionStateChangedNotification 
    object:session]; 

    if (error) { 
     UIAlertView *alertView = [[UIAlertView alloc] 
            initWithTitle:@"Error" 
            message:error.localizedDescription 
            delegate:nil 
            cancelButtonTitle:@"OK" 
            otherButtonTitles:nil]; 
     [alertView show]; 
    } 
} 

/* 
* Opens a Facebook session and optionally shows the login UX. 
*/ 
- (BOOL)openSessionWithAllowLoginUI:(BOOL)allowLoginUI { 
    return [FBSession openActiveSessionWithReadPermissions:nil 
               allowLoginUI:allowLoginUI 
             completionHandler:^(FBSession *session, 
                  FBSessionState state, 
                  NSError *error) { 
              [self sessionStateChanged:session 
                   state:state 
                   error:error]; 
             }]; 
} 

/* 
* 
*/ 
- (void) closeSession { 
    [FBSession.activeSession closeAndClearTokenInformation]; 
} 

/* 
* If we have a valid session at the time of openURL call, we handle 
* Facebook transitions by passing the url argument to handleOpenURL 
*/ 
- (BOOL)application:(UIApplication *)application 
      openURL:(NSURL *)url 
    sourceApplication:(NSString *)sourceApplication 
     annotation:(id)annotation { 
    // attempt to extract a token from the url 
    return [FBAppCall handleOpenURL:url sourceApplication:sourceApplication]; 
} 
2

veya uygulama temsilci

için aşağıdaki eklemem gerekiyor
İlgili konular