ios пре 1 година
родитељ
комит
1cd6387782

+ 40 - 6
GameClient/Assets/Game/Launcher/Platform/ATTAuth.cs

@@ -1,15 +1,49 @@
-namespace GFGGame.Launcher
+using System;
+using System.Runtime.InteropServices;
+using UnityEngine;
+
+namespace GFGGame.Launcher
 {
-    public static class AppTrackingTransparency
+    public class ATTAuth : MonoBehaviour
     {
+        [DllImport("__Internal")]
+        private static extern void _RequestTrackingAuthorizationWithCompletionHandler();
+
+        [DllImport("__Internal")]
+        private static extern int _GetAppTrackingAuthorizationStatus();
+
+        private static Action<int> getAuthorizationStatusAction;
 
-        [System.Runtime.InteropServices.DllImport("__Internal")]
-        private static extern void RequestTrackingAuthorizationI();
+        /// <summary>
+        /// 请求ATT授权窗口
+        /// </summary>
+        /// <param name="getResult"></param>
+        public static void RequestTrackingAuthorizationWithCompletionHandler(Action<int> getResult)
+        {
+            //-1:"ios版本低于14"
+            //0: "ATT 授权状态待定";
+            //1: "ATT 授权状态受限";
+            //2: "ATT 已拒绝";
+            //3: "ATT 已授权";
+            Debug.Log("RequestTrackingAuthorizationWithCompletionHandler");
+            getAuthorizationStatusAction = getResult;
+            _RequestTrackingAuthorizationWithCompletionHandler();
+        }
 
-        public static void RequestTrackingAuthorization()
+        /// <summary>
+        /// 获取当前ATT授权状态
+        /// </summary>
+        /// <returns></returns>
+        public static int GetAppTrackingAuthorizationStatus()
         {
-            RequestTrackingAuthorization();
+            return _GetAppTrackingAuthorizationStatus();
         }
+
+        public void GetAuthorizationStatus(string status)
+        {
+            getAuthorizationStatusAction?.Invoke(int.Parse(status));
+        }
+
     }
 }
 

+ 1 - 1
GameClient/Assets/Game/Launcher/Platform/AppTrackingTransparency.cs.meta → GameClient/Assets/Game/Launcher/Platform/ATTAuth.cs.meta

@@ -1,5 +1,5 @@
 fileFormatVersion: 2
-guid: 623e1462460a4498ea93f0adc67e06df
+guid: 78f2817b7143d4c25b43ea63116f227f
 MonoImporter:
   externalObjects: {}
   serializedVersion: 2

+ 27 - 9
GameClient/Assets/Game/Launcher/Platform/QDAppStoreManagerInit.cs

@@ -6,23 +6,41 @@ namespace GFGGame.Launcher
 
     public static class QDAppStoreManagerInit
     {
+        public static int AppTrackingAuthorizationStatus;
+        private const string ATTStatusLocalKey = "ATTStatusLocalKey";
+
         public static void InitPlatform()
         {
-            AppTrackingTransparency.RequestTrackingAuthorization();
+#if !UNITY_EDITOR && UNITY_IOS
+            AppTrackingAuthorizationStatus = ATTAuth.GetAppTrackingAuthorizationStatus();
+            if (AppTrackingAuthorizationStatus == 0)
+            {
+                bool requested = LocalCache.GetBool(ATTStatusLocalKey, false);
+                if(!requested)
+                {
+                    AddIOSMethod();
+                    ATTAuth.RequestTrackingAuthorizationWithCompletionHandler((status) =>
+                    {
+                        Debug.Log("ATT status :" + status);
+                        AppTrackingAuthorizationStatus = status;
+                    });
+                }
+            }
+#endif
             UniEvent.SendMessage(new LauncherEvent.InitPlatformResult() { success = true});
         }
 
-        public static void UpdateApp()
+
+        private static void AddIOSMethod()
         {
-            if (string.IsNullOrEmpty(LauncherConfig.updateAppPrompt))
+            string objName = "IOSMethod";
+            var obj = GameObject.Find(objName);
+            if(obj == null)
             {
-                LauncherConfig.updateAppPrompt = "需要安装新的安装包。";
+                obj = new GameObject(objName);
+                GameObject.DontDestroyOnLoad(obj);
             }
-            Alert.Show(LauncherConfig.updateAppPrompt)
-                    .SetLeftButton(true, "前往更新", (data) =>
-                    {
-                        Application.OpenURL("");
-                    });
+            obj.AddComponent<ATTAuth>();
         }
     }
 }

+ 0 - 3
GameClient/Assets/Game/Launcher/Platform/QDManagerInit.cs

@@ -24,9 +24,6 @@ namespace GFGGame.Launcher
         {
             switch(LauncherConfig.ChannelId)
             {
-                case (int)ChannelID.AppStore:
-                    QDAppStoreManagerInit.UpdateApp();
-                    break;
                 default:
                     if(!string.IsNullOrEmpty(LauncherConfig.updateUrl))
                     {

+ 23 - 4
GameClient/Assets/Plugins/iOS/AppTrackingTransparency/AppTrackingTransparency.mm

@@ -1,7 +1,26 @@
+#import <Foundation/Foundation.h>
 #import <AppTrackingTransparency/AppTrackingTransparency.h>
+#import "UnityInterface.h"
 
-extern "C" void RequestTrackingAuthorizationI() {
-    [ATTrackingManager requestTrackingAuthorizationWithCompletionHandler:^(ATTrackingManagerAuthorizationStatus status) {
-        // 处理授权状态
-    }];
+extern "C" {
+     void _RequestTrackingAuthorizationWithCompletionHandler() {
+         if (@available(iOS 14, *)) {
+             [ATTrackingManager requestTrackingAuthorizationWithCompletionHandler:^(ATTrackingManagerAuthorizationStatus status) {
+                 NSString *stringInt = [NSString stringWithFormat:@"%lu",(unsigned long)status];
+                 const char* charStatus = [stringInt UTF8String];
+                 UnitySendMessage("IOSMethod", "GetAuthorizationStatus", charStatus);
+             }];
+         } else {
+             UnitySendMessage("IOSMethod", "GetAuthorizationStatus", "-1");
+         }
+     }
+    
+     int _GetAppTrackingAuthorizationStatus() {
+         if (@available(iOS 14, *)) {
+             return (int)[ATTrackingManager trackingAuthorizationStatus];
+         } else {
+             return -1;
+         }
+     }
 }
+