Creation of the Unity 3D simple project. Export to iOS platform with Xcode see this
Unity3d Learn to create simple buttons, corresponding events
Unity C # code
Using unityengine;using system.collections;using System.runtime.interopservices;public class Testfeil:monobehaviour { [DllImport ("__internal")] private static extern void C_ctest (); Use the for initialization void Start () { } //update is called once per frame void update () { } void Ongui () the {//Start button creates a button. if (GUI. button (new Rect (20,100,200,50), "Qingyun")) { //system.console.writeline ("Hello World"); Print ("Hello Qingyun!"); C_ctest (); Debug.Log ("Up.up"); } } void TestResult (String msg) { Debug.Log ("TestResult:" +msg); This is a callback in C #. Used to receive data whether the transmission was successful. ----The function here is the callback in OC. void Testbtnresult (String msg) { Debug.Log ("btnpresssuccessssssssssss:" +msg); }}
OC and C interfaces in. mm files
meiyupushsdkc.m//meiyupushdemo////Created by Qingyun on 3/31/14.//Copyright (c) Qingyun. All rights reserved.//#import "MeiyuPushSdkC.h" #import "MeiyuPushSdk.h" @interface meiyupushsdkc:nsobject< Meiyupushsdkdelegate> @end @implementation meiyupushsdkc-(ID) init{id object = [super init]; [[Meiyupushsdk my_initpush]setdelegate:self]; Sdk.delegate = self; NSLog (@ "INITMEIYUPUSHSDKC"); return object;} -(void) ctestresult{unitysendmessage ("Main Camera", "Testbtnresult", "success. Wow hahaha");} @endMeiyuPushSdkC *m_pushsdk = NULL, #if defined (__cplusplus) extern "C" {#endif void C_ctest () {if (M_push SDK = = NULL) {m_pushsdk = [[Meiyupushsdkc alloc]init]; } meiyupushsdk *m = [Meiyupushsdk My_initpush]; Objc_msgsend (obj, @selector (setName:), @ "Balabala"); [M ctest]; NSLog (@ "testsuccess---------"); Unitysendmessage ("Main Camera", "TestResult", " -10862904$_^_$ Interface call failed"); } #iF defined (__cplusplus)} #endif
This connects Unity3d with OC.
Specifically, refer to Unityfile.zip
Data interaction between Unity3d and Objective-c. IOS SDK interface encapsulates the Unity3d interface.--Reprint