Search Unity

Get photo from native API

Discussion in 'iOS and tvOS' started by Ahmadhp, Mar 13, 2015.

  1. Ahmadhp

    Ahmadhp

    Joined:
    May 31, 2013
    Posts:
    33
    Hi,

    I try to work with native camera through unity ( capture photo , get from library , save photo ,...)
    I can bring camera in unity app with UIImagePickerController like this :
    Code (CSharp):
    1. - (void) pickImageFrom:(bool) camera
    2. {
    3.     UnityAppController* uac = (UnityAppController*)[UIApplication sharedApplication].delegate;
    4.  
    5.     UIImagePickerController* imagePicker = [[UIImagePickerController alloc] init];
    6.  
    7.     if (camera)
    8.     {
    9.         if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera])
    10.         {
    11.             imagePicker.sourceType = UIImagePickerControllerSourceTypeCamera ;
    12.         }
    13.     }
    14.     else
    15.     {
    16.         imagePicker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary ;
    17.     }
    18.  
    19.     imagePicker.delegate = (id)uac.rootViewController ;
    20.     imagePicker.allowsEditing = YES ;
    21.     [uac.rootViewController presentViewController:imagePicker animated:YES completion:NULL];
    22. }
    But i don't know where should i put "didFinishPickingMediaWithInfo" call back to get the result ...

    Any Idea ??

    Thanks in advance
     
  2. aihodge

    aihodge

    Joined:
    Nov 23, 2014
    Posts:
    163
    The didFinishPickingMediaWithInfo: delegate method should be in the same class as your pickImageFrom: method. Don't forget to set this class to be the UIImagePickerControllerDelegate.
     
  3. Ahmadhp

    Ahmadhp

    Joined:
    May 31, 2013
    Posts:
    33
    Thank you @aihodge ... That works
    I thought image picker delegate must be view controller , but i was wrong :D