Hi,
Here's what I have done:
1- Define some functions within a framework
In .h :
#import
FOUNDATION_EXPORT double TestVersionNumber;
FOUNDATION_EXPORT const unsigned char TestVersionString[];
@interface MyLib : NSObject
+ (id)sharedInstance;
- (void)openWebView:(NSString *)url;
- (BOOL)testMethod;
@end
In .m :
#import
#import "MyLib.h"
#import "ViewController.h"
@interface MyLib()
@property (nonatomic, retain) ViewController *webViewController;
@end
@implementation MyLib
- (void)dealloc {
[[NSNotificationCenter defaultCenter] removeObserver:self];
}
+ (id)sharedInstance {
static dispatch_once_t pred = 0;
static id instance = nil;
dispatch_once(&pred, ^{
instance = [[self alloc] init];
});
return instance;
}
- (BOOL)testMethod {
NSLog(@"testMethod was called");
return TRUE;
}
@end
3- I then copied the **framework** to 'Assets/Plugins/iOS/` folder
4- I attached this to the camera in the scene:
using UnityEngine;
using System.Collections;
using System.Runtime.InteropServices;
public class Ttest : MonoBehaviour {
[DllImport ("__Internal")]
private static extern bool testMethod();
// Use this for initialization
void Start () {
var result = testMethod();
if (result) {
Camera.main.backgroundColor = Color.yellow;
}
}
}
4- Built the unity project and ran in the simulator.
I get an error saying testMethod() was not found.
What's the problem?
Thanks.
↧