tags:

views:

1567

answers:

2

hi . i am using FBConnect for sharing something on my app . so i want implement FBConnect API with 2 buttons "Login / share on facebook" Via UIACtionSheet .

now , have some questions :

assuming i have 2 buttons on the UIActionSheet with title of "Share on Facebook" "Login"

i want when user have logged in facebook my Login button title change to Log Out i know i should use this function :

- (void)session:(FBSession*)session didLogin:(FBUID)uid {
//a code that change my login button title  to LogOut
}

2- i have logged in facebook . when iam going to go out from my app and again open app i shoud login again ! how could i Prevent this do?

3- finally i want share some text from UIWebView to facebook . my webview outlet names "myWeb" . how could connect FBConnect with UIWebView to share it ?

should is use

-(void)publishFeed:(id)target 

???? thank you .

+5  A: 
#pragma mark FBDialog delegate methods
- (void)dialogDidSucceed:(FBDialog *)dialog {
    if ([dialog isMemberOfClass:[FBLoginDialog class]]) {
        NSLog(@"[FBLoginDialog::dialogDidSucceed] just did succeed");
    } else if ([dialog isMemberOfClass:[FBPermissionDialog class]]) {
        NSLog(@"[FBPermissionDialog::dialogDidSucceed] update user status");
        [self facebookUpdateUserStatus];
    }
}

- (void)dialogDidCancel:(FBDialog *)dialog {    
}

- (void)dialog:(FBDialog *)dialog didFailWithError:(NSError *)error {
    NSLog(@"dialog:%@ didFailWithError:%@", dialog, error); 
}

#pragma mark FBSession delegate methods
- (void)session:(FBSession *)session didLogin:(FBUID)uid {
    NSLog(@"User with id %lld logged in.", uid);
    [self facebookCheckForPermission];
}

- (void)request:(FBRequest*)request didReceiveResponse:(NSURLResponse*)response {
    NSLog(@"did r response");
}

- (void)request:(FBRequest*)request didLoad:(id)result {
    if ([@"facebook.Users.hasAppPermission" isEqualToString: request.method]) {
        if ([@"1" isEqualToString: result]) {
            // post comment
            NSLog(@"[Users.hasAppPermission::dialogDidSucceed] succeed, update status");
            [self facebookUpdateUserStatus];
        } else {
            // show dialog
            NSLog(@"[Users.hasAppPermission::dialogDidSucceed] fail, show dialog");         
            FBPermissionDialog* dialog = [[[FBPermissionDialog alloc] init] autorelease]; 
            dialog.delegate = self; 
            dialog.permission = @"status_update"; 
            [dialog show];      
        }
    } else if ([@"facebook.Users.setStatus" isEqualToString: request.method]) {
        if ([@"1" isEqualToString: result]) {
            NSLog(@"facebook update did succeed");
            UIAlertView *alert = [[UIAlertView alloc] initWithTitle: @"Facebook"
                                                            message: @"L'article a bien été publié sur votre profil"
                                                           delegate: nil
                                                  cancelButtonTitle: @"OK"
                                                  otherButtonTitles: nil]; 
            [alert show];
            [alert release];            
        } else {
            NSLog(@"facebook update did fail");
            UIAlertView *alert = [[UIAlertView alloc] initWithTitle: @"Facebook"
                                                        // Slava, change text here
                                                            message: @"Update did fail"
                                                           delegate: nil
                                                  cancelButtonTitle: @"OK"
                                                  otherButtonTitles: nil]; 
            [alert show];
            [alert release];            
        }
    }
}

- (void)request:(FBRequest*)request didFailWithError:(NSError*)error {
    NSLog(@"did fail: %@", [error localizedDescription]);
}

#pragma mark FBSession helper functions
- (FBSession *)fbSessionWithDelegate:(id)theDelegate {
    if (nil != [FBSession session]) {
        return [[FBSession session] retain]; // fuckup this leak =)
    }

    FBSession *session = [FBSession sessionForApplication: kFBAPIKeyEncoded 
                                                   secret: kFBAPISecretEncoded 
                                                 delegate: theDelegate];
    return session;
}

- (void) facebookCheckForPermission {
    NSLog(@"[facebookCheckForPermission] make a call");
    NSDictionary *d = [NSDictionary dictionaryWithObjectsAndKeys: @"status_update", @"ext_perm", nil];
    //  [[FBRequest requestWithDelegate: self] call: @"facebook.Users.hasAppPermission" params: d];     
    FBSession *fbSession = [self fbSessionWithDelegate: self];
    [[FBRequest requestWithSession: fbSession delegate: self] call: @"facebook.Users.hasAppPermission" params: d];  
}

- (void) facebookUpdateUserStatus {
    NSLog(@"[facebookUpdateUserStatus] updating status");
    NSDictionary *params = [NSDictionary dictionaryWithObjectsAndKeys: [NSString stringWithFormat: @"Je te recommande cet article: %@", postURL],
                            @"status", @"true", @"status_includes_verb", nil]; 
    FBSession *fbSession = [self fbSessionWithDelegate: self];
    updateRequest = [FBRequest requestWithSession: fbSession delegate: self];
    [updateRequest call: @"facebook.Users.setStatus" params: params];
}
sakrist
WOOOW thank you ..mexcuse me can you more explain ? :| i don't know whats going on !
Momeks
if ([@"facebook.Users.hasAppPermission" isEqualToString: request.method]) {should actually be: if ([@"facebook.users.hasAppPermission" isEqualToString: request.method]) {Notice the lowercase characters.
ABeanSits
I'm going to use this solution on my iPhone solution. Thank you!
VansFannel
A: 

use [session resume] which return YES if user have been used yr app otherwise it returns no. by using this mehhod there is no need to do again login.