我尝试使用 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/