Now that I have built an iOS plugin for sharing I need to implement a wrapper class for it in C# for Unity. This post will go through the wrapper class code that I put together to add the feature of sharing to Facebook or Twitter for a Unity game for iPhone. I will go into detail about how to make the Objective-C methods available to the C# wrapper class.
From the previous post I have the following files inside the
Here we define the class
The Objective-C classes defined under the
Plugins/iOS directory are statically linked into the executable created for the iPhone. This means that the
_Share method defined in the Objective-C class exists in the executable. To get access to it we need to do an internal DLL Import of the method. The following code achieves this:
Given I have imported the method I can now invoke it inside the
ShareImage method with the appropriate parameters.
I found the process of working with iOS and Unity quite enjoyable and not as painful as working with Android. This might be because i’m working on an iMac and I have an iPhone device. In my next post I will go over the class I wrote for unifying the Android and iOS logic.
All of the code including the Objective-C classes has been open sourced on our company github account.