2016-11-18 123 views
0

我使用的是xcode8,并且我已启用所有但不工作的内容Facebook不会重定向到Safari浏览器应用程序

1)在应用程序中启用了钥匙链。

2)InAppdelegate.m

didFinishLaunching method 
[[FBSDKApplicationDelegate sharedInstance] application:application didFinishLaunchingWithOptions:launchOptions]; 

-(BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation { 

    return [[FBSDKApplicationDelegate sharedInstance] application:application openURL:url sourceApplication:sourceApplication annotation:annotation]; 

} 

我有 “使用FB登录” 按钮的动作在我的视图 - 控制文件的自定义按钮

-(void)signInWithFaceBookAction { 

    FBSDKLoginManager *loginManager = [[FBSDKLoginManager alloc] init]; 
    [loginManager logInWithReadPermissions:@[@"public_profile", @"email", @"user_friends"] 
         fromViewController:self 
            handler:^(FBSDKLoginManagerLoginResult *result, NSError *error) { 
             //TODO: process error or result 
             NSLog(@"Results :%@ --- Error:%@",result,error.description); 
             NSLog(@"Token:%@ -- isCancelled:%d -- Granted Permissions:%@ -- Declined permissions:%@",result.token,result.isCancelled,result.grantedPermissions,result.declinedPermissions); 

              NSMutableDictionary* parameters = [NSMutableDictionary dictionary]; 
              [parameters setValue:@"id,name,email" forKey:@"fields"]; 

              [[[FBSDKGraphRequest alloc] initWithGraphPath:@"me" parameters:parameters] 
              startWithCompletionHandler:^(FBSDKGraphRequestConnection *connection, id result, NSError *error) { 
               NSLog(@"Result :%@",result); 
               NSLog(@"Error: %@",error.localizedDescription); 
              }]; 

            }]; 


} 
+0

参考我的答案中的链接https://stackoverflow.com/questions/37874383/facebook-login-page-showing-blank-page-in-ios-9 – MuraliMohan

+0

在本建议的https:// stackoverflow.com/questions/37874383/facebook-login-page-showing-blank-page-in-ios-9我似乎无法在appdelegate中添加两个方法,出现重复声明错误 –

+0

Boss都是不同的方法。一个比ios 9少,另外一个来自ios 10.两个都支持。尝试复制过去并检查您是否收到错误 – MuraliMohan

回答

0

的Facebook SDK集成here步步实现。在iOS 9和10上都可以正常工作希望这对你有所帮助。

0

//appdelegate.m

#import <FBSDKCoreKit/FBSDKCoreKit.h> 
#import <FBSDKLoginKit/FBSDKLoginKit.h> 

+ (void)initialize 
{ 
// Nib files require the type to have been loaded before they can do the wireup successfully. 
// http://stackoverflow.com/questions/1725881/unknown-class-myclass-in-interface-builder-file-error-at-runtime 
[FBSDKLoginButton class]; 
[FBSDKProfilePictureView class]; 
[FBSDKSendButton class]; 
[FBSDKShareButton class]; 
} 


- (BOOL)application:(UIApplication *)application 
     openURL:(NSURL *)url 
sourceApplication:(NSString *)sourceApplication 
    annotation:(id)annotation { 
return [[FBSDKApplicationDelegate sharedInstance] application:application 
                 openURL:url 
              sourceApplication:sourceApplication 
                annotation:annotation]; 
} 


- (void)applicationDidBecomeActive:(UIApplication *)application { 
[FBSDKAppEvents activateApp]; 
} 

//你Controller.m或者

#import <FBSDKCoreKit/FBSDKCoreKit.h> 
#import <FBSDKLoginKit/FBSDKLoginKit.h> 


NSString *getFbid; 
NSString *getFbFirstName,*getFBlastName, *getFbemail,*getfbBirthday,*getfbGender,*getFBpHone,*getFBlocation,*getFBcountry; 



- (void) loginButton: (FBSDKLoginButton *)loginButton 
didCompleteWithResult: (FBSDKLoginManagerLoginResult *)result 
      error: (NSError *)error{ 

NSLog(@"facebook login button test"); 


} 
- (void) loginButtonDidLogOut:(FBSDKLoginButton *)loginButton{ 
    NSLog(@"facebook logout button test"); 
} 


-(void)loginButtonClicked 
{ 



NSUserDefaults *defFacebookData = [NSUserDefaults standardUserDefaults]; 


FBSDKLoginManager *login = [[FBSDKLoginManager alloc] init]; 
[login 
logInWithReadPermissions: @[@"public_profile", @"user_friends", @"email"] 
fromViewController:self 
handler:^(FBSDKLoginManagerLoginResult *result, NSError *error) { 
    if (error) { 
     DLog(@"Process error======%@",error.description); 
     indicators.hidden=YES; 
     [indicators stopAnimating]; 
    } else if (result.isCancelled) { 
     DLog(@"Cancelled"); 
     indicators.hidden=YES; 
     [indicators stopAnimating]; 
    } else { 

     if ([FBSDKAccessToken currentAccessToken]) { 



      [[[FBSDKGraphRequest alloc] initWithGraphPath:@"me" parameters:@{@"fields": @"id, name, link, first_name, last_name, picture.type(large), email, birthday, bio ,location ,friends ,hometown , gender ,friendlists"}] 
       startWithCompletionHandler:^(
              FBSDKGraphRequestConnection *connection, id result, NSError *error) { 
        if (!error) 
        { 

         // NSLog(@"fetched user:%@", result); 

         // [self fetchingFacebookFriends]; 

         [defFacebookData setObject:[result objectForKey:@"email"] forKey:@"fbEmail"]; 

         [defFacebookData setObject:[result objectForKey:@"id"] forKey:@"fbID"]; 


         //PASS ID 
         getFbid = [result objectForKey:@"id"]; 
    NSLog(@"getFbid========>%@",getFbid); 

         //PASS FIRST NAME 
         getFbFirstName=[result objectForKey:@"first_name"]; 

    NSLog(@"first======>%@",getFbFirstName); 

         //PASS LAST NAME 
         getFBlastName=[result objectForKey:@"last_name"]; 
    NSLog(@"first======>%@",getFBlastName); 

         //PASS EMAIL 
         getFbemail=[result objectForKey:@"email"]; 
    NSLog(@"first======>%@",getFbemail); 

         //PASS PHONE 
         getfbGender=[result objectForKey:@"gender"]; 
    NSLog(@"first======>%@",getfbGender); 


         [defFacebookData setObject:[result objectForKey:@"name"] forKey:@"fbName"]; 

         // Image 
         FBSDKGraphRequest *request = [[FBSDKGraphRequest alloc] 
                initWithGraphPath:[NSString stringWithFormat:@"me/picture?type=large&redirect=false"] 
                parameters:nil 
                HTTPMethod:@"GET"]; 
         [request startWithCompletionHandler:^(FBSDKGraphRequestConnection *connection, 
                  id fbImageResult, 
                  NSError *error) { 

NSString *strURL = [NSString stringWithFormat:@"%@",[[fbImageResult objectForKey:@"data"] objectForKey:@"url"]]; 

    NSLog(@"strURL=====>%@",strURL); 

[defFacebookData setObject:strURL forKey:@"fbImage"]; 

          [defFacebookData synchronize]; 


          NSDictionary *fbdict=[NSDictionary dictionaryWithObjectsAndKeys:getFbid,@"id",getFbFirstName,@"first_name",getFBlastName,@"last_name",getFbemail,@"email",getfbGender,@"gender",strURL,@"fbImage", nil]; 

          NSLog(@"done=========>%@",fbdict); 

    UIStoryboard*storyboard=[AppDelegate storyBoardType]; 

    NSUserDefaults *defaults =[NSUserDefaults standardUserDefaults]; 


    BOOL fblogin =[defaults boolForKey:@"KeyEditProfile"]; 

     if (fblogin) 
      { 

       UIStoryboard*Storyboard=[AppDelegate storyBoardType]; 
       DashboardVC* tabbarController = (DashboardVC*)[Storyboard instantiateViewControllerWithIdentifier:@"DashboardVCId"]; 

// tabbarController.dictFacebookdict = fbdict; // tabbarController.strFBlogin = @“fbAllDataValue”;

   indicators.hidden=YES; 
       [indicators stopAnimating]; 

       [self.navigationController pushViewController:tabbarController animated:YES]; 

     } 

    else 
    { 
    EditFBVC *cpvc=(EditFBVC*)[storyboard instantiateViewControllerWithIdentifier:@"EditFBVCId"]; 
    NSLog(@"get fb id ===%@",getFbid); 

// cpvc.checkBtnclick = @“1”; cpvc.dictFacebookdict = fbdict;

cpvc.strFBlogin [email protected]"fbAllDataValue"; 

     indicators.hidden=YES; 
     [indicators stopAnimating]; 

    [self.navigationController pushViewController:cpvc animated:YES]; 

    }     // [self facebookdataOnServer]; 
         }]; 
        } 
        else{ 
         //[SVProgressHUD dismiss]; 
         DLog(@"error is %@", error.description); 
        } 
       }]; 
     } 
    } 
}]; 

} 
相关问题