ios - 如何在 swift 中调用 UnitySendMessage 方法?

标签 ios swift unity3d

我尝试使用 swift 语言在我的 iOS Framework 项目中调用 UnitySendMessage 方法,但它显示此错误-

使用未解析的标识符“UnitySendMessage”

这是我的 swift 文件的代码片段-

import Foundation

@objc public class Example : NSObject{

    @objc open static let shared = Example()

    @objc open func printMsg(){
        print("\(#function) is called with message:");
        UnitySendMessage("CallbackTarget", "OnCallFromSwift", "Hello, Unity!");
    }
}

卡在这里,你能告诉我我错过了什么吗?

最佳答案

检查答案here .

UnitySendMessage is in libiPhone-lib.a, and as far as I can tell, the Unity folks don't include any header that declares it.

I just added the following to my code

extern void UnitySendMessage(const char *, const char *, const char *);

If you look at the generated AppController.mm, they basically do the same thing for the various UnitySendXXX functions, rather than including a header.

Having said that, while you will be able to build a library that calls UnitySendMessage, that library probably won't work unless it's linked into a Unity project, since UnitySendMessage is going to require more than just libiPhone-lib.a to actually work.

关于ios - 如何在 swift 中调用 UnitySendMessage 方法?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51192883/

相关文章:

ios - 如何将图像从 tableView 传输到另一个 imageViewController?

ios - 为什么 UserDefaults.standard.set 不保存我的数组?从后台删除应用程序后,数据将被清除

ios - 删除动画后保留动画 UIView 属性,但不使用类变量?

c# - Application.streamingAssetsPath 和 Application.persistentDataPath 有什么区别?如何使用?

c# - Unity 敌人 ai 总是向玩家上方发射子弹

ios - 应用程序因 EXC_SOFTWARE/UNCAUGHT_NS_EXCEPTION 而崩溃

ios - Apple IOs 更新,旧版本会保留吗?

Xcode 6 + Swift + NSTextViewDelegate = 编译错误

arrays - 从另一个 Array<String> 过滤 Array<String> 的值

c# - Unity如何从不同的对象引用一个对象