为什么不支持我的Facebook集成对话框登录?

时间:2014-06-23 04:40:54

标签: ios iphone objective-c facebook safari

在我的应用程序中,当我点击Facebook登录它进入Safari浏览器时,我创建了Facebook集成,如何在不通过Safari网络浏览器输入的情况下将其更改为对话框登录?

提前致谢。

  

[FBSession.activeSession closeAndClearTokenInformation];       if(FBSession.activeSession.accessTokenData.loginType!= FBSessionLoginTypeFacebookApplication / ||   FBSession.activeSession.accessTokenData.loginType!=   FBSessionLoginTypeSystemAccount /){           [HUD隐藏:是];           HUD = [MBProgressHUD showHUDAddedTo:self.navigationController.view animated:YES];           HUD.labelText = @"登录";

[FBSession openActiveSessionWithReadPermissions:@[@"basic_info",@"email",@"user_location",@"user_birthday",@"user_hometown,user_friends"]
                                   allowLoginUI:YES
                              completionHandler:^(FBSession *session, FBSessionState state, NSError *error) {

                                  switch (state) {
                                      case FBSessionStateOpen:{

                                          [FBSession setActiveSession:session];
                                          [self checkSessionState:state];
                                          [[FBRequest requestForMe] startWithCompletionHandler:^(FBRequestConnection
     

* connection,NSDictionary * user,NSError * error){                                                     if(error){                                                         [HUD隐藏:是];                                                         NSLog(@"错误报告:%@",错误);                                                     }                                                     其他                                                     {                                               [HUD隐藏:是];

                                       NSString *userLocation =  [NSString stringWithFormat:@"%@\n\n",user.location[@"name"]];
                                        NSArray* foo = [userLocation componentsSeparatedByString: @","];
                                        NSString *strCity  = [foo objectAtIndex: 0];
                                        NSString *strState  = [foo objectAtIndex: 1];



                                                  NSString *linkURL = [NSString stringWithFormat:@"http://carzillaapp.com/"];
                                                  NSString *pictureURL = @"http://www.friendsmash.com/images/logo_large.jpg";
                                                   //                                                      NSString *pictureURL = @" ";

                                                  // Prepare the native share dialog parameters
                                                  FBShareDialogParams *shareParams = [[FBShareDialogParams alloc] init];
                                                  shareParams.link = [NSURL URLWithString:linkURL];
                                                  shareParams.name = @"Download and Checkout CarZilla App!";
                                                  shareParams.caption= @"An online Car Showroom!";
                                                  shareParams.picture= [NSURL URLWithString:pictureURL];
                                                  shareParams.description =
                                                  [NSString stringWithFormat:@"Both new and old cars available there!"];

                                                  if ([FBDialogs canPresentShareDialogWithParams:shareParams]){

                                                      [FBDialogs presentShareDialogWithParams:shareParams
                                                                                  clientState:nil
                                                                                      handler:^(FBAppCall *call, NSDictionary *results, NSError *error) {
                                                                                          if(error) {
                                                                                              NSLog(@"Error publishing story.");
                                                                                          } else if (results[@"completionGesture"] &&
     

[results [@" completionGesture"] isEqualToString:@"取消"]){                                                                                                     NSLog(@"用户取消故事发布。");                                                                                                 } else {                                                                                                     NSLog(@"故事发布。");                                                                                                 }                                                                                             }];

                                                  } else {

                                                      // Prepare the web dialog parameters
                                                      NSDictionary *params = @{
                                                                               @"name" : shareParams.name,
                                                                               @"caption" : shareParams.caption,
                                                                               @"description" : shareParams.description,
                                                                               @"picture" : pictureURL,
                                                                               @"link" : linkURL
                                                                               };

                                                      // Invoke the dialog
                                                      [FBWebDialogs presentFeedDialogModallyWithSession:nil
                                                                                             parameters:params
                                                                                                handler:
                                                       ^(FBWebDialogResult result, NSURL *resultURL, NSError *error) {
                                                           if (error) {
                                                               NSLog(@"Error publishing story.");
                                                           } else {
                                                               if (result == FBWebDialogResultDialogNotCompleted) {
                                                                   NSLog(@"User canceled story publishing.");
                                                               } else {
                                                                   NSLog(@"Story published.");
                                                               }
                                                           }}];
                                                  }





                                                  NSDictionary *params = @{
                                                                           @"name" : shareParams.name,
                                                                           @"caption" : shareParams.caption,
                                                                           @"description" : shareParams.description,
                                                                           @"picture" : pictureURL,
                                                                           @"link" : linkURL
                                                                           };

                                                  [FBWebDialogs presentRequestsDialogModallyWithSession:nil
                                                                                                message:[NSString stringWithFormat:@"Checkout the CarZilla App!"]
                                                                                                  title:@"Invite"
                                                                                             parameters:params
                                                                                                handler:^(FBWebDialogResult result, NSURL *resultURL, NSError *error)
     

{                                                                                                           if(error){                                                                                                               //案例A:启动对话框或发送请求时出错。                                                                                                               NSLog(@"发送请求时出错。");                                                                                                           } else {                                                                                                               if(result == FBWebDialogResultDialogNotCompleted){                                                                                                                   //案例B:用户点击了" x"图标                                                                                                                   NSLog(@"用户取消请求。");                                                                                                               } else {                                                                                                                   NSLog(@"请求已发送。");                                                                                                               }                                                                                                           }}                                                          ];

                                        SignUpViewController *faceblogin = [[SignUpViewController alloc]init];
                                        faceblogin.firstName = [NSString stringWithFormat:@"%@ ",user.first_name];
                                        faceblogin.lastName = user.last_name;
                                        faceblogin.email =[user objectForKey:@"email"];
                                        faceblogin.city = strCity;
                                        faceblogin.state = strState;
                                        faceblogin.fblogin = YES;
                                        fbFailure = YES;
                                        fbMsg = YES;
                                        faceblogin.accountType = @"Individual Buyer/Seller";
                                        //faceblogin.isPhoneno = YES;
                                        [self presentViewController:faceblogin animated:YES completion:nil];
                                              }
                                          }];
                                          break;
                                      }
                                      case FBSessionStateClosed:{
                                          [HUD hide:YES];
                                          NSLog(@"facebook values");

                                      }
                                      case FBSessionStateClosedLoginFailed:{
                                          [HUD hide:YES];
                                          if ((!fbFailure && fbMsg) || error.code == 2) {
                                              UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"Error" message:@"Unfortunately, we
     

无法使用您的Facebook凭据登录。"   delegate:nil cancelButtonTitle:@" Ok" otherButtonTitles:nil,nil];                                                     fbMsg = NO;                                                     [警示显示];                                                 }                                                 [FBSession.activeSession closeAndClearTokenInformation];                                                 打破;                                             }                                             默认:                                                 打破;                                         }                                     }];       }

else{

    NSLog(@"accounts");    }

0 个答案:

没有答案