Facebook登录在ios10和xcode 8中不工作



它在xcode 7.3.1和ios 9.3中运行良好,但在更新xcode后它停止工作

这里是我使用的代码

-(IBAction)ClickFacebook:(id)sender
{
FBSDKLoginManager *login = [[FBSDKLoginManager alloc] init];
[login
logInWithReadPermissions: @[@"public_profile",@"email"]
fromViewController:self
handler:^(FBSDKLoginManagerLoginResult *result, NSError *error)
{
if (error)
{
//NSLog(@"Process error");
FBSDKLoginManager *loginManager = [[FBSDKLoginManager alloc] init];
[loginManager logOut];
[FBSDKAccessToken setCurrentAccessToken:nil];
}
else if (result.isCancelled)
{
NSLog(@"Cancelled");

}
else
{
FBSDKGraphRequest *requestFB = [[FBSDKGraphRequest alloc]
initWithGraphPath:@"/me"
parameters:@{ @"fields": @"name,email"}
HTTPMethod:@"GET"];
[requestFB startWithCompletionHandler:^(FBSDKGraphRequestConnection  *connection, id result,NSError  *error)
{
//NSLog(@"%@",result);
NSString *   strName=[result valueForKey:@"name"];
NSString *   strEmail=[result valueForKey:@"email"];
// [[NSUserDefaults standardUserDefaults]setValue:strEmail forKey:@"EMAIL"];
// [[NSUserDefaults standardUserDefaults]setInteger:1 forKey:@"Logged_in"];
// [[NSUserDefaults standardUserDefaults]setValue:strName forKey:@"NAME"];
UIStoryboard *sb = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
SignupJob *viewController = [sb instantiateViewControllerWithIdentifier:@"signupjob"];
viewController.strEmail=strEmail;
viewController.strName =strName;
[self.navigationController pushViewController:viewController animated:YES];
}];
}
}];
}

,但在facebook登录后,它将不会返回到本地应用程序,当我已经调试代码,它落在

else if (result.isCancelled)
{
NSLog(@"Cancelled");

}

循环,我得到了控制台错误,就像这样

