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
b88bc567
Commit
b88bc567
authored
May 30, 2024
by
pete谢兆麟
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
相机相册权限逻辑添加和判断
parent
389a4796
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
52 additions
and
56 deletions
+52
-56
YHImagePickerView.swift
...ainApplicantInformation(主申请人信息)/V/YHImagePickerView.swift
+52
-56
No files found.
galaxy/galaxy/Classes/Modules/IntelligentService(服务中心)/ServiceProcess(我的信息流程)/MainApplicantInformation(主申请人信息)/V/YHImagePickerView.swift
View file @
b88bc567
...
...
@@ -45,6 +45,58 @@ class YHImagePickerView: UIView {
setView
()
}
// 请求相机权限
@objc
func
takePhoto
()
{
AVCaptureDevice
.
requestAccess
(
for
:
.
video
)
{
[
weak
self
]
granted
in
if
granted
{
// 已获得权限,可以使用相机
DispatchQueue
.
main
.
async
{
if
UIImagePickerController
.
isSourceTypeAvailable
(
.
camera
){
//创建图片控制器
let
imagePicker
=
UIImagePickerController
()
//设置代理
imagePicker
.
delegate
=
self
//设置来源
imagePicker
.
sourceType
=
.
camera
//打开相机
UIViewController
.
current
?
.
present
(
imagePicker
,
animated
:
true
,
completion
:
{
()
->
Void
in
})
}
else
{
printLog
(
"找不到相机"
)
}
}
}
else
{
DispatchQueue
.
main
.
async
{
YHHUD
.
flash
(
message
:
"请打开相机权限"
)
}
}
}
}
// 请求相册权限
@objc
func
selectPhoto
()
{
PHPhotoLibrary
.
requestAuthorization
{
[
weak
self
]
status
in
if
status
==
.
authorized
{
DispatchQueue
.
main
.
async
{
if
UIImagePickerController
.
isSourceTypeAvailable
(
.
photoLibrary
){
let
imagePicker
=
UIImagePickerController
()
imagePicker
.
delegate
=
self
imagePicker
.
sourceType
=
.
photoLibrary
imagePicker
.
modalPresentationStyle
=
.
fullScreen
// 这一句,开始调用图库
UIViewController
.
current
?
.
present
(
imagePicker
,
animated
:
true
)
}
}
}
else
{
// 未获得权限,提示用户
DispatchQueue
.
main
.
async
{
YHHUD
.
flash
(
message
:
"请打开相册权限"
)
}
}
}
}
required
init
?(
coder
:
NSCoder
)
{
fatalError
(
"init(coder:) has not been implemented"
)
}
...
...
@@ -164,62 +216,6 @@ class YHImagePickerView: UIView {
removeFromSuperview
()
}
@objc
func
takePhoto
()
{
guard
getPhotoLibraryAuthorization
()
else
{
YHHUD
.
flash
(
message
:
"请打开相册权限"
)
return
}
if
UIImagePickerController
.
isSourceTypeAvailable
(
.
camera
){
//创建图片控制器
let
imagePicker
=
UIImagePickerController
()
//设置代理
imagePicker
.
delegate
=
self
//设置来源
imagePicker
.
sourceType
=
.
camera
//打开相机
UIViewController
.
current
?
.
present
(
imagePicker
,
animated
:
true
,
completion
:
{
()
->
Void
in
})
}
else
{
printLog
(
"找不到相机"
)
}
}
@objc
func
selectPhoto
()
{
guard
getPhotoLibraryAuthorization
()
else
{
YHHUD
.
flash
(
message
:
"请打开相册权限"
)
return
}
if
UIImagePickerController
.
isSourceTypeAvailable
(
.
photoLibrary
){
let
imagePicker
=
UIImagePickerController
()
imagePicker
.
delegate
=
self
imagePicker
.
sourceType
=
.
photoLibrary
// 这一句,开始调用图库
UIViewController
.
current
?
.
present
(
imagePicker
,
animated
:
true
)
}
}
private
func
getPhotoLibraryAuthorization
()
->
Bool
{
let
authorizationStatus
=
PHPhotoLibrary
.
authorizationStatus
()
switch
authorizationStatus
{
case
.
authorized
:
print
(
"已经授权"
)
return
true
case
.
notDetermined
:
print
(
"不确定是否授权"
)
// 请求授权
PHPhotoLibrary
.
requestAuthorization
({
(
status
)
in
})
case
.
denied
:
print
(
"拒绝授权"
)
case
.
restricted
:
print
(
"限制授权"
)
break
case
.
limited
:
break
@unknown
default
:
break
}
return
false
}
}
extension
YHImagePickerView
:
UIGestureRecognizerDelegate
{
...
...
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