iOSImpl.cs 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213
  1. using System;
  2. using UnityEngine;
  3. using System.Collections;
  4. using System.Collections.Generic;
  5. using System.Runtime.InteropServices;
  6. namespace cn.sharesdk.unity3d
  7. {
  8. #if UNITY_IPHONE
  9. public class iOSImpl : ShareSDKImpl
  10. {
  11. [DllImport("__Internal")]
  12. private static extern void __iosShareSDKRegisterAppAndSetPltformsConfig (string appKey, string configInfo);
  13. [DllImport("__Internal")]
  14. private static extern void __iosShareSDKAuthorize (int reqID, int platType, string observer);
  15. [DllImport("__Internal")]
  16. private static extern void __iosShareSDKCancelAuthorize (int platType);
  17. [DllImport("__Internal")]
  18. private static extern bool __iosShareSDKHasAuthorized (int platType);
  19. [DllImport("__Internal")]
  20. private static extern void __iosShareSDKGetUserInfo (int reqID, int platType, string observer);
  21. [DllImport("__Internal")]
  22. private static extern void __iosShareSDKShare (int reqID, int platType, string content, string observer);
  23. [DllImport("__Internal")]
  24. private static extern void __iosShareSDKOneKeyShare (int reqID, string platTypes, string content, string observer);
  25. [DllImport("__Internal")]
  26. private static extern void __iosShareSDKShowShareMenu (int reqID, string platTypes, string content, int x, int y, string observer);
  27. [DllImport("__Internal")]
  28. private static extern void __iosShareSDKShowShareView (int reqID, int platType, string content, string observer);
  29. [DllImport("__Internal")]
  30. private static extern void __iosShareSDKGetFriendsList (int reqID, int platType,int count, int page, string observer);
  31. [DllImport("__Internal")]
  32. private static extern void __iosShareSDKFollowFriend (int reqID, int platform,string account, string observer);
  33. [DllImport("__Internal")]
  34. private static extern string __iosShareSDKGetCredential (int platType);
  35. [DllImport("__Internal")]
  36. private static extern bool __iosShareSDKIsClientInstalled (int platType);
  37. [DllImport("__Internal")]
  38. private static extern void __iosShareSDKShareWithContentName (int reqID, int platform, string contentName, string customFields, string observer);
  39. [DllImport("__Internal")]
  40. private static extern void __iosShareSDKShowShareMenuWithContentName (int reqID, string contentName, string customFields, string platTypes, int x, int y, string observer);
  41. [DllImport("__Internal")]
  42. private static extern void __iosShareSDKShowShareViewWithContentName (int reqID, int platform, string contentName, string customFields, string observer);
  43. private string _callbackObjectName = "Main Camera";
  44. private string _appKey;
  45. public iOSImpl (GameObject go)
  46. {
  47. Debug.Log("iOSUtils ===>>> iOSUtils" );
  48. try{
  49. _callbackObjectName = go.name;
  50. } catch(Exception e) {
  51. Console.WriteLine("{0} Exception caught.", e);
  52. }
  53. }
  54. public override void InitSDK (String appKey)
  55. {
  56. _appKey = appKey;
  57. }
  58. public override void InitSDK (String appKey,String appSecret)
  59. {
  60. _appKey = appKey;
  61. }
  62. public override void SetPlatformConfig (Hashtable configs)
  63. {
  64. String json = ShareSDKMiniJSON.jsonEncode(configs);
  65. __iosShareSDKRegisterAppAndSetPltformsConfig (_appKey, json);
  66. }
  67. public override void Authorize(int reqID, PlatformType platform)
  68. {
  69. __iosShareSDKAuthorize (reqID, (int)platform, _callbackObjectName);
  70. }
  71. public override void CancelAuthorize (PlatformType platform)
  72. {
  73. __iosShareSDKCancelAuthorize ((int)platform);
  74. }
  75. public override bool IsAuthorized (PlatformType platform)
  76. {
  77. return __iosShareSDKHasAuthorized ((int)platform);
  78. }
  79. public override bool IsClientValid (PlatformType platform)
  80. {
  81. return __iosShareSDKIsClientInstalled ((int)platform);
  82. }
  83. public override void GetUserInfo (int reqID, PlatformType platform)
  84. {
  85. __iosShareSDKGetUserInfo (reqID, (int)platform, _callbackObjectName);
  86. }
  87. public override void ShareContent (int reqID, PlatformType platform, ShareContent content)
  88. {
  89. __iosShareSDKShare (reqID, (int)platform, content.GetShareParamsStr(), _callbackObjectName);
  90. }
  91. public override void ShareContent (int reqID, PlatformType[] platforms, ShareContent content)
  92. {
  93. string platTypesStr = null;
  94. if (platforms != null)
  95. {
  96. List<int> platTypesArr = new List<int>();
  97. foreach (PlatformType type in platforms)
  98. {
  99. platTypesArr.Add((int)type);
  100. }
  101. platTypesStr = ShareSDKMiniJSON.jsonEncode(platTypesArr.ToArray());
  102. }
  103. __iosShareSDKOneKeyShare (reqID, platTypesStr, content.GetShareParamsStr(), _callbackObjectName);
  104. }
  105. public override void ShowPlatformList (int reqID, PlatformType[] platforms, ShareContent content, int x, int y)
  106. {
  107. string platTypesStr = null;
  108. if (platforms != null)
  109. {
  110. List<int> platTypesArr = new List<int>();
  111. foreach (PlatformType type in platforms)
  112. {
  113. platTypesArr.Add((int)type);
  114. }
  115. platTypesStr = ShareSDKMiniJSON.jsonEncode(platTypesArr.ToArray());
  116. }
  117. __iosShareSDKShowShareMenu (reqID, platTypesStr, content.GetShareParamsStr(), x, y, _callbackObjectName);
  118. }
  119. public override void ShowShareContentEditor (int reqID, PlatformType platform, ShareContent content)
  120. {
  121. __iosShareSDKShowShareView (reqID, (int)platform, content.GetShareParamsStr(), _callbackObjectName);
  122. }
  123. public override void ShareWithContentName (int reqId, PlatformType platform, string contentName, Hashtable customFields)
  124. {
  125. String customFieldsStr = ShareSDKMiniJSON.jsonEncode(customFields);
  126. __iosShareSDKShareWithContentName (reqId, (int)platform, contentName, customFieldsStr, _callbackObjectName);
  127. }
  128. public override void ShowPlatformListWithContentName (int reqId, string contentName, Hashtable customFields, PlatformType[] platforms, int x, int y)
  129. {
  130. String customFieldsStr = ShareSDKMiniJSON.jsonEncode(customFields);
  131. string platTypesStr = null;
  132. if (platforms != null)
  133. {
  134. List<int> platTypesArr = new List<int>();
  135. foreach (PlatformType type in platforms)
  136. {
  137. platTypesArr.Add((int)type);
  138. }
  139. platTypesStr = ShareSDKMiniJSON.jsonEncode(platTypesArr.ToArray());
  140. }
  141. __iosShareSDKShowShareMenuWithContentName (reqId, contentName, customFieldsStr, platTypesStr, x, y, _callbackObjectName);
  142. }
  143. public override void ShowShareContentEditorWithContentName (int reqId, PlatformType platform, string contentName, Hashtable customFields)
  144. {
  145. String customFieldsStr = ShareSDKMiniJSON.jsonEncode(customFields);
  146. __iosShareSDKShowShareViewWithContentName (reqId, (int)platform, contentName, customFieldsStr, _callbackObjectName);
  147. }
  148. public override void GetFriendList (int reqID, PlatformType platform, int count, int page)
  149. {
  150. __iosShareSDKGetFriendsList (reqID, (int)platform, count, page, _callbackObjectName);
  151. }
  152. public override void AddFriend (int reqID, PlatformType platform, String account)
  153. {
  154. __iosShareSDKFollowFriend (reqID, (int)platform, account, _callbackObjectName);
  155. }
  156. public override Hashtable GetAuthInfo (PlatformType platform)
  157. {
  158. //need modify,
  159. string credStr = __iosShareSDKGetCredential((int)platform);
  160. Hashtable authInfo = (Hashtable)ShareSDKMiniJSON.jsonDecode (credStr);
  161. return authInfo;
  162. }
  163. public override void DisableSSO (Boolean open)
  164. {
  165. // no this interface on iOS
  166. Console.WriteLine ("#waring : no this interface on iOS");
  167. }
  168. }
  169. #endif
  170. }