views:

211

answers:

1

hi everyone . i implement FBConnect for my app via UIActionSheet with 2buttons .

my buttons are "Share On Facebook" and "Log out from facebook" . so i want when user click on share on facebook button FBLoginDialog shows and user log in to facebook with his account and then show FBStreamDial appears and user share something on his wall . and never show FBLoginDialog again . it means just one time . and when user going to log out that method repeat again . How can mange it ?

if i use this method : 2 method appear together !

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

switch (buttonIndex) {
    case 0:

  ///SHOW LOGIN WINDOW
    NSLog(@"asdasda");

        FBLoginDialog* dialog = [[[FBLoginDialog alloc] initWithSession:session] autorelease];
        [dialog show];


///SHOW FBStreamDialog  

        FBStreamDialog* dialog2 = [[[FBStreamDialog alloc] init] autorelease];
        dialog2.delegate = self;

        dialog2.userMessagePrompt = @"Share Ghazals on your wall";
        dialog2.attachment = @"{\"name\":\"Hafez Application for iPhone\","
        "\"href\":\"http://itunes.apple.com/us/app/divan-of-hafez/id340865571?mt=8?tab=iphone\","
        "\"media\":[{\"type\":\"image\","
        "\"src\":\"http://momeks.com/images/fb.png\","
        "\"href\":\"http://developers.facebook.com/connect.php?tab=iphone/\"}],"
        "\"properties\":{\"another link\":{\"text\":\"Hafez App HomePage\",\"href\":\"http://www.momeks.com/hafez\"}}}";
         //replace this with a friends UID
        //dialog2.targetId = @"999999";
        [dialog2 show];


        break;

    case 2:

        [session logout];

        break;


}

}

+1  A: 

The FBDialog's show method is asynchronous, meaning it returns before it completes whatever it is doing (in this case displaying a window).

You need to implement the delegate methods for responding to facebook dialog messages.

In the delegate methods you can outline the flow of your application.

Currently, your code show's the login dialog window, which returns instantly, and then proceeds on to show another dialog. You should only show the second dialog after the user has logged in, which you can determing using the FBSession delegate methods.

Jasarien