How I can use a UIImagePickerController to add an image to a tweet? [closed]

那年仲夏 提交于 2019-12-13 08:20:57

问题


I'm new to iOS development so I'm confused. I have a ViewController, in this ViewController there are many UIButtons. How I can open the picker and add the image to the tweet using addImage? PS: I'm using Storyboard.

Thanks and sorry for my english... :)


回答1:


when the button is pressed, you want to do something like:

  if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeSavedPhotosAlbum]) {
    UIImagePickerController *imagePicker = [[UIImagePickerController alloc] init];        

    imagePicker.sourceType =  UIImagePickerControllerSourceTypeSavedPhotosAlbum;  

    imagePicker.delegate = self;

    [self presentModalViewController:imagePicker animated:YES];
  }

you need to implement the delegate methods. the main one is:

- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
    UIImage *image = [info objectForKey:@"UIImagePickerControllerOriginalImage"];

    NSData *imageData = UIImagePNGRepresentation(image);

    // do twitter stuff here....

    [self dismissModalViewControllerAnimated:YES];
}

for more information, see the docs: http://developer.apple.com/library/ios/#documentation/AudioVideo/Conceptual/CameraAndPhotoLib_TopicsForIOS/Articles/PickinganItemfromthePhotoLibrary.html#//apple_ref/doc/uid/TP40010408-SW1



来源:https://stackoverflow.com/questions/8991613/how-i-can-use-a-uiimagepickercontroller-to-add-an-image-to-a-tweet

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