Skip to content

Commit ffe7527

Browse files
committed
扫码
1 parent b86d4d3 commit ffe7527

File tree

8 files changed

+102
-14
lines changed

8 files changed

+102
-14
lines changed

Coding_iOS.xcodeproj/project.pbxproj

+8
Original file line numberDiff line numberDiff line change
@@ -479,6 +479,8 @@
479479
4EB52F251C76C16300B5EBEA /* EditColorViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 4EB52F241C76C16300B5EBEA /* EditColorViewController.m */; };
480480
4EB52F281C76ED4A00B5EBEA /* TagColorEditCell.m in Sources */ = {isa = PBXBuildFile; fileRef = 4EB52F271C76ED4A00B5EBEA /* TagColorEditCell.m */; };
481481
4EB52F2B1C76ED7000B5EBEA /* TagColorDisplayCell.m in Sources */ = {isa = PBXBuildFile; fileRef = 4EB52F2A1C76ED7000B5EBEA /* TagColorDisplayCell.m */; };
482+
4EB52F2E1C77138A00B5EBEA /* button_scan@2x.png in Resources */ = {isa = PBXBuildFile; fileRef = 4EB52F2C1C77138A00B5EBEA /* button_scan@2x.png */; };
483+
4EB52F2F1C77138A00B5EBEA /* button_scan@3x.png in Resources */ = {isa = PBXBuildFile; fileRef = 4EB52F2D1C77138A00B5EBEA /* button_scan@3x.png */; };
482484
4EB5A9421BF1DB4600C23AC3 /* libSocialSinaSSO.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 4EB5A9341BF1DB4600C23AC3 /* libSocialSinaSSO.a */; };
483485
4EB5A9431BF1DB4600C23AC3 /* libWeiboSDK.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 4EB5A9351BF1DB4600C23AC3 /* libWeiboSDK.a */; };
484486
4EB5A9441BF1DB4600C23AC3 /* WeiboSDK.bundle in Resources */ = {isa = PBXBuildFile; fileRef = 4EB5A93F1BF1DB4600C23AC3 /* WeiboSDK.bundle */; };
@@ -1773,6 +1775,8 @@
17731775
4EB52F271C76ED4A00B5EBEA /* TagColorEditCell.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = TagColorEditCell.m; sourceTree = "<group>"; };
17741776
4EB52F291C76ED7000B5EBEA /* TagColorDisplayCell.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = TagColorDisplayCell.h; sourceTree = "<group>"; };
17751777
4EB52F2A1C76ED7000B5EBEA /* TagColorDisplayCell.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = TagColorDisplayCell.m; sourceTree = "<group>"; };
1778+
4EB52F2C1C77138A00B5EBEA /* button_scan@2x.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "button_scan@2x.png"; sourceTree = "<group>"; };
1779+
4EB52F2D1C77138A00B5EBEA /* button_scan@3x.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "button_scan@3x.png"; sourceTree = "<group>"; };
17761780
4EB5A9341BF1DB4600C23AC3 /* libSocialSinaSSO.a */ = {isa = PBXFileReference; lastKnownFileType = archive.ar; path = libSocialSinaSSO.a; sourceTree = "<group>"; };
17771781
4EB5A9351BF1DB4600C23AC3 /* libWeiboSDK.a */ = {isa = PBXFileReference; lastKnownFileType = archive.ar; path = libWeiboSDK.a; sourceTree = "<group>"; };
17781782
4EB5A9361BF1DB4600C23AC3 /* UMSocialSinaSSOHandler.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = UMSocialSinaSSOHandler.h; sourceTree = "<group>"; };
@@ -4531,6 +4535,8 @@
45314535
4EC4800F1C2A909D005F1772 /* register_step_un@2x.png */,
45324536
4EC480101C2A909D005F1772 /* register_step_un@3x.png */,
45334537
4ED6181E1C3A732F0017946C /* button_arrow_left@2x.png */,
4538+
4EB52F2C1C77138A00B5EBEA /* button_scan@2x.png */,
4539+
4EB52F2D1C77138A00B5EBEA /* button_scan@3x.png */,
45344540
);
45354541
path = Images;
45364542
sourceTree = "<group>";
@@ -5614,6 +5620,7 @@
56145620
D0C447CD1C02DB6700DC1C4B /* pop_Message@3x.png in Resources */,
56155621
D0C447FB1C02DCA200DC1C4B /* settingBtn_Nav@2x.png in Resources */,
56165622
4E63840B1B33F9B400D98648 /* comment_bg@2x.png in Resources */,
5623+
4EB52F2E1C77138A00B5EBEA /* button_scan@2x.png in Resources */,
56175624
8E97CEA31A0C7E26006F9AD7 /* coding_emoji_12@2x.png in Resources */,
56185625
4EF17EE81B3C3112003CDD2D /* intro_icon_6@2x.png in Resources */,
56195626
D0C447F71C02DCA200DC1C4B /* filtertBtn_normal_Nav@2x.png in Resources */,
@@ -5816,6 +5823,7 @@
58165823
B9A00D7F1ACA3A05008BA008 /* ProjectSetting.storyboard in Resources */,
58175824
8EA6D19219E240C40076D59C /* timeline_icon_unread@2x.png in Resources */,
58185825
4E095A6D1B69F920008DC439 /* banner__page_selected@2x.png in Resources */,
5826+
4EB52F2F1C77138A00B5EBEA /* button_scan@3x.png in Resources */,
58195827
4E86FEE51BB556D6005E53F3 /* tipIcon_ProjectFileComment@2x.png in Resources */,
58205828
4E217F141A70EDC700F6DF88 /* SVWebViewControllerActivitySafari-iPad@2x.png in Resources */,
58215829
4EF91F641B00B62B0021C951 /* icon_not_locationed@2x.png in Resources */,

