我是初次使用以下代码的iPhone编程我登录Facebook并从Facebook获取数据,如电子邮件ID,用户名后我发送到服务器的电子邮件。但我的问题是,如果已经登录Facebook意味着自动调用它 - (void)loginViewFetchedUserInfo:(FBLoginView *)loginView user:(id)此方法用户发送到服务器的电子邮件ID。我不想这样,如果我点击按钮然后我只想获取Facebook电子邮件ID并发送到服务器。请任何人都可以知道如何解决它。
-(void)viewdidload
{
FBLoginView *fbLoginview =
[[FBLoginView alloc] initWithPublishPermissions:[NSArray arrayWithObjects:@"publish_actions",@"email",nil] defaultAudience:FBSessionDefaultAudienceFriends];
fbLoginview.frame = CGRectMake(30, 10, 200, 30);
for (id obj in fbLoginview.subviews)
{
if ([obj isKindOfClass:[UIButton class]])
{
loginWithFbButton = obj;
loginWithFbButton.frame = CGRectMake(0, 0, 200, 30);
[loginWithFbButton setBackgroundColor:[UIColor colorWithRed:69.0/255.0 green:115.0/255.0 blue:185.0/255.0 alpha:1]];
[loginWithFbButton setBackgroundImage:nil forState:UIControlStateNormal];
[loginWithFbButton setBackgroundImage:nil forState:UIControlStateSelected];
[loginWithFbButton setBackgroundImage:nil forState:UIControlStateHighlighted];
[loginWithFbButton.layer setBorderWidth:1.0f];
[loginWithFbButton.layer setBorderColor:[UIColor colorWithRed:225.0/255.0 green:227.0/255.0 blue:231.0/255.0 alpha:0.6].CGColor];
loginWithFbButton.layer.masksToBounds = YES;
loginWithFbButton.layer.cornerRadius = 5;
[loginWithFbButton setTitle:@" Get info from Facebook" forState:UIControlStateNormal];
[loginWithFbButton.titleLabel setFont:[UIFont fontWithName:@"HelveticaNeue" size:13]];
loginWithFbButton.titleLabel.textAlignment = NSTextAlignmentCenter;
loginWithFbButton.titleLabel.backgroundColor = [UIColor clearColor];
loginWithFbButton.titleLabel.textColor = [UIColor whiteColor];
CAGradientLayer *gradient1 = [CAGradientLayer layer];
gradient1.frame = loginWithFbButton.bounds;
UIColor *startColour1 = [UIColor colorWithRed:46.0/255.0 green:174.0/255.0 blue:225.0/255.0 alpha:1.0f];
UIColor *endColour1 = [UIColor colorWithRed:46.0/255.0 green:119.0/255.0 blue:225.0/255.0 alpha:1.0f];
gradient1.colors = [NSArray arrayWithObjects:(id)[startColour1 CGColor], (id)[endColour1 CGColor], nil];
[loginWithFbButton.layer insertSublayer:gradient1 atIndex:0];
[fbLoginview addSubview:loginWithFbButton];
}
if ([obj isKindOfClass:[UILabel class]])
{
UILabel * loginLabel = obj;
loginLabel.text = nil;
loginLabel.textAlignment = NSTextAlignmentCenter;
loginLabel.frame = CGRectMake(0, 0, 271, 26);
}
}
fbLoginview.delegate = self;
[loginTempview3 addSubview:fbLoginview];
}
取
- (void)loginViewFetchedUserInfo:(FBLoginView *)loginView
user:(id<FBGraphUser>)user {
NSLog(@"Loginvieewww");
// self.profilePic.profileID = user.id;
//self.profilePic.profileID = @"1772134559592493";
// NSLog(@"usr_id::%@",user.id); NSLog(@"%@",user);
NSLog(@"usr_first_name::%@",user.first_name);
NSString *emailiddd=[NSString stringWithFormat:@"%@",[user objectForKey:@"email"]];
NSLog(@"%@",emailiddd);
NSLog(@"usr_last_nmae::%@",user.last_name);
NSLog(@"usr_Username::%@",user.username);
NSLog(@"usr_b_day::%@",user.birthday);
NSString *post = [NSString stringWithFormat:@"email=%@",emailiddd];
NSData *postData = [post dataUsingEncoding:NSASCIIStringEncoding allowLossyConversion:YES];
NSString *postLength = [NSString stringWithFormat:@"%d", [postData length]];
NSLog(@"%@",postLength);
NSMutableURLRequest *request = [[NSMutableURLRequest alloc] init];
[request setURL:[NSURL URLWithString:@"http://54.221.218.162/index.php/api/userClass/registerFBUser/format/xml"]];
[request setHTTPMethod:@"POST"];
[request setValue:postLength forHTTPHeaderField:@"Content-Length"];
[request setValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"Content-Type"];
[request setHTTPBody:postData];
NSLog(@"Aslam here");
NSLog(@"%@",request);
NSURLConnection *theConnection = [[NSURLConnection alloc] initWithRequest:request delegate:self];
if (theConnection) {
webData = [NSMutableData data];
NSLog(@"%@",webData);
}
else
{
}
}
由于 阿斯拉姆