update: 新增 Notification 接口
parent
cd7074f490
commit
fa3ec5adef
|
|
@ -20,6 +20,10 @@ namespace Guru
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public bool IAPEnabled = true;
|
public bool IAPEnabled = true;
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
/// 自动申请推送授权信息
|
||||||
|
/// </summary>
|
||||||
|
public bool AutoNotificationPermission = true;
|
||||||
|
/// <summary>
|
||||||
/// 自动记录完成的关卡
|
/// 自动记录完成的关卡
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public bool AutoRecordFinishedLevels = true;
|
public bool AutoRecordFinishedLevels = true;
|
||||||
|
|
|
||||||
|
|
@ -1,14 +1,13 @@
|
||||||
|
|
||||||
|
|
||||||
namespace Guru
|
namespace Guru
|
||||||
{
|
{
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
using System;
|
using System;
|
||||||
|
using Guru.Notification;
|
||||||
|
|
||||||
public partial class GuruSDK
|
public partial class GuruSDK
|
||||||
{
|
{
|
||||||
|
private const float CONSENT_FLOW_TIMEOUT = 10; // Consent Flow 超时时间(秒)
|
||||||
private static AdsInitSpec _adInitSpec;
|
private static AdsInitSpec _adInitSpec;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|
@ -53,7 +52,7 @@ namespace Guru
|
||||||
if (userAllow)
|
if (userAllow)
|
||||||
{
|
{
|
||||||
#if UNITY_IOS
|
#if UNITY_IOS
|
||||||
CheckAttStatus();
|
Instance.CheckAttStatus();
|
||||||
#else
|
#else
|
||||||
StartAdService(spec);
|
StartAdService(spec);
|
||||||
#endif
|
#endif
|
||||||
|
|
@ -81,6 +80,8 @@ namespace Guru
|
||||||
|
|
||||||
private bool _hasConsentCalled = false;
|
private bool _hasConsentCalled = false;
|
||||||
private bool _adServiceHasStarted = false;
|
private bool _adServiceHasStarted = false;
|
||||||
|
private string _notiStatue = "";
|
||||||
|
private bool _hasNotiGranted = false;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 启动Consent流程
|
/// 启动Consent流程
|
||||||
|
|
@ -88,10 +89,12 @@ namespace Guru
|
||||||
/// </summary>
|
/// </summary>
|
||||||
private void StartConsentFlow()
|
private void StartConsentFlow()
|
||||||
{
|
{
|
||||||
|
LogI($"#4.5 --- StartConsentFlow ---");
|
||||||
|
|
||||||
float time = 1;
|
float time = 1;
|
||||||
if (!_adServiceHasStarted && _appServicesConfig != null)
|
if (!_adServiceHasStarted && _appServicesConfig != null)
|
||||||
{
|
{
|
||||||
time = _appServicesConfig.IsAdsCompliance() ? 10 : 1f; // 启动合规判定后, 延迟最多 10 秒后启动广告
|
time = _appServicesConfig.IsAdsCompliance() ? CONSENT_FLOW_TIMEOUT : 1f; // 启动合规判定后, 延迟最多 10 秒后启动广告
|
||||||
}
|
}
|
||||||
Delay(time, AdServiceHandler); // 广告延迟启动
|
Delay(time, AdServiceHandler); // 广告延迟启动
|
||||||
|
|
||||||
|
|
@ -130,7 +133,7 @@ namespace Guru
|
||||||
#if UNITY_IOS
|
#if UNITY_IOS
|
||||||
CheckAttStatus(); // [iOS] Consent 启动后检查 ATT 初始值
|
CheckAttStatus(); // [iOS] Consent 启动后检查 ATT 初始值
|
||||||
#elif UNITY_ANDROID
|
#elif UNITY_ANDROID
|
||||||
CheckPermission(); // [Android] Consent 回调后检查 Push 推送权限
|
CheckNotiPermission(); // Consent 回调后检查 Notification 权限
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// 内部处理后继逻辑
|
// 内部处理后继逻辑
|
||||||
|
|
@ -154,6 +157,8 @@ namespace Guru
|
||||||
StartAdService(_adInitSpec);
|
StartAdService(_adInitSpec);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region IOS ATT 广告授权流程
|
#region IOS ATT 广告授权流程
|
||||||
|
|
@ -167,7 +172,7 @@ namespace Guru
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 显示系统的 ATT 弹窗
|
/// 显示系统的 ATT 弹窗
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public static void RequestAttDialog()
|
public void RequestAttDialog()
|
||||||
{
|
{
|
||||||
LogI($"RequestATTDialog");
|
LogI($"RequestATTDialog");
|
||||||
ATTManager.RequestATTDailog(ReportAttStatus);
|
ATTManager.RequestATTDailog(ReportAttStatus);
|
||||||
|
|
@ -186,7 +191,7 @@ namespace Guru
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// iOS 平台检查 ATT 状态
|
/// iOS 平台检查 ATT 状态
|
||||||
/// </summary>
|
/// </summary>
|
||||||
private static void CheckAttStatus(bool autoReCall = false)
|
private void CheckAttStatus(bool autoReCall = false)
|
||||||
{
|
{
|
||||||
_autoReCallAtt = autoReCall;
|
_autoReCallAtt = autoReCall;
|
||||||
|
|
||||||
|
|
@ -194,7 +199,7 @@ namespace Guru
|
||||||
Delay(1, () => ATTManager.CheckStatus(ReportAttStatus));
|
Delay(1, () => ATTManager.CheckStatus(ReportAttStatus));
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void ReportAttStatus(string status)
|
private void ReportAttStatus(string status)
|
||||||
{
|
{
|
||||||
LogI($"{Tag} --- Get Att status:{status} att Type:{_attType} recall:{_autoReCallAtt}");
|
LogI($"{Tag} --- Get Att status:{status} att Type:{_attType} recall:{_autoReCallAtt}");
|
||||||
SetUserProperty(Analytics.ParameterATTStatus, status); // 当前的状态
|
SetUserProperty(Analytics.ParameterATTStatus, status); // 当前的状态
|
||||||
|
|
@ -221,43 +226,64 @@ namespace Guru
|
||||||
// ATT 状态已授权
|
// ATT 状态已授权
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
CheckNotiPermission(); // Consent 回调后检查 Notification 权限
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region Android 13 PushNotification Permission
|
#region Notification Permission Check
|
||||||
|
|
||||||
private const string PERMISSION_POST_NOTIFICATION = "android.permission.POST_NOTIFICATIONS";
|
/// <summary>
|
||||||
|
/// 初始化 Noti Service
|
||||||
private void CheckPermission()
|
/// </summary>
|
||||||
|
private void InitNotiPermission()
|
||||||
{
|
{
|
||||||
float delay = 1;
|
bool hasNotiGranted = false;
|
||||||
UnityEngine.Debug.Log($"---- Check PushPermission ---");
|
_notiStatue = "no_determined";
|
||||||
#if UNITY_ANDROID
|
NotificationService.Initialize(); // 初始化 Noti 服务
|
||||||
// 如果已经请求过权限的话, 则不做动作
|
SetNotiPerm(NotificationService.GetStatus());
|
||||||
if (UnityEngine.Android.Permission.HasUserAuthorizedPermission(PERMISSION_POST_NOTIFICATION))
|
|
||||||
{
|
|
||||||
UnityEngine.Debug.Log($"--- PushPermission has passed ---");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
Invoke(nameof(RequestNotification), delay);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 请求Notification
|
/// 检查 Noti 状态
|
||||||
/// </summary>
|
/// </summary>
|
||||||
private void RequestNotification()
|
private void CheckNotiPermission()
|
||||||
{
|
{
|
||||||
#if UNITY_ANDROID
|
var status = NotificationService.GetStatus();
|
||||||
UnityEngine.Debug.Log("--- Target 33 Request Notification ---");
|
|
||||||
// Android直接申请授权
|
// 如果未启用自动 Noti 授权,则直接上报状态
|
||||||
if (!UnityEngine.Android.Permission.HasUserAuthorizedPermission(PERMISSION_POST_NOTIFICATION))
|
if (!_initConfig.AutoNotificationPermission)
|
||||||
{
|
{
|
||||||
UnityEngine.Android.Permission.RequestUserPermission(PERMISSION_POST_NOTIFICATION);
|
UnityEngine.Debug.LogWarning($"[SDK] ---- AutoNotificationPermission is OFF, Project should request permission own.");
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
|
bool isGranted = NotificationService.IsPermissionGranted();
|
||||||
|
UnityEngine.Debug.Log($"[SDK] ---- Check Noti Permission: {isGranted}");
|
||||||
|
if (isGranted)
|
||||||
|
{
|
||||||
|
SetNotiPerm(status);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
RequestNotificationPermission(); // 请求授权
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 请求推送授权
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="callback"></param>
|
||||||
|
public static void RequestNotificationPermission(Action<string> callback = null)
|
||||||
|
{
|
||||||
|
UnityEngine.Debug.Log($"[SDK] ---- RequestNotificationPermission");
|
||||||
|
NotificationService.RequestPermission(status =>
|
||||||
|
{
|
||||||
|
UnityEngine.Debug.Log($"[SDK] ---- Get Notification Permission:{status}");
|
||||||
|
SetNotiPerm(status);
|
||||||
|
callback?.Invoke(status);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,6 @@
|
||||||
|
using System;
|
||||||
|
using UnityEngine;
|
||||||
|
|
||||||
namespace Guru
|
namespace Guru
|
||||||
{
|
{
|
||||||
public partial class GuruSDK
|
public partial class GuruSDK
|
||||||
|
|
@ -41,5 +44,48 @@ namespace Guru
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
|
|
||||||
|
#region Android System
|
||||||
|
|
||||||
|
#if UNITY_ANDROID
|
||||||
|
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 获取 AndroidSDK 的系统版本号
|
||||||
|
/// </summary>
|
||||||
|
/// <returns></returns>
|
||||||
|
public static int GetAndroidSystemVersion()
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
// sdkInt 是 Android SDK 的整数版本号,例如 Android 10 对应 29。
|
||||||
|
// release 是 Android 版本的字符串表示,例如 "10"。
|
||||||
|
using (AndroidJavaClass jc = new AndroidJavaClass("android.os.Build$VERSION"))
|
||||||
|
{
|
||||||
|
int sdkInt = jc.GetStatic<int>("SDK_INT");
|
||||||
|
Debug.LogWarning($"[SDK] --- Android SDK Version:{sdkInt}");
|
||||||
|
return sdkInt;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
Debug.LogError(ex);
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -277,6 +277,8 @@ namespace Guru
|
||||||
// -------- Init Analytics ---------
|
// -------- Init Analytics ---------
|
||||||
InitUserProperties();
|
InitUserProperties();
|
||||||
SetSDKEventPriority();
|
SetSDKEventPriority();
|
||||||
|
// -------- Init Noti -----------
|
||||||
|
InitNotiPermission();
|
||||||
|
|
||||||
bool useKeywords = false;
|
bool useKeywords = false;
|
||||||
bool useIAP = _initConfig.IAPEnabled;
|
bool useIAP = _initConfig.IAPEnabled;
|
||||||
|
|
@ -413,7 +415,6 @@ namespace Guru
|
||||||
// StartConsentFlow();
|
// StartConsentFlow();
|
||||||
Try(() =>
|
Try(() =>
|
||||||
{
|
{
|
||||||
LogI($"#4.5 --- StartConsentFlow ---");
|
|
||||||
StartConsentFlow();
|
StartConsentFlow();
|
||||||
}, ex =>
|
}, ex =>
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
{
|
{
|
||||||
"name": "com.guru.unity.sdk",
|
"name": "com.guru.unity.sdk",
|
||||||
"displayName": "Guru SDK",
|
"displayName": "Guru SDK",
|
||||||
"version": "1.0.13",
|
"version": "1.0.14",
|
||||||
"description": "Guru SDK for unity project",
|
"description": "Guru SDK for unity project",
|
||||||
"unity": "2020.3",
|
"unity": "2020.3",
|
||||||
"author":{
|
"author":{
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue