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.

Execute native ios code in unity

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?

Replay

Right now I'm not in a place to go over your code thoroughly, but at a glance I'm wondering if you need to declare your code with C linkage as explained here:

extern "C" {
  float FooPluginFunction();
}

I'm not sure if this answers your question but:

iOS of course doesn't run Java since iOS requires all code to be compiled AOT to xcode / objective c. When you build an iOS project, Unity just creates an xcode project which then can be built using xcode. You are free to change the code that Unity has cross compiled, however you have to do this every time when you rebuild the xcode project from Unity.

It's probably possible to compile a native library for iOS that you can add to the Unity project itself as "plugin". However i'm not familiar with iOS development.

http://answers.unity3d.com/questions/816358/executing-native-ios-code-in-unity.html

Category: unity Time: 2014-11-02 Views: 0

Related post

iOS development

Android development

Python development

JAVA development

Development language

PHP development

Ruby development

search

Front-end development

Database

development tools

Open Platform

Javascript development

.NET development

cloud computing

server

Copyright (C) avrocks.com, All Rights Reserved.

processed in 0.219 (s). 12 q(s)