Hydrogen Framework  1.3.1
 All Classes Namespaces Functions Variables Enumerations Enumerator Properties Events
hTestFlight.cs
1 #region Copyright Notice & License Information
2 //
3 // hInput.cs
4 //
5 // Author:
6 // Matthew Davey <matthew.davey@dotbunny.com>
7 //
8 // Copyright (c) 2013 dotBunny Inc. (http://www.dotbunny.com)
9 //
10 // Permission is hereby granted, free of charge, to any person obtaining a copy
11 // of this software and associated documentation files (the "Software"), to deal
12 // in the Software without restriction, including without limitation the rights
13 // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
14 // copies of the Software, and to permit persons to whom the Software is
15 // furnished to do so, subject to the following conditions:
16 //
17 // The above copyright notice and this permission notice shall be included in
18 // all copies or substantial portions of the Software.
19 //
20 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
21 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
22 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
23 // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
24 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
25 // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
26 // THE SOFTWARE.
27 #endregion
28 
29 using System.Collections;
30 using UnityEngine;
31 
32 /// <summary>
33 /// A drop in implementation of the Hydrogen.Plugins.TestFlight manager. It implements advanced features included with
34 /// TestFlight allowing for proper session tracking and reporting.
35 /// </summary>
36 [AddComponentMenu ("Hydrogen/Singletons/TestFlight")]
37 public sealed class hTestFlight : MonoBehaviour
38 {
39  /// <summary>
40  /// Should this TestFlight manager survive scene switches.
41  /// </summary>
42  public bool Persistent = true;
43  /// <summary>
44  /// The TestFlight token for Android.
45  /// </summary>
46  public string TokenAndroid = "";
47  /// <summary>
48  /// The TestFlight token iOS.
49  /// </summary>
50  public string TokenIOS = "";
51  /// <summary>
52  /// Internal fail safe to maintain instance across threads.
53  /// </summary>
54  /// <remarks>
55  /// Multithreaded Safe Singleton Pattern.
56  /// </remarks>
57  /// <description>
58  /// http://msdn.microsoft.com/en-us/library/ms998558.aspx
59  /// </description>
60  static readonly System.Object _syncRoot = new System.Object ();
61  /// <summary>
62  /// Internal reference to the static instance of the TestFlight interface.
63  /// </summary>
64  static volatile hTestFlight _staticInstance;
65 
66  /// <summary>
67  /// Gets the TestFlight interface instance.
68  /// </summary>
69  /// <value>
70  /// The TestFlight interface
71  /// </value>
72  public static hTestFlight Instance {
73  get {
74  if (_staticInstance == null) {
75  lock (_syncRoot) {
76  _staticInstance = FindObjectOfType (typeof(hTestFlight)) as hTestFlight;
77 
78  // If we don't have it, lets make it!
79  if (_staticInstance == null) {
80 
81  var go = GameObject.Find (Hydrogen.Components.DefaultSingletonName) ??
82  new GameObject (Hydrogen.Components.DefaultSingletonName);
83 
84  go.AddComponent<hTestFlight> ();
85  _staticInstance = go.GetComponent<hTestFlight> ();
86  }
87  }
88  }
89  return _staticInstance;
90  }
91  }
92 
93  /// <summary>
94  /// Does a TestFlight manager instance exist?
95  /// </summary>
96  public static bool Exists ()
97  {
98  return _staticInstance != null;
99  }
100 
101  /// <summary>
102  /// Adds an entry into the Key-Value store for this TestFlight session.
103  /// </summary>
104  /// <param name="key">The Key.</param>
105  /// <param name="data">The Value.</param>
106 
107  public void AddCustomEnvironmentInformation (string key, string data)
108  {
109  // Make sure that we are infact flying and there is a session present, if not we'll dump out a
110  // message to console if on a platform where this should have worked.
111  if (!Hydrogen.Plugins.TestFlight.Flying || !Hydrogen.Plugins.TestFlight.Session) {
112 
113  #if (UNITY_IPHONE || UNITY_IOS || UNITY_ANDROID) && !UNITY_EDITOR
114  Debug.Log ("Unable to send information, TestFlight is not in flight.");
115  #endif
116 
117  return;
118  }
119 
120  // Notice that the data/key is swapped here. Not to sure why TestFlight decided on this format,
121  // it really seems backwards.
122  Hydrogen.Plugins.TestFlight.AddCustomEnvironmentInformation (data, key);
123  }
124 
125  /// <summary>
126  /// Send a message to TestFlight to appear in it's console.
127  /// </summary>
128  /// <param name="message">The Message.</param>
129  public void Log (string message)
130  {
131  // Make sure that we are infact flying and there is a session present, if not we'll dump out a
132  // message to console if on a platform where this should have worked.
133  if (!Hydrogen.Plugins.TestFlight.Flying || !Hydrogen.Plugins.TestFlight.Session) {
134  #if (UNITY_IPHONE || UNITY_IOS || UNITY_ANDROID) && !UNITY_EDITOR
135  Debug.Log ("Unable to send log data, TestFlight is not in flight.");
136  #endif
137  return;
138  }
139 
140  Hydrogen.Plugins.TestFlight.Log (message);
141  }
142 
143  /// <summary>
144  /// Send a message to TestFlight asynchronously to appear in it's console.
145  /// </summary>
146  /// <param name="message">The Message.</param>
147  public void LogAsync (string message)
148  {
149  // Make sure that we are infact flying and there is a session present, if not we'll dump out a
150  // message to console if on a platform where this should have worked.
151  if (!Hydrogen.Plugins.TestFlight.Flying || !Hydrogen.Plugins.TestFlight.Session) {
152  #if (UNITY_IPHONE || UNITY_IOS || UNITY_ANDROID) && !UNITY_EDITOR
153  Debug.Log ("Unable to send log data, TestFlight is not in flight.");
154  #endif
155  return;
156  }
157 
158  Hydrogen.Plugins.TestFlight.LogAsync (message);
159  }
160 
161  /// <summary>
162  /// Report to TestFlight that the session has passed a Checkpoint.
163  /// </summary>
164  /// <param name="checkpoint">The Checkpoint name.</param>
165  public void PassCheckpoint (string checkpoint)
166  {
167  // Make sure that we are infact flying and there is a session present, if not we'll dump out a
168  // message to console if on a platform where this should have worked.
169  if (!Hydrogen.Plugins.TestFlight.Flying || !Hydrogen.Plugins.TestFlight.Session) {
170  #if (UNITY_IPHONE || UNITY_IOS || UNITY_ANDROID) && !UNITY_EDITOR
171  Debug.Log ("Unable to send checkpoint data, TestFlight is not in flight.");
172  #endif
173  return;
174  }
175 
176  Hydrogen.Plugins.TestFlight.PassCheckpoint (checkpoint);
177  }
178 
179  /// <summary>
180  /// Submits a feedback message for the App to TestFlight.
181  /// </summary>
182  /// <param name="message">The feedback message.</param>
183  public void SubmitFeedback (string message)
184  {
185  // Make sure that we are infact flying and there is a session present, if not we'll dump out a
186  // message to console if on a platform where this should have worked.
187  if (!Hydrogen.Plugins.TestFlight.Flying || !Hydrogen.Plugins.TestFlight.Session) {
188  #if (UNITY_IPHONE || UNITY_IOS || UNITY_ANDROID) && !UNITY_EDITOR
189  Debug.Log ("Unable to submit feedback, TestFlight is not in flight.");
190  #endif
191  return;
192  }
193 
194  Hydrogen.Plugins.TestFlight.SubmitFeedback (message);
195  }
196 
197  /// <summary>
198  /// Raised when your application is paused, as a more accurate depiction of Session times.
199  /// </summary>
200  /// <remarks>
201  /// This was meant originally as a fix for Android, but we've carried it over to iOS and
202  /// switched everything to manual for better integration with Unity
203  /// </remarks>
204  static void OnApplicationPause ()
205  {
206  if (!Hydrogen.Plugins.TestFlight.Session)
207  Hydrogen.Plugins.TestFlight.StartSession ();
208  else
209  Hydrogen.Plugins.TestFlight.EndSession ();
210  }
211 
212  /// <summary>
213  /// Raised when your application is quit, ending the session for you via code.
214  /// </summary>
215  static void OnApplicationQuit ()
216  {
217  Hydrogen.Plugins.TestFlight.EndSession ();
218  }
219 
220  /// <summary>
221  /// Unity's Awake Event
222  /// </summary>
223  void Awake ()
224  {
225  // Should this gameObject be kept around :) I think so.
226  if (Persistent)
227  DontDestroyOnLoad (gameObject);
228 
229  // Let's get this party started, but in a somewhat safe manner
230  StartCoroutine (Initialize ());
231  }
232 
233  /// <summary>
234  /// Initialize our TestFlight plugin with the appropriate settings.
235  /// </summary>
236  IEnumerator Initialize ()
237  {
238  if (!Hydrogen.Plugins.TestFlight.Flying) {
239  // Depending on the platform there are some things that need to be handled before we can
240  // take off and start submitting data
241  Hydrogen.Plugins.TestFlight.Initialize ();
242 
243  // Issue the appropriate "takeoff" token
244  #if (UNITY_IPHONE || UNITY_IOS) && !UNITY_EDITOR
245  Hydrogen.Plugins.TestFlight.TakeOff(TokenIOS);
246  #elif UNITY_ANDROID && !UNITY_EDITOR
247  Hydrogen.Plugins.TestFlight.TakeOff(TokenAndroid);
248  #endif
249  }
250 
251  // Wait for the end of the frame for kicks
252  yield return new WaitForEndOfFrame ();
253 
254  if (!Hydrogen.Plugins.TestFlight.Session) {
255  // Start up our session captain!
256  Hydrogen.Plugins.TestFlight.StartSession ();
257  }
258  }
259 }
void LogAsync(string message)
Send a message to TestFlight asynchronously to appear in it&#39;s console.
Definition: hTestFlight.cs:147
void SubmitFeedback(string message)
Submits a feedback message for the App to TestFlight.
Definition: hTestFlight.cs:183
string TokenAndroid
The TestFlight token for Android.
Definition: hTestFlight.cs:46
static bool Exists()
Does a TestFlight manager instance exist?
Definition: hTestFlight.cs:96
bool Persistent
Should this TestFlight manager survive scene switches.
Definition: hTestFlight.cs:42
void AddCustomEnvironmentInformation(string key, string data)
Adds an entry into the Key-Value store for this TestFlight session.
Definition: hTestFlight.cs:107
void Log(string message)
Send a message to TestFlight to appear in it&#39;s console.
Definition: hTestFlight.cs:129
string TokenIOS
The TestFlight token iOS.
Definition: hTestFlight.cs:50
A drop in implementation of the Hydrogen.Plugins.TestFlight manager. It implements advanced features ...
Definition: hTestFlight.cs:37
static hTestFlight Instance
Gets the TestFlight interface instance.
Definition: hTestFlight.cs:72
void PassCheckpoint(string checkpoint)
Report to TestFlight that the session has passed a Checkpoint.
Definition: hTestFlight.cs:165