繁体   English   中英

Facebook FBLoginView自定义loginView按钮互联网问题

[英]Facebook FBLoginView Custom loginView button internet issue

嗨,大家好,

    I'm developing app,it having login with face book functionality.For this i have used Facebook iOS SDK 3.18.1 version. I have created custom FBLoginView with custom button.every thing work properly. I had one issue if there is no internet connectivity i need to show alert like 'network requires' but when click on custom login button it directly move to safari browser with out checking network.I have written code for check network connectivity using rechablity.When i click on facebook custom login button it directly move to safari browser for facebook login.

那么有人可以帮助我解决这个问题吗?

这是代码:

-(void)showFacebookLoginUI
{
    self.loginview =
    [[FBLoginView alloc] initWithReadPermissions:[NSArray arrayWithObjects:@"email",@"publish_actions",@"publish_stream",@"public_profile",@"user_about_me",@"user_hometown",@"user_location",nil]];


    if (IS_IPHONE_5) {
        self.loginview.frame = CGRectMake(80, 380, 200, 40);
    }else if(IS_IPAD){
        self.loginview.frame = CGRectMake(310, 636, 180, 100);
    }else{
       self.loginview.frame = CGRectMake(80, 330, 150, 40);
    }
    for (id obj in self.loginview.subviews)
    {
        if ([obj isKindOfClass:[UIButton class]])
        {
            UIButton * loginButton =  obj;

            UIImage *loginImage = [UIImage imageNamed:@"fbIcon.png"];
            [loginButton setBackgroundImage:loginImage forState:UIControlStateNormal];
             [loginButton setBackgroundImage:nil forState:UIControlStateSelected];
            [loginButton setBackgroundImage:nil forState:UIControlStateHighlighted];
            [loginButton addTarget:self action:@selector(fblogin:) forControlEvents:UIControlEventTouchUpInside];
        }
        if ([obj isKindOfClass:[UILabel class]])
        {
             UILabel *label =obj;
            [label removeFromSuperview];          
        }
    }

    [self.view addSubview:self.loginview];
}
-(void)fblogin:(id)sender
{

    if (![self.sharedObject CheckInternetConnectivity]) {

        [self.sharedObject showAlertWithMessage:kNetworkRequiresMessage];
    }
    else{
        self.loginview.delegate = self;
    }
}

在fblogin方法中,它可以直接导航到野生动物园浏览器以登录人脸书,而无需检查网络连接。

如下更改您的代码。

        loginFacebook =
        [[FBLoginView alloc] initWithPublishPermissions:[NSArray arrayWithObjects:@"email",@"user_friends",nil] defaultAudience:FBSessionDefaultAudienceFriends];

        if (IS_IPHONE_5) {
        self.loginview.frame = CGRectMake(80, 380, 200, 40);
        }else if(IS_IPAD){
        self.loginview.frame = CGRectMake(310, 636, 180, 100);
        }else{
        self.loginview.frame = CGRectMake(80, 330, 150, 40);
        }

        for (id obj in loginFacebook.subviews)
        {
            if ([obj isKindOfClass:[UIButton class]])
            {
                UIButton * loginButton =  obj;

                UIImage *loginImage = [UIImage imageNamed:@"facebook_off_signin.png"];
                [loginButton setBackgroundImage:loginImage forState:UIControlStateNormal];
                [loginButton setBackgroundImage:nil forState:UIControlStateSelected];
                [loginButton setBackgroundImage:nil forState:UIControlStateHighlighted];

                //[loginButton sizeToFit];
            }
            if ([obj isKindOfClass:[UILabel class]])
            {
                UILabel * loginLabel =  obj;
                loginLabel.text =@""; //@"Log in to facebook";
                loginLabel.textAlignment = NSTextAlignmentCenter;
                loginLabel.frame =CGRectMake(123,149, 280, 55);// CGRectMake(0, 0, 271, 37);
            }
        }

        loginFacebook.delegate = self;
      [self.view addSubview:loginFacebook];

当您单击Facebook的Button时,您不愿意添加button的Target,然后调用它的委托。

如果尽管按钮图像未显示,则尝试删除[loginButton sizeToFit];注释[loginButton sizeToFit]; 从代码。 它工作。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM