Unity与iOS平台SDK对接-方法篇 剪贴板中添加文本

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);
        }
    }

 

相关推荐
©️2020 CSDN 皮肤主题: 游动-白 设计师:白松林 返回首页