I am trying to add an image to a Tweet sheet in my iOS 6 app. I have one small problem. Once the user has select the image from the Photo Library, I want to then show the TweetSheet but I get the following warning:
Warning: Attempt to present on while a presentation is in progress!
How can I display the Tweet Sheet after the dismiss animation of the Photo Library has completed?
Here is my code:
-(void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
image = [info objectForKey:UIImagePickerControllerOriginalImage];
[self dismissViewControllerAnimated:YES completion:nil];
[self tweet_image];
}
-(void)imagePickerControllerDidCancel:(UIImagePickerController *)picker {
[self dismissViewControllerAnimated:YES completion:nil];
}
-(void)tweet_image {
if ([SLComposeViewController isAvailableForServiceType:SLServiceTypeTwitter]) {
SLComposeViewController *tweetSheet = [SLComposeViewController composeViewControllerForServiceType:SLServiceTypeTwitter];
[tweetSheet setInitialText:[NSString stringWithFormat: @"@%@ ", USERNAME]];
[tweetSheet addImage:image];
[self presentViewController:tweetSheet animated:YES completion:nil];
}
else {
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"Sorry" message:@"You can't send a tweet right now, make sure your device has an internet connection and you have at least one Twitter account setup in iOS settings." delegate:self cancelButtonTitle:@"Dismiss" otherButtonTitles:nil];
[alertView show];
}
}
Thanks, Dan.
Place your call to -tweet_image in the completion block of -dismissViewControllerAnimated:
-(void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
image = [info objectForKey:UIImagePickerControllerOriginalImage];
[self dismissViewControllerAnimated:YES completion:^ {
[self tweet_image];
}];
}