[英]login with facebook in Xcode and iOS 9 with objective C
我正在尝试创建一个应用程序并使用Facebook
Login
,但它总是显示error
Auth2 ,请帮助我解决这个问题。
2016-05-03 15:14:36.213 loginFB[631:124818] -canOpenURL: failed for URL: "fbauth2:/" - error: "(null)"
2016-05-03 15:14:36.225 loginFB[631:124818] -canOpenURL: failed for URL: "fbauth2:/" - error: "(null)"
2016-05-03 15:14:36.863 loginFB[631:124818] Warning: Attempt to present <FBSDKContainerViewController: 0x12659bf90> on <ViewController: 0x12655a140> whose view is not in the window hierarchy!
尝试将其添加到您的 .plist 文件中:
<key>LSApplicationQueriesSchemes</key>
<array>
<string>fbapi</string>
<string>fbapi20130214</string>
<string>fbapi20130410</string>
<string>fbapi20130702</string>
<string>fbapi20131010</string>
<string>fbapi20131219</string>
<string>fbapi20140410</string>
<string>fbapi20140116</string>
<string>fbapi20150313</string>
<string>fbapi20150629</string>
<string>fb-messenger-api</string>
<string>fbauth2</string>
<string>fbshareextension</string>
</array>
<key>LSRequiresIPhoneOS</key>
<true/>
<key>NSAppTransportSecurity</key>
<dict>
<key>NSExceptionDomains</key>
<dict>
<key>akamaihd.net</key>
<dict>
<key>NSExceptionRequiresForwardSecrecy</key>
<false/>
<key>NSIncludesSubdomains</key>
<true/>
</dict>
<key>facebook.com</key>
<dict>
<key>NSExceptionRequiresForwardSecrecy</key>
<false/>
<key>NSIncludesSubdomains</key>
<true/>
</dict>
<key>fbcdn.net</key>
<dict>
<key>NSExceptionRequiresForwardSecrecy</key>
<false/>
<key>NSIncludesSubdomains</key>
<true/>
</dict>
</dict>
</dict>
昨晚与这个问题作斗争,我得到了正确答案
- (IBAction)loginFBAction:(id)sender{
UIButton *button=sender;
if ([button isSelected]) {
// [fb facebookLogOut];
[button setSelected:NO];
}else{
FBSDKLoginManager *login = [[FBSDKLoginManager alloc] init];
[login
logInWithReadPermissions: @[@"public_profile",@"user_friends",@"email",@"user_birthday"]
fromViewController:self
handler:^(FBSDKLoginManagerLoginResult *result, NSError *error) {
if (error) {
NSLog(@"Process error");
} else if (result.isCancelled) {
NSLog(@"Cancelled");
} else {
NSLog(@"Logged in");
[self checkUser];
}
}]; [button setSelected:YES];
}
}
- (void)checkUser{
NSMutableDictionary* parametersDic = [NSMutableDictionary dictionary];
[parametersDic setValue:@"id, name, email, birthday, picture" forKey:@"fields"];
FBSDKGraphRequest *request = [[FBSDKGraphRequest alloc]
initWithGraphPath:@"me"
parameters:parametersDic
HTTPMethod:@"GET"];
[request startWithCompletionHandler:^(FBSDKGraphRequestConnection *connection,
id result,
NSError *error) {
// Handle the result
NSLog(@"result %@",result);
NSString* nameFB = [result objectForKey:@"name"];
NSString* emailFB = [result objectForKey:@"email"];
}];
}
这是代码,但您需要确保已从 FB 开发人员页面启用您的应用程序,如果您未启用您的应用程序将无法工作,我将在此处展示该图片
在这里,您看到应用名称的绿灯一侧启用此绿色,您需要转到应用审核选项并像这样公开您的应用
现在您将能够享用您的应用程序并获得 fb 登录的访问权限。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.