2012-10-11 20 views
10

से ऐप हटाते हैं तो मैं लॉग इन संभालता हूं, मैं अपने ऐप में कुछ फेसबुक एकीकरण रखना चाहता हूं। इस बिंदु पर मैंने लॉगिन करने, दोस्तों की दीवार पर पोस्ट करने, दोस्तों की सूची पुनर्प्राप्त करने में कामयाब रहे हैं। सब कुछ ठीक है ...फेसबुक एसडीके 3.1 आईओएस: अगर उपयोगकर्ता फेसबुक सेटिंग्स

यदि उपयोगकर्ता your Facebook settings/Applications से ऐप को हटा देता है और फिर प्रवेश करता है आईओएस ऐप, कोड यह नहीं पहचानता कि फेसबुक ऐप को उपयोगकर्ता सेटिंग्स से हटा दिया गया था और यह माना जाता है कि यह लॉग इन है (यह समस्या है क्योंकि यदि उपयोगकर्ता किसी मित्र की दीवार पर पोस्ट करने का प्रयास करता है, तो ऐप कुछ भी नहीं करता है)।

फिर, यदि उपयोगकर्ता IOS अनुप्रयोग बंद कर देता है और यह relaunches ... इस फिर से लॉन्च, iOS एप्लिकेशन "ठीक हो गई है" के साथ और पता लगाता है कि उपयोगकर्ता अब में लॉग ऑन है।

मैं करने के लिए प्रबंधन नहीं कर सकते पल का पता लगाने के उपयोगकर्ता आदेश उपयोगकर्ता के लिए लॉग इन प्रवाह को लाने के लिए सेटिंग्स से फेसबुक एप्लिकेशन को हटा देता है सही होने के बाद ...

यहाँ मेरी कोड है:

मेरे ऐप के पहले दृश्य में ...

if([FBSession activeSession].state == FBSessionStateCreatedTokenLoaded) 
{ 
    NSLog(@"Logged in to Facebook"); 
    [self openFacebookSession]; 
    UIAlertView *alertDialog; 

    alertDialog = [[UIAlertView alloc] initWithTitle:@"Facebook" message:@"You're already logged in to Facebook" delegate:nil cancelButtonTitle:@"Ok" otherButtonTitles:nil, nil]; 

    [alertDialog show]; 

    [alertDialog release]; 
    return YES; 
} 
else{ 
    NSLog(@"Not logged in to Facebook"); //Show the login flow 
    return NO; 
} 

यहाँ openFacebookSession

-(void)openFacebookSession 
{ 
    NSArray *permissions = [[NSArray alloc] initWithObjects: 
          @"publish_stream", 
          nil]; 

    [FBSession openActiveSessionWithPublishPermissions:permissions defaultAudience:FBSessionDefaultAudienceFriends allowLoginUI:YES completionHandler:^(FBSession *session, FBSessionState status, NSError *error) { 
     [self sessionStateChanged:session state:status error:error]; 
    }]; 
} 
के लिए कोड

sessionStateChanged के लिए कोड ...

