iOS6 problems to Tweet in UITabBarController using image taken from UIImagePickerController

StackOverflow https://stackoverflow.com/questions/15533066

  •  24-03-2022
  •  | 
  •  

Question

After picking image from UIImagePickerController I want to Tweet it but there is error!

Warning: Attempt to present <SLTwitterComposeViewController: 0x210d84b0> on <UITabBarController: 0x1fd67650> while a presentation is in progress!

P.S This is tabbar application (4 tabbars)

All code:

    -(void)useCamera:(id)sender
{
    if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]){
        UIImagePickerController *imagePicker =[[UIImagePickerController alloc] init];
        imagePicker.delegate = self;
        imagePicker.sourceType = UIImagePickerControllerSourceTypeCamera;
        imagePicker.mediaTypes = @[(NSString *) kUTTypeImage];
        imagePicker.allowsEditing = NO;
        [self presentViewController:imagePicker animated:YES completion:nil];
        _newMedia = YES;
    }
}

-(void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info{
    NSString *mediaType = info[UIImagePickerControllerMediaType];
    [self dismissViewControllerAnimated:YES completion:nil];

    if ([mediaType isEqualToString:(NSString *)kUTTypeImage]) {
        [self buttonTweet:info[UIImagePickerControllerOriginalImage]];
    }
}

- (IBAction)buttonTweet:(id)sender {

    SLComposeViewController *composeController = [SLComposeViewController composeViewControllerForServiceType:SLServiceTypeTwitter];

    [composeController setInitialText:[NSString stringWithFormat:@"#this is tweet text"]];
    [composeController addImage:sender];
    [composeController addURL: [NSURL URLWithString:@"http://www.abc.com"]];
    [self presentViewController:composeController animated:YES completion:nil];
}
Was it helpful?

Solution

You are presenting a new view controller while the old one is still disappearing. You can present the new one upon completion of the other animation by doing it like this:

[self dismissViewControllerAnimated:YES completion:^{
    if ([mediaType isEqualToString:(NSString *)kUTTypeImage]) {
        [self buttonTweet:info[UIImagePickerControllerOriginalImage]];
    }
}];
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top