oc代码
//将文本复制到IOS剪贴板
- (void)copyTextToClipboard : (NSString*)text
{
UIPasteboard *pasteboard = [UIPasteboard generalPasteboard];
pasteboard.string = text;
}
#if defined(__cplusplus)
extern "C"{
#endif
void _iOS_SetSDKValue(const char* key, const char* strData)
{
NSString* strFunc = [NSString stringWithUTF8String: key];
NSString* strVal = [NSString stringWithUTF8String: strData];
NSLog(@"%@", [NSString stringWithFormat:@"ios sdk call _iOS_SetSDKValue funcName : %@, funcArg : %@",strFunc, strVal]);
if([strFunc isEqualToString:@"CopyTextToClipboard"])
{
//将文本复制到IOS剪贴板
[[SDKCommonHelper shareSDKCommonHelper] copyTextToClipboard:strVal];
}
}
#if defined(__cplusplus)
}
#endif
Unity中方法
[DllImport("__Internal")]
private static extern void _iOS_SetSDKValue(string key, string value);
/// <summary>
/// 可复制内容至手机剪切板
/// </summary>
/// <param name="str"></param>
public void CopyTextToClipboard(string str)
{
try
{
_iOS_SetSDKValue("CopyTextToClipboard", value);
}
catch (Exception e)
{
Debuger.PrintLog("ceaponFire3D ==>CopyTextToClipboard 可复制内容至手机剪切板=" + e.Message, AppConst.IsHotModel);
}
}
本文详细介绍了一种在iOS设备上实现文本复制到剪贴板的方法。通过Objective-C和Unity的跨平台调用,展示了如何使用SDK接口进行剪贴板操作,为开发者提供了一个实用的代码示例。
3365

被折叠的 条评论
为什么被折叠?