-(void)sessionStateChanged:(FBSession *)session state:(FBSessionState)state error:(NSError *)error 
{ 
    switch (state) { 
     case FBSessionStateOpen: { 
      NSLog(@"Session opened"); 
     } 
      break; 
     case FBSessionStateClosed: 
     case FBSessionStateClosedLoginFailed: 
      [FBSession.activeSession closeAndClearTokenInformation]; 
      break; 
     default: 
      break; 
    } 

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

आपको बहुत बहुत धन्यवाद है!

+0

आपने इस समस्या को कैसे हल किया? – SAHM

+0

मैंने इसे अभी तक हल नहीं किया है ...: सी – Axort

+0

उस उत्तर ने मुझे मदद की http://stackoverflow.com/questions/12745235/handle-invalid-accesstoken-with-fbsession-openactivesessionwithreadpermissions-i – michael23

उत्तर

0

मुझे एक ही समस्या है और फेसबुक एसडीके साइट पर त्रुटि कोड के बारे में उचित दस्तावेज नहीं मिल सका।

मैंने [error code]; या [error userInfo]; मान की तुलना करके समस्या हल की।

आपका सत्र राज्य FBSessionStateClosedLoginFailed और त्रुटि के userInfo शब्दकोश निम्नलिखित रूप

"com.facebook.sdk:ErrorLoginFailedReason" = "com.facebook.sdk:ErrorLoginFailedReason"; 

दूसरी ओर त्रुटि कोड पर ही होगी मुझे 2 से पता चलता ताकि आप इसे sessionStateChanged के अंत में संभाल कर सकते हैं :: : समारोह

- (void)sessionStateChanged:(FBSession *)session 
        state:(FBSessionState)state 
        error:(NSError *)error { 
switch (state) { 
    case FBSessionStateOpen: { 
     //update permissionsArrat 
     [self retrieveUSerPermissions]; 

     if (!needstoReopenOldSession) { 
      //First User information 
      [self getUserInformation:nil]; 
     } 

     NSNotification *authorizationNotification = [NSNotification notificationWithName:facebookAuthorizationNotification object:nil]; 
     [[NSNotificationCenter defaultCenter] postNotification:authorizationNotification]; 

    } 
    case FBSessionStateClosed: { 
     break; 
    } 
    case FBSessionStateClosedLoginFailed: { 
     [FBSession.activeSession closeAndClearTokenInformation]; 
     break; 
    } 
    default: 
     break; 
} 

if (error) 
{ 
    NSNotification *authorizationNotification = [NSNotification notificationWithName:faceBookErrorOccuredNotification object:error]; 
    [[NSNotificationCenter defaultCenter] postNotification:authorizationNotification]; 
} 
} 
+0

हाय! आपकी प्रतिक्रिया के लिए धन्यवाद ... वास्तव में, sessionStateChanged विधि त्रुटि में हमेशा शून्य है। मुझे नहीं पता क्यों: सी। – Axort

+0

यदि त्रुटि शून्य है तो यह मामला नहीं हो सकता है FBSessionStateClosedLoginFailed –

+0

USerPermissions पुनर्प्राप्त क्या है? – Dejell

3

यह पता पार्स और दो कारणों के लिए त्रुटियों के इन प्रकार का पता लगाने के लिए वास्तव में बहुत मुश्किल है:

  1. मैं इस समस्या का पता लगाने के लिए किसी भी तरह यह पता लगाने नहीं कर सकते जब तक आप वास्तव में प्रयास और एक FBRequest (या समान) असफल, और
  2. NSError वस्तु में विफल रहा है FBRequest से पारित कर दिया मूर्खता से पार्स और किसी भी कार्यात्मक तरह से उपयोग करने के लिए मुश्किल है।

नीचे दी गई पागल विधि है जो सचमुच इस बात से निपटने के लिए एक अखिल-नाइट खींच रही है। यह असफल FBRequest प्रयास से NSError *error ऑब्जेक्ट को संभालता है, और इसे प्रासंगिक तरीकों से पास करता है या मुझे प्राप्त होने वाली सबसे समझदार त्रुटि प्रदर्शित करता है (या नीचे पकड़ने वाले सभी को हिट करता है)।

टिप्पणियों पर ध्यान दें - विशेष रूप से innerError और parsedResponse - जो विवरण मैंने अभी तक खोजा है। गुड लक, बहादुर सैनिक:

- (void)handleFacebookError:(NSError *)error 
     withPermissionType:(RMFacebookPermissionsType)type // this is just a typedef enum specifying Write or Read permissions so I can react accordingly 
      withCompletion:(void (^)(BOOL retry))completionBlock { 

    newMethodDebugLog; 
    NSParameterAssert(error); 
    NSParameterAssert(type); 
    NSParameterAssert(completionBlock); // the completion block tells the controller whether the error is 'fatal' or can be recovered - if YES, it can be recovered 

    // this is the parsed result of the graph call; some errors can appear here, too, sadly 
    NSDictionary *parsedResponse = [error.userInfo objectForKey:@"com.facebook.sdk:ParsedJSONResponseKey"]; 
    int parsedErrorCode = [[[[parsedResponse objectForKey:@"body"] 
          objectForKey:@"error"] 
          objectForKey:@"code"] 
          intValue]; 

    // this is an instance of NSError created by Facebook; it contains details about the error 
    NSError *innerError = [error.userInfo objectForKey:@"com.facebook.sdk:ErrorInnerErrorKey"]; 

    // innerError is usually un-recoverable 
    if (innerError) { 

     // innerError seems to be the response given in true HTTP problems; 
     DebugLog(@"______innerError FOUND______"); 
     DebugLog(@"innerError: %@",innerError); 
     DebugLog(@"innerError.code: %d",innerError.code); 

     // digging deep enough, you can actually find a coherent error message! :D 
     DebugLog(@"innerError.localizedDescription: %@",innerError.localizedDescription); 

     if (![alert isVisible]) { 

      NSString *errorString = @"Facebook Connection Failed"; 

      NSString *okString = @"OK"; 

      alert = [[UIAlertView alloc] initWithTitle:errorString 
               message:innerError.localizedDescription 
               delegate:nil 
            cancelButtonTitle:okString 
            otherButtonTitles:nil]; 

      [alert show]; 

     } else { 

      DebugLog(@"Alert already showing!"); 

     } 

     completionBlock(NO); 

    } else if (parsedResponse && 
       parsedErrorCode != 2) { // I honestly forget what error 2 is.. documentation fail :(

     // parsedResponses can usually be recovered 
     DebugLog(@"parsed response values: %@",[parsedResponse allValues]); 

     switch (parsedErrorCode) { 
      case 2500: 
      case 200: 
      case 190: 
      { 
       DebugLog(@"parsedError code hit! forcing re-login."); 

       // all errors in case 190 seem to be OAuth issues 
       // http://fbdevwiki.com/wiki/Error_codes#Parameter_Errors 
       // if needed, "error_subcode" 458 == user has de-authorized your app 
       // case 2500 reported while grabbing from a photo album & not logged in 
       // case 200 "requires extended permission: publish_actions" 

       if (type == RMFacebookPermissionsTypeRead) { 

        [self _getFacebookReadPermissionsWithUI:YES 
               completion:completionBlock]; 

       } else if (type == RMFacebookPermissionsTypeWrite) { 

        [self _getFacebookWritePermissionsWithUI:YES 
                completion:completionBlock]; 

       } 

       break; 
      } 

      default: 
       completionBlock(YES); 
       break; 
     } 

    } else { 

     if (![alert isVisible]) { 

      NSString *errorString = @"Facebook Error"; 

      NSString *messageString = @"Mixture Photos was unable to connect to Facebook on your behalf. This is usually a temporary problem. Please try again later."; 

      NSString *okString = @"OK"; 

      alert = [[UIAlertView alloc] initWithTitle:errorString 
               message:messageString 
               delegate:nil 
            cancelButtonTitle:okString 
            otherButtonTitles:nil]; 

      [alert show]; 

     } else { 

      DebugLog(@"Alert already showing!"); 

     } 

     completionBlock(NO); 

    } 
} 
5

मैं भी अपने आप को यह हो रहा है पाया .... जब कोई उपयोगकर्ता अपना फेसबुक पासवर्ड बदल दिया यह खोज की थी, और हम अब प्रमाणित कर सकता है। खाता सत्र के मैन्युअल रेजिन/स्पष्ट करने से उन्हें फिर से लॉगिन करने की अनुमति मिली।

-(void)syncFacebookAccount 
{ 
    [self forceLogout]; 
    ACAccountStore *accountStore = [[ACAccountStore alloc] init]; 
    ACAccountType *accountTypeFB = [accountStore   accountTypeWithAccountTypeIdentifier:@"com.apple.facebook"]; 
    if (accountStore && accountTypeFB) { 
    NSArray *fbAccounts = [accountStore accountsWithAccountType:accountTypeFB]; 
    id account; 
    if (fbAccounts && [fbAccounts count] > 0 && (account = [fbAccounts objectAtIndex:0])) { 
    [accountStore renewCredentialsForAccount:account completion:^(ACAccountCredentialRenewResult renewResult, NSError *error) { 
        // Not actually using the completion handler... 
    }]; 
      } 
     } 
    } 
संबंधित मुद्दे