[英]Facebook Login is not working in ios10 and xcode 8
it was working well in xcode 7.3.1 and ios 9.3 but after updating xcode it stoped working 它在xcode 7.3.1和ios 9.3中运行良好,但是在更新xcode后它停止工作
here is code which i have used 这是我用过的代码
-(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];
}];
}
}];
}
but after login in facebook it will not return back to native app and when i have debugged code it falls in 但是在Facebook上登录后,它不会返回到本机应用程序,当我调试代码时,它会落入
else if (result.isCancelled)
{
NSLog(@"Cancelled");
}
loop and i got the console error just like this 循环,我得到了控制台错误,就像这样
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)] reported event flow:finish_connect 2016-11-08 11:55:02.424919 OPT JOBS[2410:49661] [] __tcp_connection_start_block_invoke 16 sending event TCP_CONNECTION_EVENT_TLS_HANDSHAKE_COMPLETE in response to state ready and error (null) 2016-11-08 11:55:02.425626 OPT JOBS[2410:49661] [] tcp_connection_event_notify 16 event: TCP_CONNECTION_EVENT_TLS_HANDSHAKE_COMPLETE, reason: nw_connection event, should deliver: true 2016-11-08 11:55:02.426673 OPT JOBS[2410:49661] [] tcp_connection_get_statistics DNS: 18ms/24ms since start, TCP: 100ms/135ms since start, TLS: 211ms/343ms since start 2016-11-08 11:55:02.445829 OPT JOBS[2410:49655] [] nw_endpoint_flow_protocol_connected [17.1 31.13.78.13:443 in_progress socket-flow (satisfied)] Output protocol connected 2016-11-08 11:55:02.447545 OPT JOBS[2410:49655] [] nw_endpoint_flow_connected_path_change [17
flow:finish_connect 2016-11-08 11:55:02.424070 OPT JOBS [2410:49655] [] nw_connection_endpoint_report [16 graph.facebook.com:443 ready解析器(满意)]报告了事件流:finish_connect 2016-11-08 11: 55:02.424919 OPT JOBS [2410:49661] [] __tcp_connection_start_block_invoke 16发送事件TCP_CONNECTION_EVENT_TLS_HANDSHAKE_COMPLETE以响应状态就绪和错误(空)2016-11-08 11:55:02.425626 OPT JOBS [2410:49661] [] tcp_connection_event_not TCP_CONNECTION_EVENT_TLS_HANDSHAKE_COMPLETE,原因:nw_connection事件,应交付:true 2016-11-08 11:55:02.426673 OPT JOBS [2410:49661] [] tcp_connection_get_statistics DNS:自启动以来18ms / 24ms,TCP:自启动以来100ms / 135ms,TLS:211ms自开始以来的/ 343ms 2016-11-08 11:55:02.445829 OPT JOBS [2410:49655] [] nw_endpoint_flow_protocol_connected [17.1 31.13.78.13:443 in_progress套接字流(已满足)]输出协议已连接2016-11-08 11:55 :02.447545 OPT JOBS [2410:49655] [] nw_endpoint_flow_connected_path_change [17 .1 31.13.78.13:443 ready socket-flow (satisfied)] 2016-11-08 11:55:02.448063 OPT JOBS[2410:49655] [] nw_endpoint_flow_connected_path_change [17.1 31.13.78.13:443 ready socket-flow (satisfied)] Connected path is satisfied 2016-11-08 11:55:02.448526 OPT JOBS[2410:49655] [] nw_endpoint_resolver_receive_report [17 graph.facebook.com:443 in_progress resolver (satisfied)] received child report:[17.1 31.13.78.13:443 ready socket-flow (satisfied)] 2016-11-08 11:55:02.448948 OPT JOBS[2410:49655] [] nw_connection_endpoint_report [17.1 31.13.78.13:443 ready socket-flow (satisfied)] reported event 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)] reported event flow:finish_connect 2016-11-08 11:55:02.449908 OPT JOBS[2410:49558] [] __tcp_connection_start_block_invoke 17 sending event TCP_CONNECTION_EVENT_TLS_HANDSHAKE_COMPLETE in response to state ready and error (null) 2016-11-08 11:55:02.5446
.1 31.13.78.13:443准备好的套接字流(满意)] 2016-11-08 11:55:02.448063 OPT JOBS [2410:49655] [] nw_endpoint_flow_connected_path_change [17.1 31.13.78.13:443准备好的套接字流(满意)]已满足连接路径2016-11-08 11:55:02.448526 OPT JOBS [2410:49655] [] nw_endpoint_resolver_receive_report [17 graph.facebook.com:443 in_progress解析器(满意)]收到子报告:[17.1 31.13.78.13:443准备好的套接字流(已满足)] 2016-11-08 11:55:02.448948 OPT JOBS [2410:49655] [] nw_connection_endpoint_report [17.1 31.13.78.13:443准备好的套接字流(已满足)]报告的事件流:finish_connect 2016- 11-08 11:55:02.449428 OPT JOBS [2410:49655] [] nw_connection_endpoint_report [17 graph.facebook.com:443就绪的解析器(满意)]报告的事件流:finish_connect 2016-11-08 11:55:02.449908 OPT JOBS [2410:49558] [] __tcp_connection_start_block_invoke 17发送事件TCP_CONNECTION_EVENT_TLS_HANDSHAKE_COMPLETE以响应状态就绪和错误(空)2016-11-08 11:55:02.5446 63 OPT JOBS[2410:49558] [] tcp_connection_event_notify 17 event: TCP_CONNECTION_EVENT_TLS_HANDSHAKE_COMPLETE, reason: nw_connection event, should deliver: true 2016-11-08 11:55:02.545103 OPT JOBS[2410:49558] [] tcp_connection_get_statistics DNS: 11ms/18ms since start, TCP: 112ms/146ms since start, TLS: 220ms/362ms since start 2016-11-08 11:55:02.747101 OPT JOBS[2410:49551] [] nw_socket_handle_socket_event Event mask: 0x4 2016-11-08 11:55:02.747501 OPT JOBS[2410:49662] [] tcp_connection_cancel 16 2016-11-08 11:55:02.747984 OPT JOBS[2410:49551] [] nw_socket_handle_socket_event Socket received WRITE_CLOSE event 2016-11-08 11:55:02.748361 OPT JOBS[2410:49551] [] nw_endpoint_handler_cancel [16 graph.facebook.com:443 ready resolver (satisfied)] 2016-11-08 11:55:02.748705 OPT JOBS[2410:49551] [] nw_endpoint_handler_cancel [16.1 31.13.78.13:443 ready socket-flow (satisfied)] 2016-11-08 11:55:02.749132 OPT JOBS[2410:49551] [] __nw_socket_service_writes_block_invoke sendmsg(fd 9, 31 bytes): sock
63 OPT JOBS [2410:49558] [] tcp_connection_event_notify 17事件:TCP_CONNECTION_EVENT_TLS_HANDSHAKE_COMPLETE,原因:nw_connection事件,应传递:true 2016-11-08 11:55:02.545103 OPT JOBS [2410:49558] [] tcp_connection_get_statistics DNS:11ms / 18ms自启动以来,TCP:自启动以来112ms / 146ms,TLS:自启动以来220ms / 362ms 2016-11-08 11:55:02.747101 OPT JOBS [2410:49551] [] nw_socket_handle_socket_event事件掩码:0x4 2016-11-08 11:55 :02.747501 OPT JOBS [2410:49662] [] tcp_connection_cancel 16 2016-11-08 11:55:02.747984 OPT JOBS [2410:49551] [] nw_socket_handle_socket_event套接字已收到WRITE_CLOSE事件2016-11-08 11:55:02.748361 OPT JOBS [ 2410:49551] [] nw_endpoint_handler_cancel [16 graph.facebook.com:443就绪的解析器(满意)] 2016-11-08 11:55:02.748705 OPT JOBS [2410:49551] [] nw_endpoint_handler_cancel [16.1 31.13.78.13:443就绪套接字流(满意)] 2016-11-08 11:55:02.749132 OPT JOBS [2410:49551] [] __nw_socket_service_writes_block_invoke sendmsg(fd 9,31个字节):袜子 et has been closed 2016-11-08 11:55:02.749475 OPT JOBS[2410:49551] [] nw_endpoint_flow_protocol_error [16.1 31.13.78.13:443 cancelled socket-flow (null)] Socket protocol sent error: [32] Broken pipe 2016-11-08 11:55:02.749751 OPT JOBS[2410:49551] [] nw_endpoint_flow_protocol_disconnected [16.1 31.13.78.13:443 cancelled socket-flow (null)] Output protocol disconnected 2016-11-08 11:55:02.750124 OPT JOBS[2410:49551] [] nw_resolver_cancel_on_queue 0x7a086580 2016-11-08 11:55:02.750463 OPT JOBS[2410:49551] [] -[NWConcrete_tcp_connection dealloc] 16 2016-11-08 11:55:02.867926 OPT JOBS[2410:49661] [] nw_socket_handle_socket_event Event mask: 0x4 2016-11-08 11:55:02.868244 OPT JOBS[2410:49558] [] tcp_connection_cancel 17 2016-11-08 11:55:02.868817 OPT JOBS[2410:49661] [] nw_socket_handle_socket_event Socket received WRITE_CLOSE event 2016-11-08 11:55:02.869206 OPT JOBS[2410:49661] [] nw_endpoint_handler_cancel [17 graph.facebook.com:443 ready resolver (satisfied)] 2016-11-08 11:55:02.869432 O
et已关闭2016-11-08 11:55:02.749475 OPT JOBS [2410:49551] [] nw_endpoint_flow_protocol_error [16.1 31.13.78.13:443取消了套接字流(空)]套接字协议发送错误:[32]管道损坏2016 -11-08 11:55:02.749751 OPT JOBS [2410:49551] [] nw_endpoint_flow_protocol_disconnected [16.1 31.13.78.13:443取消套接字流(空)]输出协议已断开连接2016-11-08 11:55:02.750124 OPT JOBS [ 2410:49551] [] nw_resolver_cancel_on_queue 0x7a086580 2016-11-08 11:55:02.750463 OPT JOBS [2410:49551] []-[NWConcrete_tcp_connection dealloc] 16 2016-11-08 11:55:02.867926 OPT JOBS [2410:49661] [] nw_socket_handle_socket_event事件掩码:0x4 2016-11-08 11:55:02.868244 OPT JOBS [2410:49558] [] tcp_connection_cancel 17 2016-11-08 11:55:02.868817 OPT JOBS [2410:49661] [] nw_socket_handle_socket_event已收到套接字WRITE_CLOSE事件2016-11-08 11:55:02.869206 OPT JOBS [2410:49661] [] nw_endpoint_handler_cancel [17 graph.facebook.com:443就绪的解析器(满意)] 2016-11-08 11:55:02.869432 O PT JOBS[2410:49661] [] nw_endpoint_handler_cancel [17.1 31.13.78.13:443 ready socket-flow (satisfied)] 2016-11-08 11:55:02.869919 OPT JOBS[2410:49661] [] __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 protocol sent error: [32] Broken pipe 2016-11-08 11:55:02.870549 OPT JOBS[2410:49661] [] nw_endpoint_flow_protocol_disconnected [17.1 31.13.78.13:443 cancelled socket-flow (null)] Output protocol disconnected 2016-11-08 11:55:02.870896 OPT JOBS[2410:49661] [] nw_resolver_cancel_on_queue 0x7a08e1b0 2016-11-08 11:55:02.871251 OPT JOBS[2410:49661] [] -[NWConcrete_tcp_connection dealloc] 17
PT JOBS [2410:49661] [] nw_endpoint_handler_cancel [17.1 31.13.78.13:443就绪套接字流(已满足)] 2016-11-08 11:55:02.869919 OPT JOBS [2410:49661] [] __nw_socket_service_writes_block_invoke sendmsg(fd 10, 31字节):套接字已关闭2016-11-08 11:55:02.870149 OPT JOBS [2410:49661] [] nw_endpoint_flow_protocol_error [17.1 31.13.78.13:443取消了套接字流(空)]套接字协议发送了错误:[32 ]断管2016-11-08 11:55:02.870549 OPT JOBS [2410:49661] [] nw_endpoint_flow_protocol_disconnected [17.1 31.13.78.13:443取消了套接字流(空)]输出协议已断开连接2016-11-08 11:55: 02.870896 OPT JOBS [2410:49661] [] nw_resolver_cancel_on_queue 0x7a08e1b0 2016-11-08 11:55:02.871251 OPT JOBS [2410:49661] []-[NWConcrete_tcp_connection dealloc] 17
so can anyone help me to find out the Solution for ios10 and xcode 8 所以谁能帮助我找出适用于ios10和xcode 8的解决方案
**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.
}
In My app also Facebook and Google Login not working in iOS 10. So I have made ON keychain sharing and it works. 在“我的应用程序”中,Facebook和Google登录名也无法在iOS 10中使用。因此,我进行了钥匙串共享,并且可以使用。
check this : https://stackoverflow.com/a/39568942/3901620 检查一下: https : //stackoverflow.com/a/39568942/3901620
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.