Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Try this code.. Its working properly from my side.</p> <pre><code>- (IBAction) uploadPhoto:(id)sender { UIActionSheet *actionSheet = [[UIActionSheet alloc] initWithTitle:@"" delegate:self cancelButtonTitle:@"Cancel" destructiveButtonTitle:nil otherButtonTitles:@"Use Photo from Library", @"Take Photo with Camera", nil]; actionSheet.actionSheetStyle = UIActionSheetStyleDefault; actionSheetAction = ActionSheetToSelectTypeOfSource; [actionSheet showInView:self.view]; [actionSheet release]; } - (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex { UIImagePickerControllerSourceType sourceType; if (buttonIndex == 0) { sourceType = UIImagePickerControllerSourceTypePhotoLibrary; } else if(buttonIndex == 1) { sourceType = UIImagePickerControllerSourceTypeCamera; }else { // Cancel break; } if([UIImagePickerController isSourceTypeAvailable:sourceType]) { UIImagePickerController *picker = [[UIImagePickerController alloc] init]; picker.sourceType = sourceType; picker.delegate = self; if (sourceType == UIImagePickerControllerSourceTypeCamera) { picker.cameraFlashMode = UIImagePickerControllerCameraFlashModeOn; } picker.allowsImageEditing = NO; [self presentModalViewController:picker animated:YES]; [picker release]; } } #pragma mark - #pragma mark UIImagePickerControllerDelegate - (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info { UIImage *image = [info objectForKey:@"UIImagePickerControllerOriginalImage"]; NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); NSString *docDirectory = [paths objectAtIndex:0]; NSString *imgPath = [documentsDirectory stringByAppendingPathComponent:[NSString stringWithFormat:@"image1.png"]]; //COnvert it to NSData before saving and then save it NSData *imgData = UIImagePNGRepresentation(image); [imgData writeToFile:imgPath atomically:YES]; [self dismissModalViewControllerAnimated:YES]; } - (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker { [self dismissModalViewControllerAnimated:YES]; } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload