当前位置:   article > 正文

unity ShareSDk 接入遇到的问题_unity 添加share sdk后没有引用到using cn.sharesdk.unity3d;

unity 添加share sdk后没有引用到using cn.sharesdk.unity3d;

ShareSDK接入的是整个untiy 的包 官方直接包含了android 和 ios 所以只需要写接口和处理打包配置文件就行

安卓处理

1:android

:

2:在配置文件里面写回调函数和设置权限 (已经有的直接点击这个就行了)

注意修改这个 AndroidManifest.xml 微信回调要和包名一样

2:微信回调 要根据包名生成不同的DemoCallBack.jar文件

官方工程里面的微信回调改成自己的包名 打包为DemoCallBack.jar文件 替换工程里面的DemoCallBack文件

3:提示语言设置根据手机当前系统语言显示提示 (不会根据游戏内部语言修改而改变)

 

 

ios 一定要直接导入插件不能删除ios下的东西

出现错误  编译完了,在链接时候报的错 这个不是报错,这个不用管 桥接文件里有警告的东西,不用管的

解决报错

这里点击+号,添加下这个JavaScriptCore.framework依赖库

 

使用代码

  1. using UnityEngine;
  2. using System.Collections;
  3. using System.IO;
  4. using cn.sharesdk.unity3d;
  5. using LuaInterface;
  6. using LuaFramework;
  7. using System.Collections.Generic;
  8. public class ShareSDKTool : MonoBehaviour
  9. {
  10. //sharesdk实例
  11. private ShareSDK ssdk;
  12. //设置lua回调方法
  13. LuaFunction luaFun;
  14. //截屏图片名字
  15. private string ssname = "shareShot.png";
  16. //设置分享参数
  17. private string strDes = "";
  18. private string strImagtPath = "";
  19. private string strUrl = "";
  20. private string strUrlDes = "";
  21. private int contentType = 2;
  22. private string strImageUrl = "";
  23. private string strTitile = "";
  24. private string strTitleUrl = "";
  25. private string strSite = "";
  26. private string strSiteUrl = "";
  27. private string strComent = "";
  28. private string strMusicUrl = "";
  29. void Awake()
  30. {
  31. strImagtPath = Path.Combine(Application.temporaryCachePath, ssname);
  32. }
  33. //初始化sdk
  34. public void InitShareSDK()
  35. {
  36. ssdk = gameObject.GetComponent<ShareSDK>();
  37. if (ssdk == null)
  38. {
  39. ssdk = gameObject.AddComponent<ShareSDK>();
  40. }
  41. //设置回调函数
  42. ssdk.shareHandler = OnShareResultHandler;
  43. }
  44. //设置分享的参数
  45. public void InitShareContentPramas(string strdes,string strurl, string strimagtpath, string strurldes, int contenttype,string strimageurl,string strtile,string strtitleurl,string strsite,string strsiteurl,string strcoment,string strmusicurl)
  46. {
  47. strDes = strdes;
  48. strUrl = strurl;
  49. if(strimagtpath != "")
  50. {
  51. strImagtPath = strimagtpath;
  52. }
  53. strUrlDes = strurldes;
  54. contentType = contenttype;
  55. strImageUrl = strimageurl;
  56. strTitile = strtile;
  57. strTitleUrl = strtitleurl;
  58. strSite = strsite;
  59. strSiteUrl = strsiteurl;
  60. strComent = strcoment;
  61. strMusicUrl = strmusicurl;
  62. }
  63. //开始设置分享参数
  64. private ShareContent SetShareContent()
  65. {
  66. //分享的内容
  67. ShareContent content = new ShareContent();
  68. //文本分享 只有一个text
  69. //设置分享的文字 所有平台都需要这个字段 所有分享类型都需要
  70. //text分享
  71. if (contentType == 1)
  72. {
  73. if (strDes != "")
  74. {
  75. content.SetText(strDes);
  76. }
  77. //标题
  78. if (strTitile != "")
  79. {
  80. content.SetTitle(strTitile);
  81. }
  82. #if UNITY_ANDROID
  83. //标题链接
  84. if (strTitleUrl != "")
  85. {
  86. content.SetTitleUrl(strTitleUrl);
  87. }
  88. //QQ空间文本
  89. if (strSite != "")
  90. {
  91. content.SetSite(strSite);
  92. }
  93. if (strSiteUrl != "")
  94. {
  95. content.SetSiteUrl(strSiteUrl);
  96. }
  97. #endif
  98. }
  99. else
  100. {
  101. //图片分享 webpage分享
  102. if (strDes != "")
  103. {
  104. content.SetText(strDes);
  105. }
  106. //网络图片路径
  107. if (strImageUrl != "")
  108. {
  109. content.SetImageUrl(strImageUrl);
  110. }
  111. else
  112. {
  113. content.SetImagePath(strImagtPath); //本地图片路径
  114. }
  115. //标题
  116. if (strTitile != "")
  117. {
  118. content.SetTitle(strTitile);
  119. }
  120. //Android Only
  121. #if UNITY_ANDROID
  122. //标题链接
  123. if (strTitleUrl != "")
  124. {
  125. content.SetTitleUrl(strTitleUrl);
  126. }
  127. //QQ空间文本
  128. if (strSite != "")
  129. {
  130. content.SetSite(strSite);
  131. }
  132. if (strSiteUrl != "")
  133. {
  134. content.SetSiteUrl(strSiteUrl);
  135. }
  136. #elif UNITY_IPHONE
  137. //分享的网站描述
  138. if (strUrlDes != "")
  139. {
  140. content.SetUrlDescription(strUrlDes);
  141. }
  142. #endif
  143. //网页链接
  144. if (strUrl != "")
  145. {
  146. content.SetUrl(strUrl);
  147. }
  148. //描述
  149. if (strComent != "")
  150. {
  151. content.SetComment(strComent);
  152. }
  153. //音乐链接
  154. if (strMusicUrl != "")
  155. {
  156. content.SetMusicUrl(strMusicUrl);
  157. }
  158. }
  159. //设定分享内容的主要类型,放在最后一步
  160. content.SetShareType(contentType);
  161. return content;
  162. }
  163. //启动分享 通过平台ID
  164. public void ShareSDKByPlantForm(int plantform, LuaFunction f1)
  165. {
  166. PlatformType nowplantform = PlatformType.WeChatMoments;
  167. ShareContent content = SetShareContent();
  168. luaFun = f1;
  169. if (plantform == 23)
  170. {
  171. nowplantform = PlatformType.WeChatMoments;
  172. }
  173. else if (plantform == 22)
  174. {
  175. nowplantform = PlatformType.WeChat;
  176. }
  177. else if (plantform == 10)
  178. {
  179. nowplantform = PlatformType.Facebook;
  180. }
  181. else if (plantform == 1)
  182. {
  183. nowplantform = PlatformType.SinaWeibo;
  184. }
  185. else if (plantform == 24)
  186. {
  187. nowplantform = PlatformType.QQ;
  188. }
  189. else if (plantform == 6)
  190. {
  191. nowplantform = PlatformType.QZone;
  192. }
  193. ssdk.ShareContent(nowplantform, content);
  194. }
  195. //分享的结果回调函数
  196. private void OnShareResultHandler(int reqID, ResponseState state, PlatformType type, Hashtable result)
  197. {
  198. int stateNow = 1;
  199. if (state == ResponseState.Success)
  200. {
  201. print("share result :");
  202. print(MiniJSON.jsonEncode(result));
  203. stateNow = 1;
  204. }
  205. else if (state == ResponseState.Fail)
  206. {
  207. print("fail! throwable stack = " + result["stack"] + "; error msg = " + result["msg"]);
  208. stateNow = 2;
  209. }
  210. else if (state == ResponseState.Cancel)
  211. {
  212. print("cancel !");
  213. stateNow = 3;
  214. }
  215. Debug.Log("分享的结果回调函数xxxxxxxxxxxxxxxxxxxxxx" + state +"-------"+ stateNow);
  216. luaFun.Call(stateNow);
  217. }
  218. //根据不同包 需要不同的分型key 值
  219. public void SetPlantFormParams(string ssdkID, string ssdkKey, string weichatID, string weichatKey,string qqID, string qqKey, string sinaID, string sinaKey, string facebookID, string facebookKey)
  220. {
  221. #if UNITY_ANDROID
  222. //设置 平台的id
  223. ssdk.appKey = ssdkID;
  224. ssdk.appSecret = ssdkKey;
  225. //微信
  226. ssdk.devInfo.wechat.AppId = weichatID;
  227. ssdk.devInfo.wechat.AppSecret = weichatKey;
  228. ssdk.devInfo.wechatMoments.AppId = weichatID;
  229. ssdk.devInfo.wechatMoments.AppSecret = weichatKey;
  230. //QQ
  231. ssdk.devInfo.qq.AppId = qqID;
  232. ssdk.devInfo.qq.AppKey = qqKey;
  233. ssdk.devInfo.qzone.AppId = qqID;
  234. ssdk.devInfo.qzone.AppKey = qqKey;
  235. //Sina
  236. ssdk.devInfo.sinaweibo.AppKey = sinaID;
  237. ssdk.devInfo.sinaweibo.AppSecret = sinaKey;
  238. //facebook
  239. ssdk.devInfo.facebook.ConsumerKey = facebookID;
  240. ssdk.devInfo.facebook.ConsumerSecret = facebookKey;
  241. #elif UNITY_IPHONE
  242. //设置 平台的id
  243. ssdk.appKey = ssdkID;
  244. ssdk.appSecret = ssdkKey;
  245. //微信
  246. ssdk.devInfo.wechat.app_id = weichatID;
  247. ssdk.devInfo.wechat.app_secret = weichatKey;
  248. ssdk.devInfo.wechatMoments.app_id = weichatID;
  249. ssdk.devInfo.wechatMoments.app_secret = weichatKey;
  250. //QQ
  251. ssdk.devInfo.qq.app_id = qqID;
  252. ssdk.devInfo.qq.app_key = qqKey;
  253. ssdk.devInfo.qzone.app_id = qqID;
  254. ssdk.devInfo.qzone.app_key = qqKey;
  255. //Sina
  256. ssdk.devInfo.sinaweibo.app_key = sinaID;
  257. ssdk.devInfo.sinaweibo.app_secret = sinaKey;
  258. //facebook
  259. ssdk.devInfo.facebook.api_key = facebookID;
  260. ssdk.devInfo.facebook.app_secret = facebookKey;
  261. #endif
  262. //设置好参数后再初始化SDK
  263. ssdk.InitShareSDk();
  264. }
  265. }

 

 

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/我家自动化/article/detail/235817
推荐阅读
相关标签
  

闽ICP备14008679号