170 lines
5.4 KiB
C#
170 lines
5.4 KiB
C#
using System.Collections;
|
||
using UnityEngine;
|
||
using AppsFlyerSDK;
|
||
using System.Collections.Generic;
|
||
using FlowerPower;
|
||
using Unity.Advertisement.IosSupport;
|
||
using System;
|
||
using DG.Tweening;
|
||
|
||
namespace IgnoreOPS
|
||
{
|
||
|
||
|
||
internal class AppsFlyerObjectScript1 : MonoBehaviour, IAppsFlyerConversionData
|
||
{
|
||
public string appID = null;
|
||
public bool is_init = false;
|
||
|
||
public Coroutine m_Coroutine;
|
||
void Start()
|
||
{
|
||
AddListener();
|
||
AppsFlyer.setIsDebug(true);
|
||
#if UNITY_IOS && !UNITY_EDITOR
|
||
appID = "6745081004";
|
||
m_Coroutine = CrazyAsyKit.StartCoroutine(loopWaitInitAf());
|
||
|
||
#endif
|
||
|
||
|
||
#if UNITY_EDITOR
|
||
NetworkDispatcher.Instance.Dispatch(NetworkMsg.Login);
|
||
#endif
|
||
}
|
||
private void AddListener()
|
||
{
|
||
NetworkDispatcher.Instance.AddListener(NetworkMsg.NotNetwork, RequestLogin);
|
||
}
|
||
|
||
private void RemoveListener()
|
||
{
|
||
NetworkDispatcher.Instance.RemoveListener(NetworkMsg.NotNetwork, RequestLogin);
|
||
}
|
||
void RequestLogin(object obj = null)
|
||
{
|
||
if (GameHelper.IsConnect())
|
||
{
|
||
GameDispatcher.Instance.Dispatch(GameMsg.Network_reconnection);
|
||
}
|
||
|
||
CrazyAsyKit.StopCoroutine(m_Coroutine);
|
||
|
||
m_Coroutine = CrazyAsyKit.StartCoroutine(loopWaitInitAf());
|
||
}
|
||
|
||
void OnDestroy() {
|
||
RemoveListener();
|
||
}
|
||
|
||
public IEnumerator loopWaitInitAf()
|
||
{
|
||
// Debug.Log($"barry !GameHelper.IsConnect()==== {!GameHelper.IsConnect()}");
|
||
|
||
#if !FlowerPowerRelease
|
||
GameHelper.ShowTips($"is link network:{GameHelper.IsConnect()}");
|
||
#endif
|
||
if (!GameHelper.IsConnect())
|
||
{
|
||
Action action = () =>
|
||
{
|
||
DOVirtual.DelayedCall(0.5f, ()=>
|
||
{
|
||
// NetworkDispatcher.Instance.Dispatch(NetworkMsg.NotNetwork);
|
||
NetworkDispatcher.Instance.Dispatch(NetworkMsg.Login);
|
||
});
|
||
};
|
||
UICtrlDispatcher.Instance.Dispatch(UICtrlMsg.TipsViewUI_Open,action);
|
||
yield return null;
|
||
}
|
||
|
||
var reqData = new RespLoginFunnelData
|
||
{
|
||
type = "afSend",
|
||
payload = ""
|
||
};
|
||
NetworkKit.PostFunnelLogin(reqData);
|
||
|
||
float a = 0;
|
||
if (ATTrackingStatusBinding.GetAuthorizationTrackingStatus() ==
|
||
ATTrackingStatusBinding.AuthorizationTrackingStatus.NOT_DETERMINED)
|
||
{
|
||
ATTrackingStatusBinding.RequestAuthorizationTracking();
|
||
}
|
||
|
||
|
||
while ((ATTrackingStatusBinding.GetAuthorizationTrackingStatus() ==
|
||
ATTrackingStatusBinding.AuthorizationTrackingStatus.NOT_DETERMINED) && (a < 5.0f))
|
||
{
|
||
a += 0.5f;
|
||
yield return new WaitForSeconds(0.5f);
|
||
}
|
||
|
||
AppsFlyer.initSDK("MoPyHQ7ZLXpqouczgQkNdU", appID, this);
|
||
AppsFlyer.startSDK();
|
||
AppsFlyer.AFLog("8888888888888888888", ATTrackingStatusBinding.GetAuthorizationTrackingStatus().ToString());
|
||
//yield return new WaitForSeconds(0.5f);
|
||
|
||
}
|
||
|
||
public void onConversionDataSuccess(string conversionData)
|
||
{
|
||
if (is_init) return;
|
||
is_init = true;
|
||
AppsFlyer.AFLog("onConversionDataSuccess", conversionData);
|
||
Debug.Log("hunxiao0000000000000000000000-1");
|
||
var conversionDataDictionary = AppsFlyer.CallbackStringToDictionary(conversionData);
|
||
var json = SerializeUtil.ToJsonIndented(conversionDataDictionary);
|
||
// Debug.Log("hunxiao0000000000000000000000-2");
|
||
SuperApplication.Instance.attribution =
|
||
conversionDataDictionary.TryGetValue("af_status", out var afStatus)
|
||
? afStatus.ToString().ToLower()
|
||
: "organic";
|
||
|
||
// Debug.Log("hunxiao0000000000000000000000");
|
||
// if (GameHelper.IsConnect())
|
||
// {
|
||
NetworkDispatcher.Instance.Dispatch(NetworkMsg.Login);
|
||
// }
|
||
|
||
var reqData = new RespLoginFunnelData
|
||
{
|
||
type = "afRecv",
|
||
payload = "success"
|
||
};
|
||
NetworkKit.PostFunnelLogin(reqData);
|
||
}
|
||
|
||
public void onConversionDataFail(string error)
|
||
{
|
||
if (is_init) return;
|
||
is_init = true;
|
||
AppsFlyer.AFLog("onConversionDataFail", error);
|
||
Debug.Log("hunxiao0000000000000000000000-2");
|
||
// if (GameHelper.IsConnect())
|
||
// {
|
||
NetworkDispatcher.Instance.Dispatch(NetworkMsg.Login);
|
||
// }
|
||
|
||
var reqData = new RespLoginFunnelData
|
||
{
|
||
type = "afRecv",
|
||
payload = "fail"
|
||
};
|
||
NetworkKit.PostFunnelLogin(reqData);
|
||
}
|
||
|
||
public void onAppOpenAttribution(string attributionData)
|
||
{
|
||
AppsFlyer.AFLog("onAppOpenAttribution", attributionData);
|
||
Dictionary<string, object> attributionDataDictionary =
|
||
AppsFlyer.CallbackStringToDictionary(attributionData);
|
||
}
|
||
|
||
public void onAppOpenAttributionFailure(string error)
|
||
{
|
||
AppsFlyer.AFLog("onAppOpenAttributionFailure", error);
|
||
}
|
||
}
|
||
}
|