2

我正在使用Facebook Connect在我的应用程序上分享一些东西。所以我想通过UIACtionSheet.

现在,我有一些问题:

假设我有 2 个按钮UIActionSheet,标题为“在 Facebook 上分享”“登录”。

我希望,当用户登录 Facebook 时,我的登录按钮标题更改为“注销”。我知道我应该使用这个功能:

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

2- 我已登录 Facebook。当我要退出我的应用程序并再次打开应用程序时,我应该再次登录!我怎么能防止这种情况?

3- 最后我想分享一些从 UIWebView 到 Facebook 的文本。我的 webview 出口命名为“myWeb”。如何将 Facebook Connect 与 UIWebView 连接以共享它?

我应该使用

-(void)publishFeed:(id)target 

?

4

2 回答 2

10
#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];
}
于 2010-02-01T01:31:57.453 回答
0

如果用户使用了您的应用程序,则使用 [session resume] 返回 YES,否则返回 NO。通过使用此方法,无需再次登录。

于 2010-03-15T13:19:03.937 回答