问题
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