Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
G
galaxy-iOS
Project
Project
Details
Activity
Releases
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
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
mobile-group
galaxy-iOS
Commits
25b309d9
Commit
25b309d9
authored
Apr 12, 2024
by
Steven杜宇
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
// 权限设置
parent
bc9c99c4
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
75 additions
and
25 deletions
+75
-25
YHMyPermissionSettingVC.swift
.../Classes/Modules/Mine(我的)/C/YHMyPermissionSettingVC.swift
+75
-25
No files found.
galaxy/galaxy/Classes/Modules/Mine(我的)/C/YHMyPermissionSettingVC.swift
View file @
25b309d9
...
...
@@ -7,6 +7,7 @@
//
import
UIKit
import
Photos
enum
YHPermissionType
:
Int
{
case
none
=
0
...
...
@@ -31,11 +32,9 @@ class YHPermissionItem {
class
YHMyPermissionSettingVC
:
YHBaseViewController
{
var
items
:[
YHPermissionItem
]
=
[
YHPermissionItem
(
title
:
"网络"
.
local
,
type
:
.
network
,
enableStatus
:
true
),
YHPermissionItem
(
title
:
"照片"
.
local
,
type
:
.
photo
,
enableStatus
:
true
),
YHPermissionItem
(
title
:
"相机"
.
local
,
type
:
.
camera
,
enableStatus
:
false
),
YHPermissionItem
(
title
:
"位置"
.
local
,
type
:
.
location
,
enableStatus
:
true
),
YHPermissionItem
(
title
:
"文件"
.
local
,
type
:
.
file
,
enableStatus
:
false
)]
let
items
:[
YHPermissionItem
]
=
[
YHPermissionItem
(
title
:
"网络"
.
local
,
type
:
.
network
,
enableStatus
:
YHNetworkStatusManager
.
shared
.
isNetWorkOK
),
YHPermissionItem
(
title
:
"照片"
.
local
,
type
:
.
photo
,
enableStatus
:
false
),
YHPermissionItem
(
title
:
"相机"
.
local
,
type
:
.
camera
,
enableStatus
:
false
)]
lazy
var
tableView
:
UITableView
=
{
let
tableView
=
UITableView
(
frame
:
.
zero
,
style
:
.
grouped
)
...
...
@@ -64,6 +63,72 @@ class YHMyPermissionSettingVC: YHBaseViewController {
make
.
top
.
equalToSuperview
()
.
offset
(
k_Height_NavigationtBarAndStatuBar
)
make
.
bottom
.
equalToSuperview
()
.
offset
(
-
k_Height_TabBar
)
}
// 获取相册权限
requestPhotoLibraryPermission
{
[
weak
self
]
grant
in
guard
let
self
=
self
else
{
return
}
for
item
in
items
{
if
item
.
type
==
.
photo
{
item
.
enableStatus
=
grant
self
.
tableView
.
reloadData
()
}
}
}
// 获取相机权限
requestCameraPermission
{
[
weak
self
]
grant
in
guard
let
self
=
self
else
{
return
}
for
item
in
items
{
if
item
.
type
==
.
camera
{
item
.
enableStatus
=
grant
self
.
tableView
.
reloadData
()
}
}
}
}
func
requestPhotoLibraryPermission
(
completion
:
@escaping
(
Bool
)
->
Void
)
{
let
status
=
PHPhotoLibrary
.
authorizationStatus
()
switch
status
{
case
.
authorized
:
// 已经授权
completion
(
true
)
case
.
denied
,
.
restricted
,
.
limited
:
// 拒绝或受限制,需要提示用户去设置中授权
completion
(
false
)
case
.
notDetermined
:
// 尚未确定,请求授权
completion
(
false
)
@unknown
default
:
completion
(
false
)
}
}
func
requestCameraPermission
(
completion
:
@escaping
(
Bool
)
->
Void
)
{
let
status
=
AVCaptureDevice
.
authorizationStatus
(
for
:
.
video
)
switch
status
{
case
.
authorized
:
// 已经授权
completion
(
true
)
case
.
denied
,
.
restricted
:
// 拒绝或受限制,需要提示用户去设置中授权
completion
(
false
)
case
.
notDetermined
:
// 尚未确定,请求授权
completion
(
false
)
@unknown
default
:
completion
(
false
)
}
}
}
...
...
@@ -88,27 +153,12 @@ extension YHMyPermissionSettingVC: UITableViewDelegate, UITableViewDataSource {
}
func
tableView
(
_
tableView
:
UITableView
,
didSelectRowAt
indexPath
:
IndexPath
)
{
if
0
<=
indexPath
.
row
&&
indexPath
.
row
<
items
.
count
{
let
item
=
items
[
indexPath
.
row
]
if
item
.
type
==
.
photo
||
item
.
type
==
.
camera
{
let
url
=
URL
(
string
:
UIApplication
.
openSettingsURLString
)
if
let
url
=
url
,
UIApplication
.
shared
.
canOpenURL
(
url
)
{
UIApplication
.
shared
.
open
(
url
,
options
:
[:],
completionHandler
:
{
(
success
)
in
})
}
return
}
if
item
.
type
==
.
location
{
if
let
url
=
URL
(
string
:
"App-prefs:Photos"
)
{
UIApplication
.
shared
.
open
(
url
,
options
:
[:],
completionHandler
:
nil
)
}
}
else
if
item
.
type
==
.
file
{
}
let
url
=
URL
(
string
:
UIApplication
.
openSettingsURLString
)
if
let
url
=
url
,
UIApplication
.
shared
.
canOpenURL
(
url
)
{
UIApplication
.
shared
.
open
(
url
,
options
:
[:],
completionHandler
:
{
(
success
)
in
})
}
}
...
...
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