2013-07-06 10 views
5

मैं अपने ViewController < FBLoginViewDelegate> को FBLoginView जोड़ रहा:FBLoginView: लॉगिन नहीं किया जाता है

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

सभी plist में आवश्यक क्षेत्रों (FacebookAppID, FacebookDisplayName, यूआरएल योजनाएं) सभी सेट कर रहे हैं ट्यूटोरियल के अनुसार । फेसबुक ऐप को ट्यूटोरियल के अनुसार भी कॉन्फ़िगर किया गया है (बंडल आईडी सेट है, फेसबुक लॉगिन सक्षम है)।


लेकिन लॉगिन अभी भी नहीं किया गया है। जब मैं "लॉग इन" पर दबाता हूं, तो मुझे फेसबुक लॉगिन के साथ ब्राउज़र पर रीडायरेक्ट किया जाता है, लेकिन जब यह समाप्त हो जाता है, तो मैं ऐप में लॉग इन नहीं करता हूं (loginViewFetchedUserInfo: उपयोगकर्ता: नहीं कहा जाता है, "लॉग इन" नहीं बदला है "लॉग आउट" करने के लिए)। समस्या क्या हो सकती है?

उत्तर

0

आप को लागू करने की आवश्यकता हो सकती है

(BOOL) आवेदन: (UIApplication *) आवेदन handleOpenURL: (NSURL *) यूआरएल विधि

कॉल करने के लिए सुनिश्चित करें:

return [FBSession.activeSession handleOpenURL:url];

लागू होने पर।

0

@ सर्गी: क्या आप अपने मूल ऐप या ब्राउज़र में एफबीडीअलॉग खोलना चाहते हैं? यदि आप अपने मूल ऐप में खोलना चाहते हैं तो "FBSessionLoginBehaviorForcingWebView" का उपयोग करें। यहाँ मेरी कोड है कि मैं का उपयोग कर रहा है:

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; 

या आप ब्राउज़र में खोलने के लिए उसके बाद निम्न का उपयोग करना चाहते हैं: के बाद मैं AppDelegate.m (एक से लिया में निम्नलिखित लागू किया

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

सब कुछ काम किया आधिकारिक उदाहरण के):

- (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

आप एप्लिकेशन प्रतिनिधि

के लिए निम्न जोड़ने की जरूरत
संबंधित मुद्दे