Application.cs 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209
  1. /*******************************************************************************
  2. Copyright © 2015-2022 PICO Technology Co., Ltd.All rights reserved.
  3. NOTICE:All information contained herein is, and remains the property of
  4. PICO Technology Co., Ltd. The intellectual and technical concepts
  5. contained herein are proprietary to PICO Technology Co., Ltd. and may be
  6. covered by patents, patents in process, and are protected by trade secret or
  7. copyright law. Dissemination of this information or reproduction of this
  8. material is strictly forbidden unless prior written permission is obtained from
  9. PICO Technology Co., Ltd.
  10. *******************************************************************************/
  11. using System;
  12. using Pico.Platform.Models;
  13. using UnityEngine;
  14. using SystemInfo = Pico.Platform.Models.SystemInfo;
  15. namespace Pico.Platform
  16. {
  17. /**
  18. * \ingroup Platform
  19. *
  20. * ApplicationService provides functions like launch other application,jump to store, get launch details.
  21. */
  22. public static class ApplicationService
  23. {
  24. /// <summary>
  25. /// Launches another app by app package name.
  26. /// @note If the user does not have that app installed, the user will be directed to the app's download page on the PICO Store.
  27. /// </summary>
  28. /// <param name="packageName">The package name of the to-be-launched app.</param>
  29. /// <param name="options">The options for launching the app. Pass `null` or leave this parameter empty.</param>
  30. /// <returns>If something goes wrong, a description message will be returned.</returns>
  31. public static Task<string> LaunchApp(string packageName, ApplicationOptions options = null)
  32. {
  33. if (!CoreService.Initialized)
  34. {
  35. Debug.LogError(CoreService.NotInitializedError);
  36. return null;
  37. }
  38. return new Task<string>(CLIB.ppf_Application_LaunchOtherApp(packageName, (IntPtr) options));
  39. }
  40. /// <summary>
  41. /// Launches another app by app ID.
  42. /// @note If the user does not have that app installed, the user will be directed to the app's download page on the PICO Store.
  43. /// </summary>
  44. /// <param name="appId">The ID of the to-be-launched app.</param>
  45. /// <param name="options">The options for launching the app. Pass `null` or leave this parameter empty.</param>
  46. /// <returns>If something goes wrong, a description message will be returned.</returns>
  47. public static Task<string> LaunchAppByAppId(string appId, ApplicationOptions options = null)
  48. {
  49. if (!CoreService.Initialized)
  50. {
  51. Debug.LogError(CoreService.NotInitializedError);
  52. return null;
  53. }
  54. return new Task<string>(CLIB.ppf_Application_LaunchOtherAppByAppID(appId, (IntPtr) options));
  55. }
  56. /// <summary>
  57. /// Launches the PICO Store app and go to the current app's details page.
  58. ///
  59. /// You can direct user to the PICO Store to upgrade the installed app by this
  60. /// method. To judge whether there is a new version in the PICO Store, you can call
  61. /// \ref GetVersion.
  62. ///
  63. /// @note
  64. /// * If the current app has never published in the PICO Store, the response error code is non-zero.
  65. /// * The current app will quit once the PICO Store app is launched.
  66. ///
  67. /// </summary>
  68. /// <returns>A string that describes the launch info.</returns>
  69. public static Task<string> LaunchStore()
  70. {
  71. if (!CoreService.Initialized)
  72. {
  73. Debug.LogError(CoreService.NotInitializedError);
  74. return null;
  75. }
  76. return new Task<string>(CLIB.ppf_Application_LaunchStore());
  77. }
  78. /// <summary>
  79. /// Gets the app's current version info and the latest version info.
  80. ///
  81. /// You can compare the current version info and the latest version info, and
  82. /// then decide whether to call \ref LaunchStore to direct users to the current app's details page to upgrade the app.
  83. /// </summary>
  84. /// <returns>The response will contain the latest version info in the PICO Store
  85. /// and the app's current version info.
  86. /// </returns>
  87. public static Task<ApplicationVersion> GetVersion()
  88. {
  89. if (!CoreService.Initialized)
  90. {
  91. Debug.LogError(CoreService.NotInitializedError);
  92. return null;
  93. }
  94. return new Task<ApplicationVersion>(CLIB.ppf_Application_GetVersion());
  95. }
  96. /// <summary>
  97. /// Gets the details about an app launch event.
  98. /// </summary>
  99. /// <returns>App launch details, including `LaunchResult` and `LaunchType`:
  100. /// * `LaunchResult`:
  101. /// * `0`: Unknown
  102. /// * `1`: Success
  103. /// * `2`: FailedRoomFull
  104. /// * `3`: FailedGameAlreadyStarted
  105. /// * `4`: FailedRoomNotFound
  106. /// * `5`: FailedUserDeclined
  107. /// * `6`: FailedOtherReason
  108. /// * `LaunchType`:
  109. /// * `0`: Unknown
  110. /// * `1`: Normal
  111. /// * `2`: Invite
  112. /// * `3`: Coordinated
  113. /// * `4`: Deeplink
  114. /// </returns>
  115. public static LaunchDetails GetLaunchDetails()
  116. {
  117. if (!CoreService.Initialized)
  118. {
  119. Debug.LogError(CoreService.NotInitializedError);
  120. return null;
  121. }
  122. return new LaunchDetails(CLIB.ppf_ApplicationLifecycle_GetLaunchDetails());
  123. }
  124. /// <summary>
  125. /// Gets the device's system information synchronously.
  126. /// </summary>
  127. /// <returns>A structure contains the device's system information, including the device's system version, language code,
  128. /// country/region code, product name, and more.</returns>
  129. public static SystemInfo GetSystemInfo()
  130. {
  131. if (!CoreService.Initialized)
  132. {
  133. Debug.LogError(CoreService.NotInitializedError);
  134. return null;
  135. }
  136. return new SystemInfo(CLIB.ppf_Application_GetSystemInfo());
  137. }
  138. /// <summary>
  139. /// Logs whether a user has been successfully directed to the desired destination via a deep link.
  140. /// </summary>
  141. /// <param name="trackId">The tracking ID of the app launch event.</param>
  142. /// <param name="result">The app launch result:
  143. /// * `0`: Unknown
  144. /// * `1`: Success
  145. /// * `2`: FailedRoomFull
  146. /// * `3`: FailedGameAlreadyStarted
  147. /// * `4`: FailedRoomNotFound
  148. /// * `5`: FailedUserDeclined
  149. /// * `6`: FailedOtherReason
  150. /// </param>
  151. public static void LogDeeplinkResult(string trackId, LaunchResult result)
  152. {
  153. CLIB.ppf_ApplicationLifecycle_LogDeeplinkResult(trackId, result);
  154. }
  155. /// <summary>
  156. /// When the launch intent is changed, you will receive this notification.
  157. /// Then you can call \ref GetLaunchDetails to retrieve the launch details.
  158. /// </summary>
  159. /// <param name="callback">The callback function.</param>
  160. public static void SetLaunchIntentChangedCallback(Message<string>.Handler callback)
  161. {
  162. Looper.RegisterNotifyHandler(MessageType.Notification_ApplicationLifecycle_LaunchIntentChanged, callback);
  163. }
  164. }
  165. public class ApplicationOptions
  166. {
  167. public ApplicationOptions()
  168. {
  169. Handle = CLIB.ppf_ApplicationOptions_Create();
  170. }
  171. public void SetDeeplinkMessage(string value)
  172. {
  173. CLIB.ppf_ApplicationOptions_SetDeeplinkMessage(Handle, value);
  174. }
  175. /// For passing to native C
  176. public static explicit operator IntPtr(ApplicationOptions options)
  177. {
  178. return options?.Handle ?? IntPtr.Zero;
  179. }
  180. ~ApplicationOptions()
  181. {
  182. CLIB.ppf_ApplicationOptions_Destroy(Handle);
  183. }
  184. readonly IntPtr Handle;
  185. }
  186. }