Mine是Objective-C中的iOS应用程序,并集成了Facebook SDK用于登录功能.
我有一个主视图控制器,我显示我的按钮.在按钮上单击下面提到的代码在按钮处理程序上执行.
FBSDKLoginManager *login = [[FBSDKLoginManager alloc] init];
[login
logInWithReadPermissions: @[@"public_profile", @"email"]
fromViewController:self
handler:^(FBSDKLoginManagerLoginResult *result, NSError *error) {
if (error) {
NSLog(@"Process error %@",error.description);
}
else if (result.isCancelled) {
NSLog(@"Cancelled");
}
else {
if ([result.grantedPermissions containsObject:kEmail]) {
[self fetchfbUserInfo];
}
else {
NSLog(@"User Declined permissions");
}
}
}];
Run Code Online (Sandbox Code Playgroud)
当Facebook的登录页面在我们的应用程序中的webview中显示时,如果facebook登录页面保持原样/无人值守一段时间,它会间歇性关闭,并在控制台中出现以下错误.
FBSDKLog:错误:SFSafariViewController的父视图控制器被解雇.如果您从UIAlertController触发登录,则会发生这种情况.相反,请确保您的最顶层视图控制器不会过早被解雇.
做了一些逆向工程并发现必须为错误消息调用FBSDKApplicationDelegate类的这个委托方法.
- (void)viewControllerDidDisappear:(FBSDKContainerViewController *)viewController animated:(BOOL)animated
{
if (_safariViewController) {
[FBSDKLogger singleShotLogEntry:FBSDKLoggingBehaviorDeveloperErrors
logEntry:@"**ERROR**:\n The SFSafariViewController's parent view controller was dismissed.\n"
"This can happen if you …Run Code Online (Sandbox Code Playgroud)