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.

You can’t call Objective-C directly, you need to wrap it in C methods.

// .h
void sampleMethod();

// .m
void sampleMethod() {
   SomeClass *test = [[SomeClass alloc] init];
   [test someMethod];
   [test release]; // unity projects aren't arc
}