Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
D
dz_TZImagePickerController
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
shuijing
dz_TZImagePickerController
Commits
3357eab3
Commit
3357eab3
authored
Aug 27, 2019
by
yuzheng
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat: save metadata to Album,adapt iOS13
parent
b8c71c8e
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
46 additions
and
3 deletions
+46
-3
TZImagePickerController/TZImagePickerController/TZImageManager.h
...PickerController/TZImagePickerController/TZImageManager.h
+1
-0
TZImagePickerController/TZImagePickerController/TZImageManager.m
...PickerController/TZImagePickerController/TZImageManager.m
+38
-0
TZImagePickerController/TZImagePickerController/TZPhotoPickerController.m
...troller/TZImagePickerController/TZPhotoPickerController.m
+2
-1
TZImagePickerController/ViewController.m
TZImagePickerController/ViewController.m
+5
-2
No files found.
TZImagePickerController/TZImagePickerController/TZImageManager.h
View file @
3357eab3
...
@@ -80,6 +80,7 @@
...
@@ -80,6 +80,7 @@
/// Save photo 保存照片
/// Save photo 保存照片
-
(
void
)
savePhotoWithImage
:(
UIImage
*
)
image
completion
:(
void
(
^
)(
PHAsset
*
asset
,
NSError
*
error
))
completion
;
-
(
void
)
savePhotoWithImage
:(
UIImage
*
)
image
completion
:(
void
(
^
)(
PHAsset
*
asset
,
NSError
*
error
))
completion
;
-
(
void
)
savePhotoWithImage
:(
UIImage
*
)
image
location
:(
CLLocation
*
)
location
completion
:(
void
(
^
)(
PHAsset
*
asset
,
NSError
*
error
))
completion
;
-
(
void
)
savePhotoWithImage
:(
UIImage
*
)
image
location
:(
CLLocation
*
)
location
completion
:(
void
(
^
)(
PHAsset
*
asset
,
NSError
*
error
))
completion
;
-
(
void
)
savePhotoWithImage
:(
UIImage
*
)
image
meta
:(
NSDictionary
*
)
meta
location
:(
CLLocation
*
)
location
completion
:(
void
(
^
)(
PHAsset
*
asset
,
NSError
*
error
))
completion
;
/// Save video 保存视频
/// Save video 保存视频
-
(
void
)
saveVideoWithUrl
:(
NSURL
*
)
url
completion
:(
void
(
^
)(
PHAsset
*
asset
,
NSError
*
error
))
completion
;
-
(
void
)
saveVideoWithUrl
:(
NSURL
*
)
url
completion
:(
void
(
^
)(
PHAsset
*
asset
,
NSError
*
error
))
completion
;
...
...
TZImagePickerController/TZImagePickerController/TZImageManager.m
View file @
3357eab3
...
@@ -9,6 +9,7 @@
...
@@ -9,6 +9,7 @@
#import "TZImageManager.h"
#import "TZImageManager.h"
#import "TZAssetModel.h"
#import "TZAssetModel.h"
#import "TZImagePickerController.h"
#import "TZImagePickerController.h"
#import <CoreServices/CoreServices.h>
@interface
TZImageManager
()
@interface
TZImageManager
()
#pragma clang diagnostic push
#pragma clang diagnostic push
...
@@ -497,6 +498,43 @@ static dispatch_once_t onceToken;
...
@@ -497,6 +498,43 @@ static dispatch_once_t onceToken;
}];
}];
}
}
-
(
void
)
savePhotoWithImage
:(
UIImage
*
)
image
meta
:(
NSDictionary
*
)
meta
location
:(
CLLocation
*
)
location
completion
:(
void
(
^
)(
PHAsset
*
asset
,
NSError
*
error
))
completion
{
NSData
*
imageData
=
UIImageJPEGRepresentation
(
image
,
1
.
0
f
);
CGImageSourceRef
source
=
CGImageSourceCreateWithData
((
__bridge
CFDataRef
)
imageData
,
NULL
);
NSDateFormatter
*
formater
=
[[
NSDateFormatter
alloc
]
init
];
[
formater
setDateFormat
:
@"yyyy-MM-dd-HH:mm:ss-SSS"
];
NSString
*
path
=
[
NSTemporaryDirectory
()
stringByAppendingFormat
:
@"image-%@.jpg"
,
[
formater
stringFromDate
:[
NSDate
date
]]];
NSURL
*
tmpURL
=
[
NSURL
fileURLWithPath
:
path
];
CGImageDestinationRef
destination
=
CGImageDestinationCreateWithURL
((
__bridge
CFURLRef
)
tmpURL
,
kUTTypeJPEG
,
1
,
NULL
);
CGImageDestinationAddImageFromSource
(
destination
,
source
,
0
,
(
__bridge
CFDictionaryRef
)
meta
);
CGImageDestinationFinalize
(
destination
);
CFRelease
(
source
);
CFRelease
(
destination
);
__block
NSString
*
localIdentifier
=
nil
;
[[
PHPhotoLibrary
sharedPhotoLibrary
]
performChanges
:
^
{
PHAssetChangeRequest
*
request
=
[
PHAssetChangeRequest
creationRequestForAssetFromImageAtFileURL
:
tmpURL
];
localIdentifier
=
request
.
placeholderForCreatedAsset
.
localIdentifier
;
if
(
location
)
{
request
.
location
=
location
;
}
request
.
creationDate
=
[
NSDate
date
];
}
completionHandler
:
^
(
BOOL
success
,
NSError
*
error
)
{
[[
NSFileManager
defaultManager
]
removeItemAtPath
:
path
error
:
nil
];
dispatch_async
(
dispatch_get_main_queue
(),
^
{
if
(
success
&&
completion
)
{
PHAsset
*
asset
=
[[
PHAsset
fetchAssetsWithLocalIdentifiers
:@[
localIdentifier
]
options
:
nil
]
firstObject
];
completion
(
asset
,
nil
);
}
else
if
(
error
)
{
NSLog
(
@"保存照片出错:%@"
,
error
.
localizedDescription
);
if
(
completion
)
{
completion
(
nil
,
error
);
}
}
});
}];
}
#pragma mark - Save video
#pragma mark - Save video
-
(
void
)
saveVideoWithUrl
:(
NSURL
*
)
url
completion
:(
void
(
^
)(
PHAsset
*
asset
,
NSError
*
error
))
completion
{
-
(
void
)
saveVideoWithUrl
:(
NSURL
*
)
url
completion
:(
void
(
^
)(
PHAsset
*
asset
,
NSError
*
error
))
completion
{
...
...
TZImagePickerController/TZImagePickerController/TZPhotoPickerController.m
View file @
3357eab3
...
@@ -811,8 +811,9 @@ static CGFloat itemMargin = 5;
...
@@ -811,8 +811,9 @@ static CGFloat itemMargin = 5;
TZImagePickerController
*
imagePickerVc
=
(
TZImagePickerController
*
)
self
.
navigationController
;
TZImagePickerController
*
imagePickerVc
=
(
TZImagePickerController
*
)
self
.
navigationController
;
[
imagePickerVc
showProgressHUD
];
[
imagePickerVc
showProgressHUD
];
UIImage
*
photo
=
[
info
objectForKey
:
UIImagePickerControllerOriginalImage
];
UIImage
*
photo
=
[
info
objectForKey
:
UIImagePickerControllerOriginalImage
];
NSDictionary
*
meta
=
[
info
objectForKey
:
UIImagePickerControllerMediaMetadata
];
if
(
photo
)
{
if
(
photo
)
{
[[
TZImageManager
manager
]
savePhotoWithImage
:
photo
location
:
self
.
location
completion
:^
(
PHAsset
*
asset
,
NSError
*
error
){
[[
TZImageManager
manager
]
savePhotoWithImage
:
photo
meta
:
meta
location
:
self
.
location
completion
:^
(
PHAsset
*
asset
,
NSError
*
error
){
if
(
!
error
)
{
if
(
!
error
)
{
[
self
addPHAsset
:
asset
];
[
self
addPHAsset
:
asset
];
}
}
...
...
TZImagePickerController/ViewController.m
View file @
3357eab3
...
@@ -201,11 +201,13 @@
...
@@ -201,11 +201,13 @@
TZGifPhotoPreviewController
*
vc
=
[[
TZGifPhotoPreviewController
alloc
]
init
];
TZGifPhotoPreviewController
*
vc
=
[[
TZGifPhotoPreviewController
alloc
]
init
];
TZAssetModel
*
model
=
[
TZAssetModel
modelWithAsset
:
asset
type
:
TZAssetModelMediaTypePhotoGif
timeLength
:
@""
];
TZAssetModel
*
model
=
[
TZAssetModel
modelWithAsset
:
asset
type
:
TZAssetModelMediaTypePhotoGif
timeLength
:
@""
];
vc
.
model
=
model
;
vc
.
model
=
model
;
vc
.
modalPresentationStyle
=
UIModalPresentationFullScreen
;
[
self
presentViewController
:
vc
animated
:
YES
completion
:
nil
];
[
self
presentViewController
:
vc
animated
:
YES
completion
:
nil
];
}
else
if
(
isVideo
&&
!
self
.
allowPickingMuitlpleVideoSwitch
.
isOn
)
{
// perview video / 预览视频
}
else
if
(
isVideo
&&
!
self
.
allowPickingMuitlpleVideoSwitch
.
isOn
)
{
// perview video / 预览视频
TZVideoPlayerController
*
vc
=
[[
TZVideoPlayerController
alloc
]
init
];
TZVideoPlayerController
*
vc
=
[[
TZVideoPlayerController
alloc
]
init
];
TZAssetModel
*
model
=
[
TZAssetModel
modelWithAsset
:
asset
type
:
TZAssetModelMediaTypeVideo
timeLength
:
@""
];
TZAssetModel
*
model
=
[
TZAssetModel
modelWithAsset
:
asset
type
:
TZAssetModelMediaTypeVideo
timeLength
:
@""
];
vc
.
model
=
model
;
vc
.
model
=
model
;
vc
.
modalPresentationStyle
=
UIModalPresentationFullScreen
;
[
self
presentViewController
:
vc
animated
:
YES
completion
:
nil
];
[
self
presentViewController
:
vc
animated
:
YES
completion
:
nil
];
}
else
{
// preview photos / 预览照片
}
else
{
// preview photos / 预览照片
TZImagePickerController
*
imagePickerVc
=
[[
TZImagePickerController
alloc
]
initWithSelectedAssets
:
_selectedAssets
selectedPhotos
:
_selectedPhotos
index
:
indexPath
.
item
];
TZImagePickerController
*
imagePickerVc
=
[[
TZImagePickerController
alloc
]
initWithSelectedAssets
:
_selectedAssets
selectedPhotos
:
_selectedPhotos
index
:
indexPath
.
item
];
...
@@ -215,6 +217,7 @@
...
@@ -215,6 +217,7 @@
imagePickerVc
.
allowPickingMultipleVideo
=
self
.
allowPickingMuitlpleVideoSwitch
.
isOn
;
imagePickerVc
.
allowPickingMultipleVideo
=
self
.
allowPickingMuitlpleVideoSwitch
.
isOn
;
imagePickerVc
.
showSelectedIndex
=
self
.
showSelectedIndexSwitch
.
isOn
;
imagePickerVc
.
showSelectedIndex
=
self
.
showSelectedIndexSwitch
.
isOn
;
imagePickerVc
.
isSelectOriginalPhoto
=
_isSelectOriginalPhoto
;
imagePickerVc
.
isSelectOriginalPhoto
=
_isSelectOriginalPhoto
;
imagePickerVc
.
modalPresentationStyle
=
UIModalPresentationFullScreen
;
[
imagePickerVc
setDidFinishPickingPhotosHandle
:
^
(
NSArray
<
UIImage
*>
*
photos
,
NSArray
*
assets
,
BOOL
isSelectOriginalPhoto
)
{
[
imagePickerVc
setDidFinishPickingPhotosHandle
:
^
(
NSArray
<
UIImage
*>
*
photos
,
NSArray
*
assets
,
BOOL
isSelectOriginalPhoto
)
{
self
->
_selectedPhotos
=
[
NSMutableArray
arrayWithArray
:
photos
];
self
->
_selectedPhotos
=
[
NSMutableArray
arrayWithArray
:
photos
];
self
->
_selectedAssets
=
[
NSMutableArray
arrayWithArray
:
assets
];
self
->
_selectedAssets
=
[
NSMutableArray
arrayWithArray
:
assets
];
...
@@ -468,9 +471,9 @@
...
@@ -468,9 +471,9 @@
[
tzImagePickerVc
showProgressHUD
];
[
tzImagePickerVc
showProgressHUD
];
if
([
type
isEqualToString
:
@"public.image"
])
{
if
([
type
isEqualToString
:
@"public.image"
])
{
UIImage
*
image
=
[
info
objectForKey
:
UIImagePickerControllerOriginalImage
];
UIImage
*
image
=
[
info
objectForKey
:
UIImagePickerControllerOriginalImage
];
NSDictionary
*
meta
=
[
info
objectForKey
:
UIImagePickerControllerMediaMetadata
];
// save photo and get asset / 保存图片,获取到asset
// save photo and get asset / 保存图片,获取到asset
[[
TZImageManager
manager
]
savePhotoWithImage
:
image
location
:
self
.
location
completion
:^
(
PHAsset
*
asset
,
NSError
*
error
){
[[
TZImageManager
manager
]
savePhotoWithImage
:
image
meta
:
meta
location
:
self
.
location
completion
:^
(
PHAsset
*
asset
,
NSError
*
error
){
[
tzImagePickerVc
hideProgressHUD
];
[
tzImagePickerVc
hideProgressHUD
];
if
(
error
)
{
if
(
error
)
{
NSLog
(
@"图片保存失败 %@"
,
error
);
NSLog
(
@"图片保存失败 %@"
,
error
);
...
...
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