1、IOS篇(用OC和C++混编)
头文件声明:
public static void copy(std::string str);
实现如下:
void copy(std::string str) {
//把string类型转换成为char*
char*p=(char*)str.data();
//把char*转换成OC的NSString
NSString *nsMessage= [[NSStringalloc] initWithCString:pencoding:NSUTF8StringEncoding];
//获得iOS的剪切板
UIPasteboard *pasteboard = [UIPasteboardgeneralPasteboard];
//改变剪切板的内容
pasteboard.string = nsMessage;
}
2、Android篇
public void copy(final String str)
{
Runnable runnable = new Runnable() {
public void run() {
ClipboardManager mClipboardManager = (ClipboardManager)getSystemService(CLIPBOARD_SERVICE);
mClipboardManager.setText(str);
}
};
runOnUiThread(runnable);
}