From cfe81b5583fa892db0a72f0f56585c11f90e1a90 Mon Sep 17 00:00:00 2001 From: huyufei Date: Fri, 21 Jun 2024 14:13:58 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=E6=8F=90=E7=A4=BA=20B?= =?UTF-8?q?UG?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: huyufei --- .../Manager/NotificationAgentAndroid.cs | 21 ++++++++----------- 1 file changed, 9 insertions(+), 12 deletions(-) diff --git a/Runtime/GuruNoification/Manager/NotificationAgentAndroid.cs b/Runtime/GuruNoification/Manager/NotificationAgentAndroid.cs index 6830f7d..4d2c545 100644 --- a/Runtime/GuruNoification/Manager/NotificationAgentAndroid.cs +++ b/Runtime/GuruNoification/Manager/NotificationAgentAndroid.cs @@ -18,7 +18,6 @@ namespace Guru.Notification private bool _initOnce = false; private string _notiStatus; - private bool _isPluginsInited = false; private string SavedNotiPermStatus { @@ -38,7 +37,6 @@ namespace Guru.Notification if (!string.IsNullOrEmpty(SavedNotiPermStatus)) { _notiStatus = SavedNotiPermStatus; - return; } #if UNITY_ANDROID @@ -108,8 +106,6 @@ namespace Guru.Notification { AndroidNotificationCenter.Initialize(); Debug.Log($"[Noti][AND] --- Notification Service InitPlugins"); - - _isPluginsInited = true; UpdateNotiStatus(); } @@ -119,8 +115,7 @@ namespace Guru.Notification /// private void UpdateNotiStatus() { - if (!_isPluginsInited) return; - + TryExecute(() => { _permissionStatus = AndroidNotificationCenter.UserPermissionToPost; @@ -148,12 +143,6 @@ namespace Guru.Notification private PermissionCallbacks _permissionCallbacks; private void RequestAndroidPermission(Action callback = null) { - if (!_isPluginsInited) - { - callback?.Invoke(_notiStatus); - return; - } - UpdateNotiStatus(); if (_notiStatus == STATUS_GRANTED) @@ -176,6 +165,14 @@ namespace Guru.Notification else { // SDK 33 以上,请求弹窗 + + bool hasPermission = Permission.HasUserAuthorizedPermission(PERMISSION_POST_NOTIFICATION); + if (hasPermission) + { + SetGrantStatus(STATUS_GRANTED); + callback?.Invoke(STATUS_GRANTED); + return; + } Debug.Log($"[SDK][Noti] --- #4 SDK {sdkInt} :: Ask Post Permission"); Permission.RequestUserPermission(PERMISSION_POST_NOTIFICATION, SetupPermissionCallbacks()); }