Coding_iOS/Controllers/RootControllers/Project_RootViewController.m

+52-1
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

+5-3
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

+14-5
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
}

Coding_iOS/Images/button_scan@2x.png

197 Bytes
Loading

Coding_iOS/Images/button_scan@3x.png

273 Bytes
Loading

Coding_iOS/Views/Search/CategorySearchBar.h

+1
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

+22-5
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ -(UIButton*)iconBtn{
6565

6666

6767

68+
6869
#pragma mark -- event
6970
-(void)selectCategoryAction{
7071
_curBlock();
@@ -75,18 +76,34 @@ -(void)setSearchCategory:(NSString*)title{
7576
}
7677
@end
7778

78-
7979
@implementation MainSearchBar
80+
81+
- (UIButton *)scanBtn{
82+
if (!_scanBtn) {
83+
_scanBtn = [UIButton new];
84+
[_scanBtn setImage:[UIImage imageNamed:@"button_scan"] forState:UIControlStateNormal];
85+
[self addSubview:_scanBtn];
86+
[_scanBtn mas_makeConstraints:^(MASConstraintMaker *make) {
87+
make.size.mas_equalTo(CGSizeMake(50, 30));
88+
make.centerY.equalTo(self);
89+
make.right.equalTo(self);
90+
}];
91+
}
92+
return _scanBtn;
93+
}
94+
8095
-(void)layoutSubviews
8196
{
8297
//fix width in ios7
8398
self.width=kScreen_Width-115;
8499
self.autoresizesSubviews = YES;
85100
//找到输入框 右移
86-
UITextField *searchField=[[[[self subviews] firstObject] subviews] lastObject];
87-
searchField.textAlignment=NSTextAlignmentLeft;
88-
[searchField setFrame:CGRectMake(0,4.8,self.frame.size.width,22)];
89-
// searchField.backgroundColor=[UIColor blueColor];
101+
NSPredicate *finalPredicate = [NSPredicate predicateWithBlock:^BOOL(UIView *candidateView, NSDictionary *bindings) {
102+
return [candidateView isMemberOfClass:NSClassFromString(@"UISearchBarTextField")];
103+
}];
104+
UITextField *searchField = [[[[[self subviews] firstObject] subviews] filteredArrayUsingPredicate:finalPredicate] lastObject];
105+
searchField.textAlignment = NSTextAlignmentLeft;
106+
[searchField setFrame:CGRectMake(-CGRectGetWidth(self.frame)/2 + 40, 4.8, CGRectGetWidth(self.frame), 22)];
90107
[(UIImageView*)searchField.leftView setSize:CGSizeMake(13, 13)];
91108
}
92109
@end

0 commit comments

Comments
 (0)