尝试编写一个快速的Unity插件以从剪贴板中获取数据,有问题的函数如下:
extern "C"
{
const char * _importString()
{
UIPasteboard *result = [UIPasteboard generalPasteboard];
NSString * resultString = [result string];
return [resultString UTF8String];
}
}
但是,当我激活该功能时,它给了我以下错误:
GfxDevice: creating device client; threaded=1
Initializing Metal device caps: Apple A9 GPU
Initialize engine version: 2017.1.0f3 (472613c02cf7)
2017-08-26 13:46:21.395230+0100 ProductName[8608:2930827] [Common] _BSMachError: port 5e03; (os/kern) invalid capability (0x14) "Unable to insert COPY_SEND"
2017-08-26 13:46:21.400889+0100 ProductName[8608:2930827] [Common] _BSMachError: port 5e03; (os/kern) invalid capability (0x14) "Unable to insert COPY_SEND"
UnloadTime: 4.034333 ms
ProductName(8608,0x1b8100b40) malloc: *** error for object 0x1740a6191: pointer being freed was not allocated
*** set a breakpoint in malloc_error_break to debug
主要用Unity C编写,所以对iOS插件知之甚少,也不知道从哪里开始,任何帮助表示赞赏。
编辑:
对于那些在家玩的人,这里有相关的 Unity 代码段:
[DllImport("__Internal")]
private static extern string _importString();
//retrieves the clipboard contents from xcode
public string iPhoneImportClipboard()
{
return _importString();
}
-string
的结果不得被视为恶意指针。
您需要malloc
缓冲区并在返回之前strcpy
所述字符串。
extern "C"
{
const char * _importString()
{
UIPasteboard *result = [UIPasteboard generalPasteboard];
NSString * resultString = [result string];
return strdup([resultString UTF8String]);
}
}