flow:finish_connect 2016-11-08 11:55:02.424070 OPT JOBS[2410:49655] []Nw_connection_endpoint_report [16 graph.facebook.com:443 ready .Resolver (satisfied)]上报的事件流:finish_connect 2016-11-0811:55:02.424919选择工作[2410:49 . 661][]__tcp_connection_start_block_invoke 16发送事件TCP_CONNECTION_EVENT_TLS_HANDSHAKE_COMPLETE响应状态就绪and error (null) 2016-11-08 11:55:02.425626 OPT JOBS[2410:49661] []Tcp_connection_event_notify 16事件:TCP_CONNECTION_EVENT_TLS_HANDSHAKE_COMPLETE,原因:nw_connection事件,应交付:true 2016-11-08 11:55:02.426673 OPTJOBS[2410:49661] [] tcp_connection_get_statistics DNS: 18ms/24ms sinceTCP: 100ms/135ms since start, TLS: 2111ms/343ms since start2016-11-08 11:55:02.445829 opt jobs [2410:49655] []Nw_endpoint_flow_protocol_connected [17.1 31.13.78.13:443] in_progresssocket-flow(满意)]输出协议连接2016-11-0811:55:02.44 . 545 opt jobs [2410:49 . 655] []Nw_endpoint_flow_connected_path_change [17.1 31.13.78.13:443] readysocket-flow(满意)]2016-11-08 11:55:02.448063[2410:49 . 655] [] nw_endpoint_flow_connected_path_change [17.1 .[2014-11-08 11:55:02.448526 OPT JOBS[2410:49 . 655] []Nw_endpoint_resolver_receive_report [17] graph.facebook.com:443In_progress resolver (satisfied)]收到了子报告:[17.1 .1][[] nw_connection_endpoint_report . cn] 2016-11-08 11:55:02.448948 OPT JOBS[2410:49655] [] nw_connection_endpoint_report . cn[17.1 31.13.78:443]已报告的事件flow:finish_connect 2016-11-08 11:55:02.449428 OPT JOBS[2410:49655] []Nw_connection_endpoint_report [17 graph.facebook.com:443 ready .Resolver (satisfied)]上报的事件流:finish_connect 2016-11-0811:55:02.449908 opt jobs [2410:49 . 558] []__tcp_connection_start_block_invoke 17发送事件TCP_CONNECTION_EVENT_TLS_HANDSHAKE_COMPLETE以响应状态就绪and error (null) 2016-11-08 11:55:02.544663 OPT JOBS[2410:49 . 558] []Tcp_connection_event_notify 17事件:TCP_CONNECTION_EVENT_TLS_HANDSHAKE_COMPLETE,原因:nw_connection事件,应交付:true 2016-11-08 11:55:02.545103 OPTJOBS[2410:49 . 558] [] tcp_connection_get_statistics DNS: 11ms/18ms sinceTCP: 112ms/146ms since start, TLS: 220ms/362ms since start2016-11-08 11:55:02.747101 opt jobs [2410:49 . 551] []nw_socket_handle_socket_event事件掩码:0x4 2016-11-0811:55:02.747501 OPT JOBS[2410:49 . 662] [] tcp_connection_cancel2016-11-08 11:55:02.747984 opt jobs [2410:49 . 551] []nw_socket_handle_socket_event Socket收到WRITE_CLOSE事件2016-11-08 11:55:02.748361 opt jobs [2410:49 . 551] []Nw_endpoint_handler_cancel [16 graph.facebook.com:4432016-11-08 11:55:02.748705 OPT JOBS[2410:49 . 551] []Nw_endpoint_handler_cancel [16.1 31.13.78.13:443] ready socket-flow[2016-11-08 11:55:02.749132 OPT JOBS[2410:49 . 551] []__nw_socket_service_writes_block_invoke sendmsg(fd 9,31 bytes): socket has been closed 2016-11-08 11:55:02.749475 OPT JOBS[2410:49551][] nw_endpoint_flow_protocol_error [16.1 31.13.78:443] cancelled .取消Socket -flow (null)] Socket协议发送错误:[32]管道破裂2016-11-08 11:55:02.749751 opt jobs [2410:49 . 551] []Nw_endpoint_flow_protocol_disconnected[16.1 31.13.78.13:443]取消socket-flow (null)]输出协议断开2016-11-08[11:55:02.750124 OPT JOBS] [2410:49 . 551] [] nw_resolver_cancel_on_queue .0x7a086580 2016-11-08 11:55:02.750463 OPT JOBS[2410:49 . 551] []-[NWConcrete_tcp_connection dealloc] 16 2016-11-08 11:55:02.867926 OPT JOBS[2410:49661] [] nw_socket_handle_socket_event事件掩码:0x42016-11-08 11:55:02.868244 opt jobs [2410:49 . 558] []tcp_connection_cancel 17 2016-11-08 11:55:02.868817 OPTJOBS[2410:49 . 661] [] nw_socket_handle_socket_event收到的SocketWRITE_CLOSE事件2016-11-08 11:55:02.869206 OPT JOBS[2410:49661] []Nw_endpoint_handler_cancel [17 graph.facebook.com:443[2014-11-08 11:55:02.869432 OPT JOBS[2410:49 . 661] []Nw_endpoint_handler_cancel [17.1 31.13.78:443] ready socket-flow[2016-11-08 11:55:02.869919 OPT JOBS[2410:49 . 661] []__nw_socket_service_writes_block_invoke sendmsg(fd 10,31 bytes): socket has been closed 2016-11-08 11:55:02.870149 OPT JOBS[2410:49661][] nw_endpoint_flow_protocol_error [17.1 31.13.78.13:443] cancelled .取消Socket -flow (null)] Socket协议发送错误:[32]管道破裂2016-11-08 11:55:02.870549 opt jobs [2410:49 . 661] []Nw_endpoint_flow_protocol_disconnected[17.1 31.13.78.13:443]取消socket-flow (null)]输出协议断开2016-11-08[11:55:02.870896 OPT JOBS] [2410:49 . 661] [] nw_resolver_cancel_on_queue .0x7a08e1b0 2016-11-08 11:55:02.871251 OPT JOBS[2410:49 . 661] []-[NWConcrete_tcp_connection dealloc] 17

所以谁能帮我找到ios10和xcode 8的解决方案

在我的应用程序中也不能在iOS 10中使用Facebook和Google Login。所以我做了ON钥匙链共享,它工作了。

检查这个:https://stackoverflow.com/a/39568942/3901620

**In Capabilities tab Keychain Sharing should be enable.**
**Also Make sure you have added this to your plist**
<key>CFBundleURLTypes</key>
<array>
<dict>
<key>CFBundleURLSchemes</key>
<array>
<string>fb648725325301980</string>
</array>
</dict>
</array>
<key>FacebookAppID</key>
<string>648725325301980</string>
<key>FacebookDisplayName</key>
<string>MeetBox</string>
<key>LSApplicationQueriesSchemes</key>
<array>
<string>fbapi</string>
<string>fb-messenger-api</string>
<string>fbauth2</string>
<string>fbshareextension</string>
</array>

- **If it is still not working then replace your code with this**
**Swift**
-(IBAction)ClickFacebook:(id)sender
{
let loginManager = FBSDKLoginManager()
loginManager.logOut()
loginManager.logIn(withReadPermissions: ["public_profile", "email", "user_friends", "user_likes", "user_relationship_details", "user_relationships"], from: self, handler: {(result , error) -> Void in
print("Value of Result is (result)")
print("Value of Error is (error)")
if (error != nil) {
let cont = UIAlertController(title: "Error", message: "Something Went Wrong", preferredStyle: .alert)
let okAction = UIAlertAction(title: "Ok", style: .default, handler: {(action: UIAlertAction) -> Void in
})
cont.addAction(okAction)
self.present(cont, animated: true, completion: { _ in })
}
else if (result?.isCancelled)!
{
}
else
{
if (FBSDKAccessToken.current() != nil)
{
let homeVC = self.storyboard?.instantiateViewController(withIdentifier: "HomeViewController")
self.navigationController?.pushViewController(homeVC!, animated: true)
FBSDKGraphRequest.init(graphPath: "me", parameters: nil).start(completionHandler: {(connection, result, error) -> Void in
print("Value of Error is", error)
print("Value of Result is", result)
if error == nil
{
FBSDKGraphRequest.init(graphPath: "me", parameters: ["fields":"picture.width(500).height(500),first_name,email,last_name,location,gender,likes,interested_in,friends"]).start(completionHandler: {(connection, result, error) -> Void in
print("ResultArray: ",result)
})
}
})
}
}
})
}
**Objective C**
-(IBAction)ClickFacebook:(id)sender
{
FBSDKLoginManager *loginManager = [[FBSDKLoginManager alloc]init];
[loginManager logOut];
[loginManager logInWithReadPermissions:@[@"public_profile",@"email",@"user_friends",@"user_likes",@"user_relationship_details"] fromViewController:self handler:^(FBSDKLoginManagerLoginResult result, NSError error) {
NSLog(@"Value of Result is %@",result);
NSLog(@"Value of Error is %@",error);
if (error)
{
UIAlertController *cont = [UIAlertController alertControllerWithTitle:@"Error" message:@"Something Went Wrong" preferredStyle:UIAlertControllerStyleAlert];
UIAlertAction okAction = [UIAlertAction actionWithTitle:@"Ok" style:UIAlertActionStyleDefault handler:^(UIAlertAction    _Nonnull action) {
}];
[cont addAction:okAction];
[self presentViewController:cont animated:true completion:nil];
}
else if (result.isCancelled)
{
//Permission Canceled
}
else
{
//User Accept Permission
NSLog(@"Granded Permissions are %@",result.grantedPermissions);
if ([FBSDKAccessToken currentAccessToken])
{
[[[FBSDKGraphRequest alloc]initWithGraphPath:@"me" parameters:nil]startWithCompletionHandler:^(FBSDKGraphRequestConnection connection, id result, NSError error) {
NSLog(@"Value of Error is %@",error);
NSLog(@"Value of Result is %@",result);

if (error == nil)
{
//
[[[FBSDKGraphRequest alloc]initWithGraphPath:@"me" parameters:@{@"fields": @"picture.width(500).height(500),first_name,email,last_name,location,gender,likes,interested_in"}]startWithCompletionHandler:^(FBSDKGraphRequestConnection connection, id result, NSError error) {
NSLog(@"Value of Result is %@",result);
NSLog(@"Value of Error is %@",error);
if ( error != nil)
{
// NSMutableDictionary *tempDict = [[NSMutableDictionary alloc]init];
// myPagesArray = [[result valueForKey:@"likes"]valueForKey:@"data"];
}
}];
}
else
{
//Something Went Wrong...
}
}];
}
}
}];
}

- (void)applicationDidBecomeActive:(UIApplication *)application {
[FBSDKAppEvents activateApp];
// Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
}

最新更新