0

我已经在我的应用程序中成功连接了 FBConnect,现在我想以这样一种方式连接,一旦用户从登录名成功登录,我ViewController应该打开。但是在哪里使用代码进入我的应用程序..

AppDelegate *appdelegte =(AppDelegate*)[[UIApplication sharedApplication]delegate];

[[[appdelegte navigationController] view]removeFromSuperview];

[[appdelegte window]addSubview:[[appdelegte tabBarController]view]];

[[appdelegte tabBarController]setSelectedIndex:0];

这将是我要输入的代码:- 但是在 Fbconnect 代码中的何处使用它

- (void)session:(FBSession*)session didLogin:(FBUID)uid {
    NSString* fql = [NSString stringWithFormat:
                     @"select uid,name from user where uid == %lld", self.usersession.uid];
    NSDictionary* params = [NSDictionary dictionaryWithObject:fql forKey:@"query"];
    [[FBRequest requestWithDelegate:self] call:@"facebook.fql.query" params:params];
    self.post=YES;

    self.usersession =session;
    NSLog(@"User with id %lld logged in.", uid);


    [self getFacebookName];
}

- (void)getFacebookName {
    NSString* fql = [NSString stringWithFormat:
                 @"select uid,name from user where uid == %lld", self.usersession.uid];
    NSDictionary* params = [NSDictionary dictionaryWithObject:fql forKey:@"query"];
    [[FBRequest requestWithDelegate:self] call:@"facebook.fql.query" params:params];
    self.post=YES;
}

- (void)request:(FBRequest*)request didLoad:(id)result {
    if ([request.method isEqualToString:@"facebook.fql.query"]) {
        NSArray* users = result;
        NSDictionary* user = [users objectAtIndex:0];
        NSString* name = [user objectForKey:@"name"];
        self.username = name;   
        if (self.post) {
            [self postToWall];
            self.post = NO;
        }
    }
}

请让我知道如何进入应用程序..从 fbconnect 成功登录后

4

1 回答 1

0

你应该把代码放到你的主应用程序中-session:didLogin:。登录成功时调用此方法。如果您的视图控制器称为 ViewController,则转换代码如下:

ViewController *vc = [[ViewController alloc] init];
self.window.rootViewController = vc;

如果您还没有导入 ViewController.h,请将以下内容添加到文件顶部:

#import "ViewController.h"
于 2012-12-30T20:25:30.660 回答