views:

189

answers:

1

hi . i implement Facbook connect for my app on the AnotherViewController [based on NavigationController Project] , on there i have something to share to facebook . so when put this code on the viewDidLoad . when user go to AnotherViewController with Push animation . my FBSession appear to login !! i want when user select the button and actionSheet appear then decide to login to facebook

- (void)actionSheet:(UIActionSheet *)menu didDismissWithButtonIndex:(NSInteger)buttonIndex {

    switch (buttonIndex) {
        case 0:

            session = [FBSession sessionForApplication:@"587421274743043f3177a2f86684e533" secret:@"d22ad909a2e670269edd4d4e79c61c2a" delegate:self];
                [session resume];     
            if( session.isConnected )
            {                    

                [self showFBFeed];
            }
            else
            {
                FBLoginDialog* login = [[FBLoginDialog alloc] initWithSession:session];
                [login show];
                [login release];
            }

            break;

            case 1:
                    [session logout];


                break;

    }

So when put that code on the viewDidUnload method everything works fine but my facebook API Key and secret doesn't work !!! why ? How could solve my prablem ? :| Thank you .

+1  A: 

I don't think you understand what you are doing. The viewDidLoad method is called before your view controller's view is loaded and put on the screen. By putting the above code in there you will aways automatically do a facebook login.

If you want the facebook login to happen when the user clicks a button in your action sheet then you should run the above code from the action sheet's delegate method.

Also, in the above code you show the facebook login screen both when the user was already logged in and when there is no session. That makes no sense at all.

St3fan
thank you . it works great ! but i don't know why '[session logOut];'doesn't work !! i edit my codes at the question , look
Momeks