- Home /
Executing native iOS code in Unity
I want to execute following code in Unity.
UIImage *image = [UIImage imageNamed:@"roadfire.png"];
NSString *message = @"Best image from my application.";
NSArray *postItems = @[message, image];
UIActivityViewController *activityVc = [[UIActivityViewController alloc]initWithActivityItems:postItems applicationActivities:nil];
[self presentViewController:activityVc animated:YES completion:nil];
I have implemented similar code for Android using AndroidJavaObject and AndroidJavaClass object but I can't able to understand how to convert this code?
Only starting point become enough for me.
Answer by Bunny83 · Oct 24, 2014 at 01:13 PM
AndroidJavaObject and AndroidJavaClass are wrapping the JNI interface that is available for native code by the JVM. So your route is:
your managed code -> Unity's native JNI wrapper -> Java
iOS of course doesn't run Java since iOS requires all code to be compiled AOT to xcode / objective c. When you build an iOS project, Unity just creates an xcode project which then can be built using xcode. You are free to change the code that Unity has cross compiled, however you have to do this every time when you rebuild the xcode project from Unity.
It's probably possible to compile a native library for iOS that you can add to the Unity project itself as "plugin". However i'm not familiar with iOS development. Maybe someone else know how to create "objective c plugins" for unity.
I don't like the objective c syntax. It looks "too alien" to me :D
Thanks @Bunny83 for this help. I have one question in my $$anonymous$$d. Can I modify unity code using xcode means add some code?
Yes, as i said when you build your Unity project for iOS you actually create an xcode project which can be modified in xcode. Just take a look at the project that get generated. Of course don't use "build and run" as this will tell xcode to build the project and push the app to your device.
Your answer
Follow this Question
Related Questions
iOS native share PDF popup with QuickLook option 1 Answer
A node in a childnode? 1 Answer
Sharing image and text using objective c native code 1 Answer
Execute native ios code in unity 1 Answer
Share text message on selected media 1 Answer