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
920725d4
Commit
920725d4
authored
Oct 18, 2016
by
banchichen
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
优化跳转去设置页面的代码
parent
c87edb80
Changes
7
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
43 additions
and
11 deletions
+43
-11
TZImagePickerController/TZImagePickerController/TZImageManager.h
...PickerController/TZImagePickerController/TZImageManager.h
+1
-0
TZImagePickerController/TZImagePickerController/TZImageManager.m
...PickerController/TZImagePickerController/TZImageManager.m
+6
-2
TZImagePickerController/TZImagePickerController/TZImagePickerController.bundle/en.lproj/Localizable.strings
...ImagePickerController.bundle/en.lproj/Localizable.strings
+0
-0
TZImagePickerController/TZImagePickerController/TZImagePickerController.bundle/zh-Hans.lproj/Localizable.strings
...PickerController.bundle/zh-Hans.lproj/Localizable.strings
+0
-0
TZImagePickerController/TZImagePickerController/TZImagePickerController.m
...troller/TZImagePickerController/TZImagePickerController.m
+8
-1
TZImagePickerController/TZImagePickerController/TZPhotoPickerController.m
...troller/TZImagePickerController/TZPhotoPickerController.m
+8
-1
TZImagePickerController/ViewController.m
TZImagePickerController/ViewController.m
+20
-7
No files found.
TZImagePickerController/TZImagePickerController/TZImageManager.h
View file @
920725d4
...
@@ -33,6 +33,7 @@
...
@@ -33,6 +33,7 @@
/// Return YES if Authorized 返回YES如果得到了授权
/// Return YES if Authorized 返回YES如果得到了授权
-
(
BOOL
)
authorizationStatusAuthorized
;
-
(
BOOL
)
authorizationStatusAuthorized
;
-
(
NSInteger
)
authorizationStatus
;
/// Get Album 获得相册/相册数组
/// Get Album 获得相册/相册数组
-
(
void
)
getCameraRollAlbum
:(
BOOL
)
allowPickingVideo
allowPickingImage
:(
BOOL
)
allowPickingImage
completion
:(
void
(
^
)(
TZAlbumModel
*
model
))
completion
;
-
(
void
)
getCameraRollAlbum
:(
BOOL
)
allowPickingVideo
allowPickingImage
:(
BOOL
)
allowPickingImage
completion
:(
void
(
^
)(
TZAlbumModel
*
model
))
completion
;
...
...
TZImagePickerController/TZImagePickerController/TZImageManager.m
View file @
920725d4
...
@@ -61,12 +61,16 @@ static CGFloat TZScreenScale;
...
@@ -61,12 +61,16 @@ static CGFloat TZScreenScale;
/// Return YES if Authorized 返回YES如果得到了授权
/// Return YES if Authorized 返回YES如果得到了授权
-
(
BOOL
)
authorizationStatusAuthorized
{
-
(
BOOL
)
authorizationStatusAuthorized
{
return
[
self
authorizationStatus
]
==
3
;
}
-
(
NSInteger
)
authorizationStatus
{
if
(
iOS8Later
)
{
if
(
iOS8Later
)
{
if
([
PHPhotoLibrary
authorizationStatus
]
==
PHAuthorizationStatusAuthorized
)
return
YES
;
return
[
PHPhotoLibrary
authorizationStatus
]
;
}
else
{
}
else
{
#pragma clang diagnostic push
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
if
([
ALAssetsLibrary
authorizationStatus
]
==
ALAuthorizationStatusAuthorized
)
return
YES
;
return
[
ALAssetsLibrary
authorizationStatus
]
;
#pragma clang diagnostic pop
#pragma clang diagnostic pop
}
}
return
NO
;
return
NO
;
...
...
TZImagePickerController/TZImagePickerController/TZImagePickerController.bundle/en.lproj/Localizable.strings
View file @
920725d4
B
"OK" = "OK";
B
"OK" = "OK";
...
...
TZImagePickerController/TZImagePickerController/TZImagePickerController.bundle/zh-Hans.lproj/Localizable.strings
View file @
920725d4
B
"OK" = "确定";
B
"OK" = "确定";
...
...
TZImagePickerController/TZImagePickerController/TZImagePickerController.m
View file @
920725d4
...
@@ -339,7 +339,14 @@
...
@@ -339,7 +339,14 @@
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"
]];
NSURL
*
privacyUrl
=
[
NSURL
URLWithString
:
@"prefs:root=Privacy&path=PHOTOS"
];
if
([[
UIApplication
sharedApplication
]
canOpenURL
:
privacyUrl
])
{
[[
UIApplication
sharedApplication
]
openURL
:
privacyUrl
];
}
else
{
NSString
*
message
=
[
NSBundle
tz_localizedStringForKey
:
@"Can not jump to the privacy settings page, please go to the settings page by self, thank you"
];
UIAlertView
*
alert
=
[[
UIAlertView
alloc
]
initWithTitle
:[
NSBundle
tz_localizedStringForKey
:
@"Sorry"
]
message
:
message
delegate
:
nil
cancelButtonTitle
:
[
NSBundle
tz_localizedStringForKey
:
@"OK"
]
otherButtonTitles
:
nil
];
[
alert
show
];
}
}
}
}
}
...
...
TZImagePickerController/TZImagePickerController/TZPhotoPickerController.m
View file @
920725d4
...
@@ -552,7 +552,14 @@ static CGSize AssetGridThumbnailSize;
...
@@ -552,7 +552,14 @@ 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=CAMERA"
]];
NSURL
*
privacyUrl
=
[
NSURL
URLWithString
:
@"prefs:root=Privacy&path=CAMERA"
];
if
([[
UIApplication
sharedApplication
]
canOpenURL
:
privacyUrl
])
{
[[
UIApplication
sharedApplication
]
openURL
:
privacyUrl
];
}
else
{
NSString
*
message
=
[
NSBundle
tz_localizedStringForKey
:
@"Can not jump to the privacy settings page, please go to the settings page by self, thank you"
];
UIAlertView
*
alert
=
[[
UIAlertView
alloc
]
initWithTitle
:[
NSBundle
tz_localizedStringForKey
:
@"Sorry"
]
message
:
message
delegate
:
nil
cancelButtonTitle
:
[
NSBundle
tz_localizedStringForKey
:
@"OK"
]
otherButtonTitles
:
nil
];
[
alert
show
];
}
}
}
}
}
}
}
...
...
TZImagePickerController/ViewController.m
View file @
920725d4
...
@@ -238,12 +238,21 @@
...
@@ -238,12 +238,21 @@
-
(
void
)
takePhoto
{
-
(
void
)
takePhoto
{
AVAuthorizationStatus
authStatus
=
[
AVCaptureDevice
authorizationStatusForMediaType
:
AVMediaTypeVideo
];
AVAuthorizationStatus
authStatus
=
[
AVCaptureDevice
authorizationStatusForMediaType
:
AVMediaTypeVideo
];
if
((
authStatus
==
AVAuthorizationStatusRestricted
||
authStatus
==
AVAuthorizationStatusDenied
)
&&
iOS7Later
)
{
if
((
authStatus
==
AVAuthorizationStatusRestricted
||
authStatus
==
AVAuthorizationStatusDenied
)
&&
iOS7Later
)
{
// 无权限 做一个友好的提示
// 无
相机
权限 做一个友好的提示
#pragma clang diagnostic push
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
UIAlertView
*
alert
=
[[
UIAlertView
alloc
]
initWithTitle
:
@"无法使用相机"
message
:
@"请在iPhone的""设置-隐私-相机""中允许访问相机"
delegate
:
self
cancelButtonTitle
:
@"取消"
otherButtonTitles
:
@"设置"
,
nil
];
UIAlertView
*
alert
=
[[
UIAlertView
alloc
]
initWithTitle
:
@"无法使用相机"
message
:
@"请在iPhone的""设置-隐私-相机""中允许访问相机"
delegate
:
self
cancelButtonTitle
:
@"取消"
otherButtonTitles
:
@"设置"
,
nil
];
[
alert
show
];
[
alert
show
];
#define push @#clang diagnostic pop
#define push @#clang diagnostic pop
// 拍照之前还需要检查相册权限
}
else
if
([[
TZImageManager
manager
]
authorizationStatus
]
==
2
)
{
// 已被拒绝,没有相册权限,将无法保存拍的照片
UIAlertView
*
alert
=
[[
UIAlertView
alloc
]
initWithTitle
:
@"无法访问相册"
message
:
@"请在iPhone的""设置-隐私-相册""中允许访问相册"
delegate
:
self
cancelButtonTitle
:
@"取消"
otherButtonTitles
:
@"设置"
,
nil
];
alert
.
tag
=
1
;
[
alert
show
];
}
else
if
([[
TZImageManager
manager
]
authorizationStatus
]
==
0
)
{
// 正在弹框询问用户是否允许访问相册,监听权限状态
dispatch_after
(
dispatch_time
(
DISPATCH_TIME_NOW
,
(
int64_t
)(
0
.
1
*
NSEC_PER_SEC
)),
dispatch_get_main_queue
(),
^
{
return
[
self
takePhoto
];
});
}
else
{
// 调用相机
}
else
{
// 调用相机
UIImagePickerControllerSourceType
sourceType
=
UIImagePickerControllerSourceTypeCamera
;
UIImagePickerControllerSourceType
sourceType
=
UIImagePickerControllerSourceTypeCamera
;
if
([
UIImagePickerController
isSourceTypeAvailable
:
UIImagePickerControllerSourceTypeCamera
])
{
if
([
UIImagePickerController
isSourceTypeAvailable
:
UIImagePickerControllerSourceTypeCamera
])
{
...
@@ -268,12 +277,9 @@
...
@@ -268,12 +277,9 @@
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
:
^
(
NSError
*
error
){
[[
TZImageManager
manager
]
savePhotoWithImage
:
image
completion
:
^
(
NSError
*
error
){
if
(
error
)
{
// 如果保存失败,基本是没有相册权限导致的...
if
(
error
)
{
[
tzImagePickerVc
hideProgressHUD
];
[
tzImagePickerVc
hideProgressHUD
];
NSLog
(
@"图片保存失败 %@"
,
error
);
NSLog
(
@"图片保存失败 %@"
,
error
);
UIAlertView
*
alert
=
[[
UIAlertView
alloc
]
initWithTitle
:
@"无法保存图片"
message
:
@"请在iPhone的""设置-隐私-相册""中允许访问相册"
delegate
:
self
cancelButtonTitle
:
@"取消"
otherButtonTitles
:
@"设置"
,
nil
];
alert
.
tag
=
1
;
[
alert
show
];
}
else
{
}
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
)
{
...
@@ -321,10 +327,17 @@
...
@@ -321,10 +327,17 @@
if
(
iOS8Later
)
{
if
(
iOS8Later
)
{
[[
UIApplication
sharedApplication
]
openURL
:[
NSURL
URLWithString
:
UIApplicationOpenSettingsURLString
]];
[[
UIApplication
sharedApplication
]
openURL
:[
NSURL
URLWithString
:
UIApplicationOpenSettingsURLString
]];
}
else
{
}
else
{
NSURL
*
privacyUrl
;
if
(
alertView
.
tag
==
1
)
{
if
(
alertView
.
tag
==
1
)
{
[[
UIApplication
sharedApplication
]
openURL
:[
NSURL
URLWithString
:
@"prefs:root=Privacy&path=PHOTOS"
]
];
privacyUrl
=
[
NSURL
URLWithString
:
@"prefs:root=Privacy&path=PHOTOS"
];
}
else
{
}
else
{
[[
UIApplication
sharedApplication
]
openURL
:[
NSURL
URLWithString
:
@"prefs:root=Privacy&path=CAMERA"
]];
privacyUrl
=
[
NSURL
URLWithString
:
@"prefs:root=Privacy&path=CAMERA"
];
}
if
([[
UIApplication
sharedApplication
]
canOpenURL
:
privacyUrl
])
{
[[
UIApplication
sharedApplication
]
openURL
:
privacyUrl
];
}
else
{
UIAlertView
*
alert
=
[[
UIAlertView
alloc
]
initWithTitle
:
@"抱歉"
message
:
@"无法跳转到隐私设置页面,请手动前往设置页面,谢谢"
delegate
:
nil
cancelButtonTitle
:
@"确定"
otherButtonTitles
:
nil
];
[
alert
show
];
}
}
}
}
}
}
...
...
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