Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
zhangyongji
/
MRFramework
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Members
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
188911fa
authored
Nov 28, 2019
by
Sarkizz
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
图片保存到相册添加授权判断和请求逻辑
parent
1a05b5a3
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
34 additions
and
21 deletions
+34
-21
MRFramework/MRFramework/Extensions/UIKit/UIImage+file.swift
+34
-21
No files found.
MRFramework/MRFramework/Extensions/UIKit/UIImage+file.swift
View file @
188911fa
...
...
@@ -86,34 +86,47 @@ extension UIImage {
/// 将图片写入到相册
/// - Parameter complate: 回调
public
func
saveToAlbum
(
_
complate
:
UIImageSaveToAlbumCompleteBlock
?)
{
var
localId
:
String
?
PHPhotoLibrary
.
shared
()
.
performChanges
({
let
rs
=
PHAssetChangeRequest
.
creationRequestForAsset
(
from
:
self
)
let
placeholder
=
rs
.
placeholderForCreatedAsset
localId
=
placeholder
?
.
localIdentifier
},
completionHandler
:
{
(
isSuccessed
,
error
)
in
if
isSuccessed
{
if
let
id
=
localId
{
let
rs
=
PHAsset
.
fetchAssets
(
withLocalIdentifiers
:
[
id
],
options
:
nil
)
if
let
asset
=
rs
.
firstObject
{
let
options
=
PHContentEditingInputRequestOptions
()
options
.
canHandleAdjustmentData
=
{
data
in
return
true
checkAuthorization
({
status
in
var
localId
:
String
?
PHPhotoLibrary
.
shared
()
.
performChanges
({
let
rs
=
PHAssetChangeRequest
.
creationRequestForAsset
(
from
:
self
)
let
placeholder
=
rs
.
placeholderForCreatedAsset
localId
=
placeholder
?
.
localIdentifier
},
completionHandler
:
{
(
isSuccessed
,
error
)
in
if
isSuccessed
{
if
let
id
=
localId
{
let
rs
=
PHAsset
.
fetchAssets
(
withLocalIdentifiers
:
[
id
],
options
:
nil
)
if
let
asset
=
rs
.
firstObject
{
let
options
=
PHContentEditingInputRequestOptions
()
options
.
canHandleAdjustmentData
=
{
data
in
return
true
}
asset
.
requestContentEditingInput
(
with
:
options
,
completionHandler
:
{
(
input
,
_
)
in
complate
?(
self
,
input
?
.
fullSizeImageURL
,
nil
)
})
}
else
{
complate
?(
self
,
nil
,
self
.
error
(
code
:
-
2
,
msg
:
"获取图片资源失败"
))
}
asset
.
requestContentEditingInput
(
with
:
options
,
completionHandler
:
{
(
input
,
_
)
in
complate
?(
self
,
input
?
.
fullSizeImageURL
,
nil
)
})
}
else
{
complate
?(
self
,
nil
,
self
.
error
(
code
:
-
2
,
msg
:
"获取图片资源失败
"
))
complate
?(
self
,
nil
,
self
.
error
(
code
:
-
1
,
msg
:
"保存图片缺失localIdentifier
"
))
}
}
else
{
complate
?(
self
,
nil
,
self
.
error
(
code
:
-
1
,
msg
:
"保存图片缺失localIdentifier"
)
)
complate
?(
self
,
nil
,
error
)
}
}
else
{
complate
?(
self
,
nil
,
error
)
}
})
})
}
/// 检查当前授权状态,未授权则调用授权接口
/// - Parameter completion: 回调
public
func
checkAuthorization
(
_
completion
:
@escaping
(
_
status
:
PHAuthorizationStatus
)
->
Void
)
{
let
current
=
PHPhotoLibrary
.
authorizationStatus
()
if
current
==
.
notDetermined
{
PHPhotoLibrary
.
requestAuthorization
(
completion
)
}
else
{
completion
(
current
)
}
}
}
extension
UIImage
{
...
...
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