2

嗨,我在 Xib 文件中的 Xcode 4.6 上的应用程序中使用了类似的功能,但单击 facebook 时未登录。而在另一边,当我在故事板的另一个应用程序中登录时,它是登录。如果有人知道,请指导我。

- (id)initWithCoder:(NSCoder *)aDecoder {
    if (self = [super initWithCoder:aDecoder]) {
        _facebook = [[Facebook alloc] initWithAppId:@"129649123867187" andDelegate:self];
    }
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
    self.facebookLikeView.href = [NSURL URLWithString:@"http://sis.uol.edu.pk/sis/MainForms/login.aspx"];
    self.facebookLikeView.layout = @"button_count";
    self.facebookLikeView.showFaces = NO;
    //    self.facebookLikeView.alpha = 1;
    [self.facebookLikeView load];
    facebookLikeView.delegate = self;
}

#pragma mark FBSessionDelegate methods

- (void)fbDidLogin {
    self.facebookLikeView.alpha = 1;
    [self.facebookLikeView load];
}

- (void)fbDidLogout {
    self.facebookLikeView.alpha = 1;
    [self.facebookLikeView load];
}

#pragma mark FacebookLikeViewDelegate methods

- (void)facebookLikeViewRequiresLogin:(FacebookLikeView *)aFacebookLikeView {
    [_facebook authorize:[NSArray array]];
}

- (void)facebookLikeViewDidRender:(FacebookLikeView *)aFacebookLikeView {
    [UIView beginAnimations:@"" context:nil];
    [UIView setAnimationDelay:0.5];
    self.facebookLikeView.alpha = 1;
    [UIView commitAnimations];
}

- (void)facebookLikeViewDidLike:(FacebookLikeView *)aFacebookLikeView {
    UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Liked"
                                                    message:@"You liked  my app. Thanks!"
                                                   delegate:self
                                          cancelButtonTitle:@"OK"
                                          otherButtonTitles:nil] ;
    [alert show];
}

- (void)facebookLikeViewDidUnlike:(FacebookLikeView *)aFacebookLikeView {
    UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Unliked"
                                                    message:@"You unliked my app ."
                                                   delegate:self
                                          cancelButtonTitle:@"OK"
                                          otherButtonTitles:nil] ;
    [alert show];
}
4

1 回答 1

0

您的代码似乎没问题,并且您正在使用FacebookLikeView的代码,当我尝试在我的应用程序中实现相同的代码时,它不会显示登录,因为我忘记将FacebookLikeView与 IB 绑定。我也遇到的另一个问题是,您可能需要_facebook = [[Facebook alloc] initWithAppId:@"129649123867187" andDelegate:self]; 从方法中删除行init并将其放入viewDidLoad如下所示,因为在我的情况下它不会被调用!

if(!_facebook)
{
    _facebook = [[Facebook alloc] initWithAppId:@"129649123867187" andDelegate:self];
}

我相信您不会忘记为FBConnect,FacebookLikeViewDelegateFBSessionDelegate

如果您仍然无法解决问题,那么可能是您Facebook App ID尝试使用源代码中提供的默认应用程序 ID,它应该可以工作!

于 2013-04-25T07:43:29.940 回答