ios - How can I return a bool from objc(Xcode) to Unity OR execute a function in xCode? -


i quite in unity face problem couldn't solve after days of research. want execute function on iphone when camera permission app created not given user. want show alert message in code below(which works when put whole alertview-stuff inside if-statement). cannot figure out how place ibaction there (so button works). ofc better if xcode return variable int or boolean unity , execute functions in there advice user.

basically flow following:

  1. user wants make pic

  2. uialert pops "you need give camera permission blabla"

  3. user chooses "go settings" , opens settings.

here's code have far:

#include "permissioncamplugin.h" #import "permissioncamplugin.h" #import <social/social.h> #import <foundation/nsexception.h> #import <avfoundation/avfoundation.h> #import <uikit/uikit.h> @implementation alertviewcontroller  -(ibaction)alertbutton {    uialertview *alert = [[uialertview alloc] initwithtitle:@"oops... "                                                 message:@"if want enable camera go settings."                                                delegate:self                                       cancelbuttontitle:@"close"                                       otherbuttontitles:@"go settings", nil]; [alert show]; }   -(void)alertview:(uialertview *)alertview clickedbuttonatindex:(nsinteger)buttonindex { if(buttonindex == 1) {     [[uiapplication sharedapplication] openurl:[nsurl urlwithstring:uiapplicationopensettingsurlstring]]; } } @end    bool cameracheckdone = no;   bool campermgiven = no;   void sd_camera_permission()  {  if ([avcapturedevice respondstoselector:@selector(requestaccessformediatype:completionhandler:)]) {     // completion handler dispatched on separate thread     [avcapturedevice requestaccessformediatype:avmediatypevideo completionhandler:^(bool granted) {         if (yes == granted)         {             campermgiven = yes;         }         else         {             campermgiven = no;              //here want execute alert call , execute button function if user chooses         }          // (no matter if 'granted' yes or no)         cameracheckdone = yes;     }]; } else {     // ios < 7 (camera access ok)      cameracheckdone = yes;     // continue app launch... } 

}

write function in class , call function unity when app launched or can write unity send message in .m file call unity function.

xcode .m file:

extern "c" {

bool getcamerastatus() {      return campermgiven;  } 

}

unity class: [dllimport ("__internal")] private static extern bool getcamerastatus ();


Comments

Popular posts from this blog

ubuntu - PHP script to find files of certain extensions in a directory, returns populated array when run in browser, but empty array when run from terminal -

php - How can i create a user dashboard -

javascript - How to detect toggling of the fullscreen-toolbar in jQuery Mobile? -