I’m trying to get my feet wet with native plugin programming and my goal is to write a OSX / Mac plugin that can be used for Push notifications on the Mac. So far I’ve followed the basic steps to create a cocoa bundle and created an objective C class named “Plugin” (Plugin.h/.m).
For a simple test I would like to call from Unity a NSLog output in the plugin via the SoundTest method. The .m file looks like this:
#include #import "Plugin.h" @implementation Plugin - (void)DebugLog:(NSString *)msg { NSLog(@"###################################"); } - (void)SoundTest { // <-------------- WANT TO CALL THIS ONE FROM C# CODE NSLog(@"======================================"); } ... ...
I created a corresponding C# file to import the plugin:
using UnityEngine; using System.Collections; using System; using System.Runtime.InteropServices; public class PushNotificationPlugin { //Calls to the native plugin [DllImport ("PushNotification")] public static extern void SoundTest();
Now I got in Xcode a pre-defined PCH file and I read that I have to define in there via some extern “C” the method call. But how?
This is the generated PushNotification-Prefix.pch file:
#ifdef __OBJC__ #import extern "C" { static extern void SoundTest(); // <----- doesn't work } #endif