大家好,
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浏览器进行面书登录,而不检查网络连接。
答案 0 :(得分:0)
更改您的代码如下。
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];
的评论
从代码。它工作。