forked from kingsic/SGQRCode
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathViewController.m
executable file
·112 lines (91 loc) · 4.27 KB
/
ViewController.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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
//
// ViewController.m
// SGQRCodeExample
//
// Created by kingsic on 16/8/25.
// Copyright © 2016年 kingsic. All rights reserved.
//
#import "ViewController.h"
#import <AVFoundation/AVFoundation.h>
#import "WBQRCodeVC.h"
#import "WCQRCodeVC.h"
@interface ViewController () <UITableViewDelegate, UITableViewDataSource>
@property (weak, nonatomic) IBOutlet UITableView *tableView;
@property (nonatomic, strong) NSArray *dataList;
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
[self configuration];
}
- (void)configuration {
_dataList = @[@"WBQRCodeVC (pop 逻辑处理)", @"WCQRCodeVC (popToRoot 逻辑处理)"];
[_tableView registerClass:[UITableViewCell class] forCellReuseIdentifier:@"cell"];
_tableView.tableFooterView = [[UIView alloc] initWithFrame:CGRectZero];
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return _dataList.count;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell"];
cell.backgroundColor = [UIColor clearColor];
cell.selectionStyle = UITableViewCellSelectionStyleNone;
cell.textLabel.text = _dataList[indexPath.row];
return cell;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
if (indexPath.row == 0) {
WBQRCodeVC *WBVC = [[WBQRCodeVC alloc] init];
[self QRCodeScanVC:WBVC];
}
if (indexPath.row == 1) {
WCQRCodeVC *WCVC = [[WCQRCodeVC alloc] init];
[self QRCodeScanVC:WCVC];
}
}
- (void)QRCodeScanVC:(UIViewController *)scanVC {
AVCaptureDevice *device = [AVCaptureDevice defaultDeviceWithMediaType:AVMediaTypeVideo];
if (device) {
AVAuthorizationStatus status = [AVCaptureDevice authorizationStatusForMediaType:AVMediaTypeVideo];
switch (status) {
case AVAuthorizationStatusNotDetermined: {
[AVCaptureDevice requestAccessForMediaType:AVMediaTypeVideo completionHandler:^(BOOL granted) {
if (granted) {
dispatch_sync(dispatch_get_main_queue(), ^{
[self.navigationController pushViewController:scanVC animated:YES];
});
NSLog(@"用户第一次同意了访问相机权限 - - %@", [NSThread currentThread]);
} else {
NSLog(@"用户第一次拒绝了访问相机权限 - - %@", [NSThread currentThread]);
}
}];
break;
}
case AVAuthorizationStatusAuthorized: {
[self.navigationController pushViewController:scanVC animated:YES];
break;
}
case AVAuthorizationStatusDenied: {
UIAlertController *alertC = [UIAlertController alertControllerWithTitle:@"温馨提示" message:@"请去-> [设置 - 隐私 - 相机 - SGQRCodeExample] 打开访问开关" preferredStyle:(UIAlertControllerStyleAlert)];
UIAlertAction *alertA = [UIAlertAction actionWithTitle:@"确定" style:(UIAlertActionStyleDefault) handler:^(UIAlertAction * _Nonnull action) {
}];
[alertC addAction:alertA];
[self presentViewController:alertC animated:YES completion:nil];
break;
}
case AVAuthorizationStatusRestricted: {
NSLog(@"因为系统原因, 无法访问相册");
break;
}
default:
break;
}
return;
}
UIAlertController *alertC = [UIAlertController alertControllerWithTitle:@"温馨提示" message:@"未检测到您的摄像头" preferredStyle:(UIAlertControllerStyleAlert)];
UIAlertAction *alertA = [UIAlertAction actionWithTitle:@"确定" style:(UIAlertActionStyleDefault) handler:^(UIAlertAction * _Nonnull action) {
}];
[alertC addAction:alertA];
[self presentViewController:alertC animated:YES completion:nil];
}
@end