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
1b52982a
Commit
1b52982a
authored
Aug 22, 2016
by
banchichen
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
优化权限判断相关代码
parent
ef2b14a2
Changes
5
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
60 additions
and
23 deletions
+60
-23
TZImagePickerController/TZImagePickerController/TZImageManager.h
...PickerController/TZImagePickerController/TZImageManager.h
+1
-1
TZImagePickerController/TZImagePickerController/TZImageManager.m
...PickerController/TZImagePickerController/TZImageManager.m
+9
-3
TZImagePickerController/TZImagePickerController/TZImagePickerController.m
...troller/TZImagePickerController/TZImagePickerController.m
+18
-1
TZImagePickerController/TZImagePickerController/TZPhotoPickerController.m
...troller/TZImagePickerController/TZPhotoPickerController.m
+6
-4
TZImagePickerController/ViewController.m
TZImagePickerController/ViewController.m
+26
-14
No files found.
TZImagePickerController/TZImagePickerController/TZImageManager.h
View file @
1b52982a
...
@@ -45,7 +45,7 @@
...
@@ -45,7 +45,7 @@
-
(
void
)
getOriginalPhotoWithAsset
:(
id
)
asset
completion
:(
void
(
^
)(
UIImage
*
photo
,
NSDictionary
*
info
))
completion
;
-
(
void
)
getOriginalPhotoWithAsset
:(
id
)
asset
completion
:(
void
(
^
)(
UIImage
*
photo
,
NSDictionary
*
info
))
completion
;
/// Save photo 保存照片
/// Save photo 保存照片
-
(
void
)
savePhotoWithImage
:(
UIImage
*
)
image
completion
:(
void
(
^
)())
completion
;
-
(
void
)
savePhotoWithImage
:(
UIImage
*
)
image
completion
:(
void
(
^
)(
NSError
*
error
))
completion
;
/// Get video 获得视频
/// Get video 获得视频
-
(
void
)
getVideoWithAsset
:(
id
)
asset
completion
:(
void
(
^
)(
AVPlayerItem
*
playerItem
,
NSDictionary
*
info
))
completion
;
-
(
void
)
getVideoWithAsset
:(
id
)
asset
completion
:(
void
(
^
)(
AVPlayerItem
*
playerItem
,
NSDictionary
*
info
))
completion
;
...
...
TZImagePickerController/TZImagePickerController/TZImageManager.m
View file @
1b52982a
...
@@ -509,7 +509,7 @@ static CGFloat TZScreenScale;
...
@@ -509,7 +509,7 @@ static CGFloat TZScreenScale;
#pragma mark - Save photo
#pragma mark - Save photo
-
(
void
)
savePhotoWithImage
:(
UIImage
*
)
image
completion
:(
void
(
^
)())
completion
{
-
(
void
)
savePhotoWithImage
:(
UIImage
*
)
image
completion
:(
void
(
^
)(
NSError
*
error
))
completion
{
NSData
*
data
=
UIImageJPEGRepresentation
(
image
,
0
.
9
);
NSData
*
data
=
UIImageJPEGRepresentation
(
image
,
0
.
9
);
if
(
iOS9Later
)
{
// 这里有坑... iOS8系统下这个方法保存图片会失败
if
(
iOS9Later
)
{
// 这里有坑... iOS8系统下这个方法保存图片会失败
[[
PHPhotoLibrary
sharedPhotoLibrary
]
performChanges
:
^
{
[[
PHPhotoLibrary
sharedPhotoLibrary
]
performChanges
:
^
{
...
@@ -519,9 +519,12 @@ static CGFloat TZScreenScale;
...
@@ -519,9 +519,12 @@ static CGFloat TZScreenScale;
}
completionHandler
:
^
(
BOOL
success
,
NSError
*
_Nullable
error
)
{
}
completionHandler
:
^
(
BOOL
success
,
NSError
*
_Nullable
error
)
{
dispatch_sync
(
dispatch_get_main_queue
(),
^
{
dispatch_sync
(
dispatch_get_main_queue
(),
^
{
if
(
success
&&
completion
)
{
if
(
success
&&
completion
)
{
completion
();
completion
(
nil
);
}
else
if
(
error
)
{
}
else
if
(
error
)
{
NSLog
(
@"保存照片出错:%@"
,
error
.
localizedDescription
);
NSLog
(
@"保存照片出错:%@"
,
error
.
localizedDescription
);
if
(
completion
)
{
completion
(
error
);
}
}
}
});
});
}];
}];
...
@@ -532,9 +535,12 @@ static CGFloat TZScreenScale;
...
@@ -532,9 +535,12 @@ static CGFloat TZScreenScale;
#pragma clang diagnostic pop
#pragma clang diagnostic pop
if
(
error
)
{
if
(
error
)
{
NSLog
(
@"保存图片失败:%@"
,
error
.
localizedDescription
);
NSLog
(
@"保存图片失败:%@"
,
error
.
localizedDescription
);
if
(
completion
)
{
completion
(
error
);
}
}
else
{
}
else
{
if
(
completion
)
{
if
(
completion
)
{
completion
();
completion
(
nil
);
}
}
}
}
}];
}];
...
...
TZImagePickerController/TZImagePickerController/TZImagePickerController.m
View file @
1b52982a
...
@@ -17,6 +17,7 @@
...
@@ -17,6 +17,7 @@
@interface
TZImagePickerController
()
{
@interface
TZImagePickerController
()
{
NSTimer
*
_timer
;
NSTimer
*
_timer
;
UILabel
*
_tipLable
;
UILabel
*
_tipLable
;
UIButton
*
_settingBtn
;
BOOL
_pushToPhotoPickerVc
;
BOOL
_pushToPhotoPickerVc
;
UIButton
*
_progressHUD
;
UIButton
*
_progressHUD
;
...
@@ -103,7 +104,7 @@
...
@@ -103,7 +104,7 @@
if
(
!
[[
TZImageManager
manager
]
authorizationStatusAuthorized
])
{
if
(
!
[[
TZImageManager
manager
]
authorizationStatusAuthorized
])
{
_tipLable
=
[[
UILabel
alloc
]
init
];
_tipLable
=
[[
UILabel
alloc
]
init
];
_tipLable
.
frame
=
CGRectMake
(
8
,
0
,
self
.
view
.
tz_width
-
16
,
30
0
);
_tipLable
.
frame
=
CGRectMake
(
8
,
120
,
self
.
view
.
tz_width
-
16
,
6
0
);
_tipLable
.
textAlignment
=
NSTextAlignmentCenter
;
_tipLable
.
textAlignment
=
NSTextAlignmentCenter
;
_tipLable
.
numberOfLines
=
0
;
_tipLable
.
numberOfLines
=
0
;
_tipLable
.
font
=
[
UIFont
systemFontOfSize
:
16
];
_tipLable
.
font
=
[
UIFont
systemFontOfSize
:
16
];
...
@@ -114,6 +115,13 @@
...
@@ -114,6 +115,13 @@
_tipLable
.
text
=
tipText
;
_tipLable
.
text
=
tipText
;
[
self
.
view
addSubview
:
_tipLable
];
[
self
.
view
addSubview
:
_tipLable
];
_settingBtn
=
[
UIButton
buttonWithType
:
UIButtonTypeSystem
];
[
_settingBtn
setTitle
:[
NSBundle
tz_localizedStringForKey
:
@"Setting"
]
forState
:
UIControlStateNormal
];
_settingBtn
.
frame
=
CGRectMake
(
0
,
180
,
self
.
view
.
tz_width
,
44
);
_settingBtn
.
titleLabel
.
font
=
[
UIFont
systemFontOfSize
:
18
];
[
_settingBtn
addTarget
:
self
action
:
@selector
(
settingBtnClick
)
forControlEvents
:
UIControlEventTouchUpInside
];
[
self
.
view
addSubview
:
_settingBtn
];
_timer
=
[
NSTimer
scheduledTimerWithTimeInterval
:
0
.
2
target
:
self
selector
:
@selector
(
observeAuthrizationStatusChange
)
userInfo
:
nil
repeats
:
YES
];
_timer
=
[
NSTimer
scheduledTimerWithTimeInterval
:
0
.
2
target
:
self
selector
:
@selector
(
observeAuthrizationStatusChange
)
userInfo
:
nil
repeats
:
YES
];
}
else
{
}
else
{
[
self
pushToPhotoPickerVc
];
[
self
pushToPhotoPickerVc
];
...
@@ -164,6 +172,7 @@
...
@@ -164,6 +172,7 @@
if
([[
TZImageManager
manager
]
authorizationStatusAuthorized
])
{
if
([[
TZImageManager
manager
]
authorizationStatusAuthorized
])
{
[
self
pushToPhotoPickerVc
];
[
self
pushToPhotoPickerVc
];
[
_tipLable
removeFromSuperview
];
[
_tipLable
removeFromSuperview
];
[
_settingBtn
removeFromSuperview
];
[
_timer
invalidate
];
[
_timer
invalidate
];
_timer
=
nil
;
_timer
=
nil
;
}
}
...
@@ -285,6 +294,14 @@
...
@@ -285,6 +294,14 @@
[
TZImageManager
manager
].
sortAscendingByModificationDate
=
sortAscendingByModificationDate
;
[
TZImageManager
manager
].
sortAscendingByModificationDate
=
sortAscendingByModificationDate
;
}
}
-
(
void
)
settingBtnClick
{
if
(
iOS8Later
)
{
[[
UIApplication
sharedApplication
]
openURL
:[
NSURL
URLWithString
:
UIApplicationOpenSettingsURLString
]];
}
else
{
[[
UIApplication
sharedApplication
]
openURL
:[
NSURL
URLWithString
:
@"prefs:root=Privacy&path=PHOTOS"
]];
}
}
-
(
void
)
pushViewController
:(
UIViewController
*
)
viewController
animated
:(
BOOL
)
animated
{
-
(
void
)
pushViewController
:(
UIViewController
*
)
viewController
animated
:(
BOOL
)
animated
{
if
(
iOS7Later
)
viewController
.
automaticallyAdjustsScrollViewInsets
=
NO
;
if
(
iOS7Later
)
viewController
.
automaticallyAdjustsScrollViewInsets
=
NO
;
if
(
_timer
)
{
[
_timer
invalidate
];
_timer
=
nil
;}
if
(
_timer
)
{
[
_timer
invalidate
];
_timer
=
nil
;}
...
...
TZImagePickerController/TZImagePickerController/TZPhotoPickerController.m
View file @
1b52982a
...
@@ -418,7 +418,7 @@ static CGSize AssetGridThumbnailSize;
...
@@ -418,7 +418,7 @@ static CGSize AssetGridThumbnailSize;
-
(
void
)
takePhoto
{
-
(
void
)
takePhoto
{
AVAuthorizationStatus
authStatus
=
[
AVCaptureDevice
authorizationStatusForMediaType
:
AVMediaTypeVideo
];
AVAuthorizationStatus
authStatus
=
[
AVCaptureDevice
authorizationStatusForMediaType
:
AVMediaTypeVideo
];
if
((
authStatus
==
AVAuthorizationStatusRestricted
||
authStatus
==
AVAuthorizationStatusDenied
)
&&
iOS
8
Later
)
{
if
((
authStatus
==
AVAuthorizationStatusRestricted
||
authStatus
==
AVAuthorizationStatusDenied
)
&&
iOS
7
Later
)
{
#pragma clang diagnostic push
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
// 无权限 做一个友好的提示
// 无权限 做一个友好的提示
...
@@ -531,7 +531,7 @@ static CGSize AssetGridThumbnailSize;
...
@@ -531,7 +531,7 @@ static CGSize AssetGridThumbnailSize;
if
(
iOS8Later
)
{
if
(
iOS8Later
)
{
[[
UIApplication
sharedApplication
]
openURL
:[
NSURL
URLWithString
:
UIApplicationOpenSettingsURLString
]];
[[
UIApplication
sharedApplication
]
openURL
:[
NSURL
URLWithString
:
UIApplicationOpenSettingsURLString
]];
}
else
{
}
else
{
// [[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"prefs:root=Privacy&path=Photos
"]];
[[
UIApplication
sharedApplication
]
openURL
:[
NSURL
URLWithString
:
@"prefs:root=Privacy&path=CAMERA
"
]];
}
}
}
}
}
}
...
@@ -545,8 +545,10 @@ static CGSize AssetGridThumbnailSize;
...
@@ -545,8 +545,10 @@ static CGSize AssetGridThumbnailSize;
TZImagePickerController
*
imagePickerVc
=
(
TZImagePickerController
*
)
self
.
navigationController
;
TZImagePickerController
*
imagePickerVc
=
(
TZImagePickerController
*
)
self
.
navigationController
;
[
imagePickerVc
showProgressHUD
];
[
imagePickerVc
showProgressHUD
];
UIImage
*
image
=
[
info
objectForKey
:
UIImagePickerControllerOriginalImage
];
UIImage
*
image
=
[
info
objectForKey
:
UIImagePickerControllerOriginalImage
];
[[
TZImageManager
manager
]
savePhotoWithImage
:
image
completion
:
^
{
[[
TZImageManager
manager
]
savePhotoWithImage
:
image
completion
:
^
(
NSError
*
error
){
if
(
!
error
)
{
[
self
reloadPhotoArray
];
[
self
reloadPhotoArray
];
}
}];
}];
}
}
}
}
...
...
TZImagePickerController/ViewController.m
View file @
1b52982a
...
@@ -215,7 +215,7 @@
...
@@ -215,7 +215,7 @@
-
(
void
)
takePhoto
{
-
(
void
)
takePhoto
{
AVAuthorizationStatus
authStatus
=
[
AVCaptureDevice
authorizationStatusForMediaType
:
AVMediaTypeVideo
];
AVAuthorizationStatus
authStatus
=
[
AVCaptureDevice
authorizationStatusForMediaType
:
AVMediaTypeVideo
];
if
((
authStatus
==
AVAuthorizationStatusRestricted
||
authStatus
==
AVAuthorizationStatusDenied
)
&&
iOS
8
Later
)
{
if
((
authStatus
==
AVAuthorizationStatusRestricted
||
authStatus
==
AVAuthorizationStatusDenied
)
&&
iOS
7
Later
)
{
// 无权限 做一个友好的提示
// 无权限 做一个友好的提示
#pragma clang diagnostic push
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
...
@@ -245,7 +245,14 @@
...
@@ -245,7 +245,14 @@
[
tzImagePickerVc
showProgressHUD
];
[
tzImagePickerVc
showProgressHUD
];
UIImage
*
image
=
[
info
objectForKey
:
UIImagePickerControllerOriginalImage
];
UIImage
*
image
=
[
info
objectForKey
:
UIImagePickerControllerOriginalImage
];
// save photo and get asset / 保存图片,获取到asset
// save photo and get asset / 保存图片,获取到asset
[[
TZImageManager
manager
]
savePhotoWithImage
:
image
completion
:
^
{
[[
TZImageManager
manager
]
savePhotoWithImage
:
image
completion
:
^
(
NSError
*
error
){
if
(
error
)
{
// 如果保存失败,基本是没有相册权限导致的...
[
tzImagePickerVc
hideProgressHUD
];
NSLog
(
@"图片保存失败 %@"
,
error
);
UIAlertView
*
alert
=
[[
UIAlertView
alloc
]
initWithTitle
:
@"无法保存图片"
message
:
@"请在iPhone的""设置-隐私-相册""中允许访问相册"
delegate
:
self
cancelButtonTitle
:
@"取消"
otherButtonTitles
:
@"设置"
,
nil
];
alert
.
tag
=
1
;
[
alert
show
];
}
else
{
[[
TZImageManager
manager
]
getCameraRollAlbum
:
NO
allowPickingImage
:
YES
completion
:^
(
TZAlbumModel
*
model
)
{
[[
TZImageManager
manager
]
getCameraRollAlbum
:
NO
allowPickingImage
:
YES
completion
:^
(
TZAlbumModel
*
model
)
{
[[
TZImageManager
manager
]
getAssetsFromFetchResult
:
model
.
result
allowPickingVideo
:
NO
allowPickingImage
:
YES
completion
:^
(
NSArray
<
TZAssetModel
*>
*
models
)
{
[[
TZImageManager
manager
]
getAssetsFromFetchResult
:
model
.
result
allowPickingVideo
:
NO
allowPickingImage
:
YES
completion
:^
(
NSArray
<
TZAssetModel
*>
*
models
)
{
[
tzImagePickerVc
hideProgressHUD
];
[
tzImagePickerVc
hideProgressHUD
];
...
@@ -258,6 +265,7 @@
...
@@ -258,6 +265,7 @@
[
_collectionView
reloadData
];
[
_collectionView
reloadData
];
}];
}];
}];
}];
}
}];
}];
}
}
}
}
...
@@ -291,7 +299,11 @@
...
@@ -291,7 +299,11 @@
if
(
iOS8Later
)
{
if
(
iOS8Later
)
{
[[
UIApplication
sharedApplication
]
openURL
:[
NSURL
URLWithString
:
UIApplicationOpenSettingsURLString
]];
[[
UIApplication
sharedApplication
]
openURL
:[
NSURL
URLWithString
:
UIApplicationOpenSettingsURLString
]];
}
else
{
}
else
{
// [[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"prefs:root=Privacy&path=Photos"]];
if
(
alertView
.
tag
==
1
)
{
[[
UIApplication
sharedApplication
]
openURL
:[
NSURL
URLWithString
:
@"prefs:root=Privacy&path=PHOTOS"
]];
}
else
{
[[
UIApplication
sharedApplication
]
openURL
:[
NSURL
URLWithString
:
@"prefs:root=Privacy&path=CAMERA"
]];
}
}
}
}
}
}
}
...
...
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