2016-11-08 91 views
0

它在Xcode 7.3.1和iOS 9.3的工作很好,但更新後的xcode它採空工作Facebook的登錄不ios10和Xcode中工作8

這裏的代碼,我已經使用

-(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"); 


     } 

環和我有共同nsole錯誤就這樣

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.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.544663 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): 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.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 OPT 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

所以任何人都可以幫我找出ios10和Xcode的8

回答

0
   **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. 
    } 
+0

這個配置我已經做的這個原因BCS這是在ios9 –

+0

工作試試這個代碼,我已經削減這從iOS的10認爲它應該在iOS的10個工作 – User511

+0

你可以給我這個代碼在客觀上c –