-
Notifications
You must be signed in to change notification settings - Fork 1.3k
/
Copy pathHelper.m
61 lines (53 loc) · 2.09 KB
/
Helper.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
//
// Helper.m
// Coding_iOS
//
// Created by Elf Sundae on 14-12-22.
// Copyright (c) 2014年 Coding. All rights reserved.
//
#import "Helper.h"
@import AVFoundation;
@implementation Helper
+ (BOOL)checkPhotoLibraryAuthorizationStatus
{
PHAuthorizationStatus authStatus = PHPhotoLibrary.authorizationStatus;
if (authStatus == PHAuthorizationStatusRestricted ||
authStatus == PHAuthorizationStatusDenied) {
[self showSettingAlertStr:@"请在iPhone的“设置->隐私->照片”中打开本应用的访问权限"];
return NO;
}
return YES;
}
+ (BOOL)checkCameraAuthorizationStatus
{
if (![UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]) {
kTipAlert(@"该设备不支持拍照");
return NO;
}
if ([AVCaptureDevice respondsToSelector:@selector(authorizationStatusForMediaType:)]) {
AVAuthorizationStatus authStatus = [AVCaptureDevice authorizationStatusForMediaType:AVMediaTypeVideo];
if (AVAuthorizationStatusDenied == authStatus ||
AVAuthorizationStatusRestricted == authStatus) {
[self showSettingAlertStr:@"请在iPhone的“设置->隐私->相机”中打开本应用的访问权限"];
return NO;
}
}
return YES;
}
+ (void)showSettingAlertStr:(NSString *)tipStr{
//iOS8+系统下可跳转到‘设置’页面,否则只弹出提示窗即可
if (floor(NSFoundationVersionNumber) > NSFoundationVersionNumber_iOS_7_1) {
[[UIAlertController ea_alertViewWithTitle:@"提示" message:tipStr buttonTitles:@[@"设置"] destructiveTitle:nil cancelTitle:@"取消" andDidDismissBlock:^(UIAlertAction *action, NSInteger index) {
if (index == 0) {
UIApplication *app = [UIApplication sharedApplication];
NSURL *settingsURL = [NSURL URLWithString:UIApplicationOpenSettingsURLString];
if ([app canOpenURL:settingsURL]) {
[app openURL:settingsURL];
}
}
}] show];
}else{
kTipAlert(@"%@", tipStr);
}
}
@end