[英]Make Button touchUpInside FBLoginView
I have a FBLoginView with property loginButton, and I want to make a button that is not in the same view fire this FBLoginView built in button feature. 我有一个具有属性loginButton的FBLoginView,并且我想创建一个不在同一视图中的按钮触发此FBLoginView内置按钮功能。 Does anyone have any suggestions?
有没有人有什么建议? thanks
谢谢
Download latest facebook SDK install and import coreKit & LoginKit frameworks in target. 下载最新的facebook SDK安装程序并在目标中导入coreKit和LoginKit框架。
Create one sample button and give action. 创建一个示例按钮并执行操作。
Ex: 例如:
[fbLogin addTarget:self action:@selector(facebookLogin:) forControlEvents:UIControlEventTouchUpInside]; [fbLogin addTarget:self操作:@selector(facebookLogin :) forControlEvents:UIControlEventTouchUpInside];
#import<FBSDKCoreKit/FBSDKCoreKit.h>
#import<FBSDKLoginKit/FBSDKLoginKit.h>
-(void)facebookLogin:(id)sender
{
FBSDKLoginManager *login = [[FBSDKLoginManager alloc] init];
[login logInWithReadPermissions:@[@"email"] handler:^(FBSDKLoginManagerLoginResult *result, NSError *error) {
if (error) {
// Process error
NSLog(@"error %@",error);
} else if (result.isCancelled) {
// Handle cancellations
NSLog(@"Cancelled");
} else {
if ([result.grantedPermissions containsObject:@"email"]) {
// Do work
[self fetchUserInfo];
}
}
}];
}
-(void)fetchUserInfo
{
if ([FBSDKAccessToken currentAccessToken]) {
NSLog(@"Token is available");
[[[FBSDKGraphRequest alloc] initWithGraphPath:@"me" parameters:nil]
startWithCompletionHandler:^(FBSDKGraphRequestConnection *connection, id result, NSError *error) {
if (!error)
{
NSLog(@"Fetched User Information:%@", result);
}
else
{
NSLog(@"Error %@",error);
}
}];
} else {
NSLog(@"User is not Logged in");
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.