- Home /
Can you build iOS plugins using objective-c or only with pure c?
Hey :)
I'm in the proces of learning how to build native iOS plugins for Unity. I already have a lot of experience with objective-c as a language, so no problems there.
The problem is that there does not seem to be that much documentation out there on actually building iOS plugins (besides the official documentations which just shows some really shallow pure c functions build into a plugin).
What I am interested in knowing is if it's possible to build native plugins for iOS using objective-c, or are you forced to using pure C?
For example, could I take this objective-c class and source file:
DialogTest.h
@interface TestingThis : NSObject
-(void) ShowDialog;
@end
DialogTest.m
@implementation TestingThis
-(void) ShowDialog
{
UIAlertView *view = [[UIAlertView alloc] initWithTitle:@"MAO!" message:@"MAO!" delegate:nil cancelButtonTitle:@"OK!" otherButtonTitles:nil];
[view show];
[view release];
}
@end
And use it as a plugin in Unity for displaying a native popup? Or would I have to use pure c functions?
I actually already tried to import the above example source code into my Unity xCode project but unfortunately got linker errors when my test script tried to call the ShowDialog() function.
So can anyone shed some light on this? :) Any way to build plugins using pure objective-c?
Just remove my answer as I did not notice early enough it was plug-ins you were mentioning. I thought you were just starting and trying to use Objective-C as you saw iOS.
aha I see :D Well at any rate thank you for taking the time to read my question and attempting to help out :)
Yep, I'm well aware of them :) I am working on a project where we are trying to save money, so we would like to attempt not purchasing them, they do have a steep price when you need several feature packages at once. Since we already have experience with program$$anonymous$$g up against Store$$anonymous$$it, we thought it would be worth a try writing our own plugin ins$$anonymous$$d :)
Answer by $$anonymous$$ · Oct 11, 2012 at 10:57 AM
Well, figured it out in the end. You simply have an objective-c class as my example in the original post. What you do is write a C interface which calls the class methods for you, and then you call the C interface functions through Unity. To the flow is Unity method call -> C API -> Class method.
Hi PastryGood. I'm curious to know how you got it working. The C interface you said, in the example given at this page, http://docs.unity3d.com/Documentation/$$anonymous$$anual/Plugins.html, it's just a line. When you wrote the interface, do you have to do the normal #include and main functions?
Your answer
Follow this Question
Related Questions
low level native render plugin Xcode issues 1 Answer
Using NavigationController in an iOS plugin 1 Answer
xCode to Unity communication? 1 Answer