扫码 · TonyScript/Coding-iOS@ffe7527 · GitHub
Skip to content

Commit ffe7527

Browse files
committed
扫码
1 parent b86d4d3 commit ffe7527

8 files changed

Lines changed: 102 additions & 14 deletions

File tree

Coding_iOS.xcodeproj/project.pbxproj

Lines changed: 8 additions & 0 deletions

Coding_iOS/Controllers/RootControllers/Project_RootViewController.m

Lines changed: 52 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@
3030
#import "pop.h"
3131
#import "FRDLivelyButton.h"
3232
#import "StartImagesManager.h"
33+
#import "ZXScanCodeViewController.h"
34+
#import "WebViewController.h"
3335

3436
@interface Project_RootViewController ()<UISearchBarDelegate, UITableViewDataSource, UITableViewDelegate>
3537
@property (strong, nonatomic) NSMutableDictionary *myProjectsDict;
@@ -98,7 +100,8 @@ - (void)viewDidLoad
98100
//添加搜索框
99101
_mySearchBar = ({
100102
MainSearchBar *searchBar = [[MainSearchBar alloc] initWithFrame:CGRectMake(60,7, kScreen_Width-115, 31)];
101-
[searchBar setPlaceholder:@"项目/任务/讨论/冒泡等"];
103+
[searchBar setContentMode:UIViewContentModeLeft];
104+
[searchBar setPlaceholder:@"搜索"];
102105
searchBar.delegate = self;
103106
searchBar.layer.cornerRadius=15;
104107
searchBar.layer.masksToBounds=TRUE;
@@ -108,6 +111,7 @@ - (void)viewDidLoad
108111
[searchBar setTintColor:[UIColor whiteColor]];
109112
[searchBar insertBGColor:[UIColor colorWithHexString:@"0xffffff"]];
110113
[searchBar setHeight:30];
114+
[searchBar.scanBtn addTarget:self action:@selector(scanBtnClicked) forControlEvents:UIControlEventTouchUpInside];
111115
searchBar;
112116
});
113117
__weak typeof(_myCarousel) weakCarousel = _myCarousel;
@@ -601,6 +605,53 @@ - (void)updateFilteredContentForSearchString:(NSString *)searchString{
601605
self.searchResults = [[self.searchResults filteredArrayUsingPredicate:finalCompoundPredicate] mutableCopy];
602606
}
603607

608+
#pragma mark scan QR-Code
609+
- (void)scanBtnClicked{
610+
ZXScanCodeViewController *vc = [ZXScanCodeViewController new];
611+
__weak typeof(self) weakSelf = self;
612+
vc.scanResultBlock = ^(ZXScanCodeViewController *vc, NSString *resultStr){
613+
[weakSelf dealWithScanResult:resultStr ofVC:vc];
614+
};
615+
[self.navigationController pushViewController:vc animated:YES];
616+
}
617+
618+
- (void)dealWithScanResult:(NSString *)resultStr ofVC:(ZXScanCodeViewController *)vc{
619+
UIViewController *nextVC = [BaseViewController analyseVCFromLinkStr:resultStr];
620+
NSURL *URL = [NSURL URLWithString:resultStr];
621+
if (nextVC) {
622+
[self.navigationController pushViewController:nextVC animated:YES];
623+
}else if (URL){
624+
UIAlertView *alertV = [UIAlertView bk_alertViewWithTitle:@"提示" message:[NSString stringWithFormat:@"可能存在风险,是否打开此链接?\n%@", resultStr]];
625+
[alertV bk_setCancelButtonWithTitle:@"取消" handler:nil];
626+
[alertV bk_addButtonWithTitle:@"打开链接" handler:nil];
627+
[alertV bk_setWillDismissBlock:^(UIAlertView *al, NSInteger index) {
628+
if (index == 1) {
629+
[[UIApplication sharedApplication] openURL:URL];
630+
}
631+
[self.navigationController popViewControllerAnimated:YES];
632+
}];
633+
[alertV show];
634+
}else if (resultStr.length > 0){
635+
UIAlertView *alertV = [UIAlertView bk_alertViewWithTitle:@"提示" message:[NSString stringWithFormat:@"已识别此二维码内容为:\n%@", resultStr]];
636+
[alertV bk_setCancelButtonWithTitle:@"取消" handler:nil];
637+
[alertV bk_addButtonWithTitle:@"复制链接" handler:nil];
638+
[alertV bk_setWillDismissBlock:^(UIAlertView *al, NSInteger index) {
639+
if (index == 1) {
640+
[[UIPasteboard generalPasteboard] setString:resultStr];
641+
}
642+
[self.navigationController popViewControllerAnimated:YES];
643+
}];
644+
[alertV show];
604645

646+
}else{
647+
UIAlertView *alertV = [UIAlertView bk_alertViewWithTitle:@"无效条码" message:@"未检测到条码信息"];
648+
[alertV bk_addButtonWithTitle:@"重试" handler:^{
649+
if (![vc isScaning]) {
650+
[vc startScan];
651+
}
652+
}];
653+
[alertV show];
654+
}
655+
}
605656

