ios将图片上传到脸书

时间:2014-04-02 19:50:38

标签: ios facebook facebook-graph-api uiimage

这是我用来将图像上传到Facebook的最简单,最简单的代码,它可以在我的模拟器和测试阶段的设备上完美运行。但是,当我将我的应用程序发布到iTunes时,80%的应用程序崩溃,20%的成功将图像上传到Facebook。为什么会这样? Xcode显示警告" openActiveSessionWithPermissions已被弃用"

  if (FBSession.activeSession.isOpen)
{
    [self UploadToFb];
}
else // Take permissions
{
    NSArray *permissions = [[NSArray alloc] initWithObjects:
                            @"publish_stream",
                            nil];
    [self controlStatusUsable:NO];
    [FBSession openActiveSessionWithPermissions:permissions
                                   allowLoginUI:YES
                              completionHandler:^(FBSession *session, 
                                                  FBSessionState status, 
                                                  NSError *error) {
                                  // if login fails for any reason
                                  if (error) {


                                  } else if (FB_ISSESSIONOPENWITHSTATE(status)) {

                                      [[FBRequest requestForMe] startWithCompletionHandler:
                                       ^(FBRequestConnection *connection, NSDictionary<FBGraphUser> *user, NSError *error) {
                                           if (!error) {
                                             [self UploadToFb];

                                           }
                                     }];                                                
                                  }
                              }];
}

从用户上传图片到Facebook后获取权限

-(void)UploadToFb
{
[FBRequestConnection startForUploadPhoto:myImg.image 
                               completionHandler:^(FBRequestConnection *connection, id result, NSError *error) {
                if (!error) 
                   {
                     [FBRequestConnection startForUploadPhoto:myImg.image 
                               completionHandler:^(FBRequestConnection *connection, id result, NSError *error) {
                                  if (!error)
                                  {
                                      NSLog(@"Uploaded");
                                  } 
                                  else 
                                  {
                                       NSLog(@"Error");
                                  }
                    }];

                   } 
                   else 
                       {
                        NSLog(@"Error");
                       }
 }];
}

0 个答案:

没有答案