2

I have an application in Xcode 4.5 which integrates Facebook. I am using ARC. The application uses native dialogs and therefore deprecated headers (ie Facebook.h). Apparently doing so leads to the following error when closing/cleaning the active session:

"An instance 0xa089350 of class FBSessionManualTokenCachingStrategy was deallocated while key value observers were still registered with it. Observation info was leaked, and may even become mistakenly attached to some other object."

Upon researching this error, I assume that the issue is that when I init an instance of self.Facebook in the app delegate, Facebook adds two observers rather than one, and then only one is cleaned up during logout. I have made numerous attempts to remove both instances, including every solution on this page regarding this very error: facebook ios sdk log : strange message

None of these solutions have worked for me, including one solution I saw which involved deallocation which I cannot use as I am using ARC. Here is my code for opening and closing a session for reference:

- (void)sessionStateChanged:(FBSession *)session
                  state:(FBSessionState) state
                  error:(NSError *)error
{
switch (state) {
    case FBSessionStateOpen:
        if (!error) {
            // We have a valid session

            // Initiate a Facebook instance

            self.facebook = [[Facebook alloc]
                             initWithAppId:FBSession.activeSession.appID
                             andDelegate:nil];

            // Store the Facebook session information
             self.facebook.accessToken = FBSession.activeSession.accessToken;
            self.facebook.expirationDate = FBSession.activeSession.expirationDate;

        }
        break;
    case FBSessionStateClosed:
    case FBSessionStateClosedLoginFailed:
        [FBSession.activeSession closeAndClearTokenInformation];
        // Clear out the Facebook instance
        self.facebook = nil;
        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 //do I need this method?
{
NSArray *permissions = [[NSArray alloc] initWithObjects:
                        @"user_about_me",
                        @"read_friendlists",
                        @"read_stream",
                        @"friends_likes",
                        @"user_likes",
                        @"friends_photos",
                        @"user_photos",
                        nil];

return [FBSession openActiveSessionWithReadPermissions:permissions
                                          allowLoginUI:allowLoginUI
                                     completionHandler:^(FBSession *session,    
                                                    FBSessionState state,
                                                         NSError *error) {
                                         [self sessionStateChanged:session state:state
                                                             error:error]; }];
}

/*
 * 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 [FBSession.activeSession handleOpenURL:url];
}

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

If anyone can offer any guidance as to how to solve this I would greatly appreciate it.

Community
  • 1
  • 1
jac300
  • 5,182
  • 14
  • 54
  • 89

0 Answers0