- Home /
Execute native ios code in unity
I want to execute native iOS code in unity. For this I have added two files in /plugins/ios.
ViewController.h
ViewController.m
Code for each file represented as under.
ViewController.h
@interface ViewController
-(void)sampleMethod;
@end
ViewController.m
#import "ViewController.h"
@implementation ViewController
-(void)sampleMethod
{
NSLog(@"Sample Method Execute");
}
@end
For C# file I have added following code
[DllImport("__Internal")]
private static extern void sampleMethod();
and call to above method
sampleMethod();
When I am export project for iOS, xCode give me following error that I can't able to understand.
I can't able to understand how to solve this problem? Please give some suggestion here.
Answer by gjf · Nov 02, 2014 at 05:45 PM
you need to expose the iOS code as "C"... i don't recall the correct syntax but something like
extern "C"
{
your iOS code here...
}
Which code I have to write in extern brackets? Because I have created .h and .m file those correctly executed in xCode.
in the past, i've put everything from my source (.mm in my case) inside the braces. the functions need to be declared as external to xcode, then unity can 'see' them.
i haven't done much with iOS so the syntax may be different for your .m files...
Your answer
Follow this Question
Related Questions
Native Gallery "Error returned from daemon: Error Domain=com.apple.accounts Code=7 "(null)"" 1 Answer
Is it possible to capture the iOS GPU frame time using XCode or XCode Instruments? 2 Answers
Support for Delta Updates in Unity 1 Answer
GUI Button linking to a different UIView/UIViewController 0 Answers
Application quit shows error in iOS 1 Answer