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

Posted

技术标签:

【中文标题】Facebook FBLoginView 自定义 loginView 按钮互联网问题【英文标题】:Facebook FBLoginView Custom loginView button internet issue 【发布时间】:2014-10-15 04:31:14 【问题描述】:

大家好,

    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 方法中,它直接导航到 safari 浏览器进行 Facebook 登录,而不检查网络连接。

【问题讨论】:

在 Facebook 按钮中首先检查网络是否可用,如果互联网不可用显示警报,否则部分调用允许 ui 方法 嗨 Karthik ..感谢您的回复。你能检查 fblogin 方法吗我首先检查网络连接,如果不是我也会显示警报。但是当点击登录按钮时它直接移动到CheckInternetConnectivity 调用后用于 facebook 登录的 Safari 浏览器..这是我的问题吗?希望你能理解 【参考方案1】:

如下更改您的代码。

        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 的按钮时,您不会添加按钮目标,然后调用它的委托。

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

【讨论】:

以上是关于Facebook FBLoginView 自定义 loginView 按钮互联网问题的主要内容,如果未能解决你的问题,请参考以下文章

使用 FBLoginView 自定义注销

在 ios 应用程序中自定义登录到 facebook

自定义移动 Facebook 登录按钮?

如果我们从设置中有 Facebook 会话,FBLoginView 不会发出警报

FBLoginView 拒绝某些用户

Facebook SDK FBLoginView 获取 EXC_BAD_ACCESS