Skip to main content
Post Closed as "Not suitable for this site" by House
added 381 characters in body
Source Link
Siddharth
  • 2k
  • 5
  • 27
  • 55

I want to execute native iOS code in unity. For this I have added two files in /plugins/ios.

  1. ViewController.h
  2. 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.

enter image description here

I can't able to understand how to solve this problem? Please give some suggestion here.

EDIT :

I have added extern keyword in my .m file after reading some suggestion.

#import "ViewController.h"

@implementation ViewController

extern "C"
{
   -(void)sampleMethod
   {
        NSLog(@"Sample Method Execute");
   }
}
@end

But in xCode now I am getting Expected Identifier or '(' at the line of extern keyword line. So what to do next?

I want to execute native iOS code in unity. For this I have added two files in /plugins/ios.

  1. ViewController.h
  2. 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.

enter image description here

I can't able to understand how to solve this problem? Please give some suggestion here.

I want to execute native iOS code in unity. For this I have added two files in /plugins/ios.

  1. ViewController.h
  2. 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.

enter image description here

I can't able to understand how to solve this problem? Please give some suggestion here.

EDIT :

I have added extern keyword in my .m file after reading some suggestion.

#import "ViewController.h"

@implementation ViewController

extern "C"
{
   -(void)sampleMethod
   {
        NSLog(@"Sample Method Execute");
   }
}
@end

But in xCode now I am getting Expected Identifier or '(' at the line of extern keyword line. So what to do next?

Source Link
Siddharth
  • 2k
  • 5
  • 27
  • 55

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.

  1. ViewController.h
  2. 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.

enter image description here

I can't able to understand how to solve this problem? Please give some suggestion here.