public class DeepLinkListener MonoBehaviour DllImport __Internal priva

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
public class DeepLinkListener : MonoBehaviour
{
[DllImport("__Internal")]
private static extern void DeepLinkReceiverIsAlive();
[DllImport("__Internal")]
private static extern string GetDeepLinkURL();
public bool dontDestroyOnLoad = true;
public static DeepLinkListener instanse;
private bool isDeferredAppLinkFetched = false;
void Start()
{
if (instanse != null)
{
Destroy(gameObject);
}
else
{
instanse = this;
DontDestroyOnLoad(gameObject);
#if UNITY_EDITOR
return;
#endif
DeepLinkReceiverIsAlive(); // Let the App Controller know it's ok to call URLOpened now.
}
}
private void Update()
{
if (!isDeferredAppLinkFetched)
{
if (FB.IsInitialized)
{
//https://developers.facebook.com/docs/unity/reference/current/FB.Mobile.FetchDeferredAppLinkData/
FB.Mobile.FetchDeferredAppLinkData(DeepLinkCallback);
isDeferredAppLinkFetched = true;
}
}
}
private void OnApplicationFocus(bool focus)
{
#if UNITY_EDITOR
return;
#endif
if(focus)
{
var lastUrl = GetDeepLinkURL();
if (lastUrl != String.Empty)
{
Logger.Debug("DEEPLINK: " + lastUrl);
}
}
}
public void URLOpened(string url)
{
Logger.Debug("App opened by link:" + url);
SharedProperties.SetDeepLinkOpened(url);
var eventParams = url.Length > 0 ? SKDeepLinkParser.ParseUrl(url) : null;
if (eventParams != null)
{
AppMetrica.Instance.ReportEvent(MetricaHelper.appOpenedByLink, eventParams);
}
else
{
AppMetrica.Instance.ReportEvent(MetricaHelper.appOpenedByLink);
}
}
void DeepLinkCallback(IAppLinkResult result)
{
var url = result.Url;
if (!string.IsNullOrEmpty(url))
{
SharedProperties.SetDeepLinkOpened(url);
var eventParams = url.Length > 0 ? SKDeepLinkParser.ParseUrl(url) : null;
if (eventParams != null)
{
AppMetrica.Instance.ReportEvent(MetricaHelper.appOpenedByDeferredLink, eventParams);
}
else
{
AppMetrica.Instance.ReportEvent(MetricaHelper.appOpenedByDeferredLink);
}
}
}
}