简体   繁体   中英

Error with UIImagePickerController

I have this code for send images on tweet. When I try the app, the picker works well but it doesn't grab the image. What's wrong?

- (IBAction)sendImageTweet:(id)sender
{
    UIImagePickerController *picker = [[UIImagePickerController alloc] init];
    picker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
    picker.delegate = self;
    picker.allowsEditing = NO;
    [self presentModalViewController:picker animated:YES];
}

- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
    TWTweetComposeViewController *tweetViewController = [[TWTweetComposeViewController alloc] init];
    UIImage *image = [info objectForKey:@"UIImagePickerControllerOriginalImage"];
    NSData *imageData = UIImagePNGRepresentation(image);
    [self dismissModalViewControllerAnimated:YES];
    [tweetViewController addImage:(UIImage *)imageData];
    [self presentModalViewController:tweetViewController animated:YES];
}

你应该使用常量,而不是NSString和密钥。

UIImage *image = [info objectForKey:UIImagePickerControllerOriginalImage];

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM