Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Sign in / Register
Toggle navigation
P
PhoneManager
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Packages
Packages
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Yang
PhoneManager
Commits
a6c383bd
Commit
a6c383bd
authored
Apr 21, 2025
by
CZ1004
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
修改追踪权限
parent
daf5a83d
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
64 additions
and
6 deletions
+64
-6
AppDelegate.swift
PhoneManager/AppDelegate.swift
+4
-4
HomeViewController.swift
...er/Class/Session/Home/Controller/HomeViewController.swift
+58
-2
Info.plist
PhoneManager/Info.plist
+2
-0
No files found.
PhoneManager/AppDelegate.swift
View file @
a6c383bd
PhoneManager/Class/Session/Home/Controller/HomeViewController.swift
View file @
a6c383bd
...
...
@@ -6,7 +6,7 @@
//
import
UIKit
import
AppTrackingTransparency
class
HomeViewController
:
BaseViewController
{
...
...
@@ -17,7 +17,8 @@ class HomeViewController:BaseViewController {
override
func
viewDidLoad
()
{
super
.
viewDidLoad
()
// 调用下追踪权限
checkTrackingAuthorization
()
let
dataUpdated
=
Notification
.
Name
(
"DataUpdatedNotification"
)
...
...
@@ -368,3 +369,58 @@ class HomeViewController:BaseViewController {
}
}
extension
HomeViewController
{
// 检查跟踪授权状态
func
checkTrackingAuthorization
()
{
if
#available(iOS 14, *)
{
let
status
=
ATTrackingManager
.
trackingAuthorizationStatus
switch
status
{
case
.
authorized
:
// 用户已授权跟踪
print
(
"用户已授权应用进行跟踪"
)
case
.
denied
:
// 用户拒绝了跟踪请求
print
(
"用户拒绝了应用的跟踪请求"
)
case
.
restricted
:
// 由于系统限制,无法跟踪用户
print
(
"由于系统限制,无法跟踪用户"
)
case
.
notDetermined
:
// 用户尚未对跟踪请求做出决定
print
(
"用户尚未对跟踪请求做出决定,再次请求授权"
)
requestTrackingAuthorization
()
@unknown
default
:
break
}
}
else
{
// iOS 14 以下系统不支持 ATT 框架
// 可以执行其他操作
}
}
func
requestTrackingAuthorization
()
{
if
#available(iOS 14, *)
{
ATTrackingManager
.
requestTrackingAuthorization
(
completionHandler
:
{
status
in
switch
status
{
case
.
authorized
:
// 用户已授权跟踪
print
(
"用户已授权应用进行跟踪"
)
case
.
denied
:
// 用户拒绝了跟踪请求
print
(
"用户拒绝了应用的跟踪请求"
)
case
.
restricted
:
// 由于系统限制,无法跟踪用户
print
(
"由于系统限制,无法跟踪用户"
)
case
.
notDetermined
:
// 用户尚未对跟踪请求做出决定
print
(
"用户尚未对跟踪请求做出决定"
)
@unknown
default
:
break
}
})
}
else
{
// iOS 14 以下系统不支持 ATT 框架
// 可以执行其他操作
}
}
}
PhoneManager/Info.plist
View file @
a6c383bd
...
...
@@ -2,6 +2,8 @@
<
!
D
O
C
TYP
E
plist
PU
B
LI
C
"-//
A
ppl
e
//
D
T
D
PLIST
1
.
0
//
E
N"
"http://www.
a
ppl
e
.
c
om/
D
T
D
s/Prop
e
rtyList-
1
.
0
.
d
t
d
"
>
<
plist
v
e
rsion="
1
.
0
"
>
<
d
i
c
t
>
<
k
e
y
>
NSUserTrackingUsageDescription
<
/k
e
y
>
<
string
>
We
need
your
permission
to
track
your
usage
habits
in
order
to
provide
a
more
personalized
advertising
experience
<
/string
>
<
k
e
y
>
NSAppTransportSecurity
<
/k
e
y
>
<
d
i
c
t
>
<
k
e
y
>
NSAllowsArbitraryLoads
<
/k
e
y
>
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment