ios upload image to facebook

怎甘沉沦 提交于 2020-01-06 05:00:12

问题


This is the most easy and simple code I have used to upload images to Facebook it works perfectly on my simulator and on my device in testing phase. But when I published my app to iTunes it 80% got crash and 20% made success to upload image to facebook. Why this is happening ? Xcode shows warning that "openActiveSessionWithPermissions is deprecated"

  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];

                                           }
                                     }];                                                
                                  }
                              }];
}

After taking Permissions from user Upload image to 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");
                       }
 }];
}

来源:https://stackoverflow.com/questions/22821575/ios-upload-image-to-facebook

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!