File tree Expand file tree Collapse file tree 3 files changed +115
-0
lines changed
Expand file tree Collapse file tree 3 files changed +115
-0
lines changed Original file line number Diff line number Diff line change 1+ //
2+ // GameFrameXTrackingAuthorization.mm
3+ // GameFrameX
4+ //
5+ // Created by jiangjiayi on 2025/8/12.
6+ // https://github.com/gameframex
7+ // https://github.com/alianblank
8+ //
9+ // 广告跟踪授权
10+ //
11+ #import < Foundation/Foundation.h>
12+ #import < AppTrackingTransparency/AppTrackingTransparency.h>
13+ @interface GameFrameXTrackingAuthorization : NSObject
14+
15+ /* *
16+ * @brief 请求广告跟踪授权
17+ * @details 向用户请求广告跟踪授权,并在授权结果回调中处理不同的授权状态
18+ */
19+ + (void )RequestTrackingAuthorization ;
20+
21+ @end
22+
23+ NS_ASSUME_NONNULL_BEGIN
24+
25+ @implementation GameFrameXTrackingAuthorization
26+
27+ /* *
28+ * @brief 请求广告跟踪授权
29+ * @details 向用户请求广告跟踪授权,并在授权结果回调中处理不同的授权状态
30+ */
31+ + (void )RequestTrackingAuthorization
32+ {
33+ if (@available (iOS 14 , *)) {
34+ [ATTrackingManager requestTrackingAuthorizationWithCompletionHandler: ^(ATTrackingManagerAuthorizationStatus status) {
35+ switch (status)
36+ {
37+ case ATTrackingManagerAuthorizationStatusNotDetermined:
38+ NSLog (@" 跟踪授权状态: 未确定" );
39+ break ;
40+ case ATTrackingManagerAuthorizationStatusRestricted:
41+ NSLog (@" 跟踪授权状态: 受限制" );
42+ break ;
43+ case ATTrackingManagerAuthorizationStatusDenied:
44+ NSLog (@" 跟踪授权状态: 已拒绝" );
45+ break ;
46+ case ATTrackingManagerAuthorizationStatusAuthorized:
47+ NSLog (@" 跟踪授权状态: 已授权" );
48+ break ;
49+ }
50+ }];
51+ }
52+ }
53+
54+ @end
55+
56+ NS_ASSUME_NONNULL_END
57+
58+ /* *
59+ * @brief 打开广告跟踪授权请求
60+ * @details 调用请求广告跟踪授权的方法
61+ */
62+ extern " C" void open_request_tracking_authorization (){
63+ [GameFrameXTrackingAuthorization RequestTrackingAuthorization ];
64+ }
Original file line number Diff line number Diff line change @@ -159,6 +159,20 @@ public static void OpenSetting()
159159 open_setting ( ) ;
160160#endif
161161 }
162+
163+
164+ #if UNITY_IOS
165+ [ System . Runtime . InteropServices . DllImport ( "__Internal" ) ]
166+ private static extern void open_request_tracking_authorization ( ) ;
167+ #endif
168+ /// <summary>
169+ /// 打开请求跟踪授权
170+ /// </summary>
171+ [ UnityEngine . Scripting . Preserve ]
172+ public static void OpenRequestTrackingAuthorization ( )
173+ {
174+ #if UNITY_IOS
175+ open_request_tracking_authorization ( ) ;
162176#endif
163177 }
164178 }
You can’t perform that action at this time.
0 commit comments