606657
@end

Coding_iOS/Controllers/WebViewController.m

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,10 @@ @interface WebViewController ()<UIWebViewDelegate>
2323
@implementation WebViewController
2424

2525
+ (instancetype)webVCWithUrlStr:(NSString *)curUrlStr{
26+
if (!curUrlStr || curUrlStr.length <= 0 || [curUrlStr hasPrefix:kCodingAppScheme]) {
27+
return nil;
28+
}
29+
2630
// NSString *tasksRegexStr = @"/user/tasks[\?]?";
2731
NSString *tasksRegexStr = @"/user/tasks";
2832
if ([curUrlStr captureComponentsMatchedByRegex:tasksRegexStr].count > 0){
@@ -32,9 +36,7 @@ + (instancetype)webVCWithUrlStr:(NSString *)curUrlStr{
3236
return nil;
3337
}
3438
}
35-
if (!curUrlStr || curUrlStr.length <= 0 || [curUrlStr hasPrefix:kCodingAppScheme]) {
36-
return nil;
37-
}
39+
3840
NSString *proName = [NSString stringWithFormat:@"/%@.app/", [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleName"]];
3941
NSURL *curUrl;
4042
if (![curUrlStr hasPrefix:@"/"] || [curUrlStr rangeOfString:proName].location != NSNotFound) {

Coding_iOS/Ease_2FA/Controllers/ZXScanCodeViewController.m

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,8 @@ - (void)viewDidAppear:(BOOL)animated {
5050
[super viewDidAppear:animated];
5151
if (!_videoPreviewLayer) {
5252
[self configUI];
53+
}else{
54+
[self startScan];
5355
}
5456
}
5557

@@ -188,8 +190,7 @@ - (void)analyseResult:(AVMetadataMachineReadableCodeObject *)result{
188190
return;
189191
}
190192
//停止扫描
191-
[self.videoPreviewLayer.session stopRunning];
192-
[self scanLineStopAction];
193+
[self stopScan];
193194
//震动反馈
194195
AudioServicesPlaySystemSound(kSystemSoundID_Vibrate);
195196
//交给 block 处理
@@ -212,8 +213,7 @@ -(void)clickRightBarButton:(UIBarButtonItem*)item{
212213
return;
213214
}
214215
//停止扫描
215-
[self.videoPreviewLayer.session stopRunning];
216-
[self scanLineStopAction];
216+
[self stopScan];
217217

218218
UIImagePickerController *picker = [UIImagePickerController new];
219219
picker.delegate = self;
@@ -223,7 +223,15 @@ -(void)clickRightBarButton:(UIBarButtonItem*)item{
223223
}
224224

225225
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary<NSString *,id> *)info{
226-
[picker dismissViewControllerAnimated:YES completion:nil];
226+
[picker dismissViewControllerAnimated:YES completion:^{
227+
[self handleImageInfo:info];
228+
}];
229+
}
230+
231+
- (void)handleImageInfo:(NSDictionary *)info{
232+
//停止扫描
233+
[self stopScan];
234+
227235
UIImage *image = [info objectForKey:UIImagePickerControllerEditedImage];
228236
if (!image){
229237
image = [info objectForKey:UIImagePickerControllerOriginalImage];
@@ -243,6 +251,7 @@ - (void)imagePickerController:(UIImagePickerController *)picker didFinishPicking
243251
_scanResultBlock(self, resultStr);
244252
}
245253
}
254+
246255
- (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker{
247256
[picker dismissViewControllerAnimated:YES completion:nil];
248257
}
197 Bytes
Loading
273 Bytes
Loading

Coding_iOS/Views/Search/CategorySearchBar.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,5 @@ typedef void(^SelectBlock)();
1616

1717

1818
@interface MainSearchBar : UISearchBar
19+
@property (strong, nonatomic) UIButton *scanBtn;
1920
@end

Coding_iOS/Views/Search/CategorySearchBar.m

Lines changed: 22 additions & 5 deletions

0 commit comments

Comments
 (0)