|
@@ -10,8 +10,11 @@
|
|
|
#import <ImageIO/ImageIO.h>
|
|
|
#import "GuideViewController.h"
|
|
|
#import "RSATool.h"
|
|
|
+#import <TZImageManager.h>
|
|
|
+#import <TZImagePickerController.h>
|
|
|
+#import "connectDeviceManager.h"
|
|
|
|
|
|
-@interface QRCodeScanViewController ()<AVCaptureMetadataOutputObjectsDelegate,AVCaptureVideoDataOutputSampleBufferDelegate,UINavigationControllerDelegate,UIImagePickerControllerDelegate>
|
|
|
+@interface QRCodeScanViewController ()<AVCaptureMetadataOutputObjectsDelegate,AVCaptureVideoDataOutputSampleBufferDelegate,UINavigationControllerDelegate,UIImagePickerControllerDelegate,TZImagePickerControllerDelegate>
|
|
|
|
|
|
@property(nonatomic,strong)AVCaptureVideoPreviewLayer *layer;
|
|
|
|
|
@@ -274,8 +277,8 @@ bool isDownType = YES;
|
|
|
[[iToast makeText:NSLocalizedString(@"guide_qrcoede_tips_ok",nil)] show];
|
|
|
[_scanLineTimer invalidate];
|
|
|
|
|
|
- NSDictionary *newDict = [[NSDictionary alloc] initWithObjectsAndKeys:resStr,Const_Have_Add_Device_SN, nil];
|
|
|
- [HWDataManager setObjectWithKey:Const_Have_Add_Device value:newDict];
|
|
|
+// NSDictionary *newDict = [[NSDictionary alloc] initWithObjectsAndKeys:resStr,Const_Have_Add_Device_SN, nil];
|
|
|
+// [HWDataManager setObjectWithKey:Const_Have_Add_Device value:newDict];
|
|
|
|
|
|
[self nextStep:resStr];
|
|
|
|
|
@@ -293,6 +296,27 @@ bool isDownType = YES;
|
|
|
|
|
|
|
|
|
- (void)nextStep:(NSString *)sn{
|
|
|
+
|
|
|
+ KWeakSelf
|
|
|
+ [[connectDeviceManager shareInstance] getThridMsgBySN:sn needReconnect:NO didNetEnd:^(bool didSuc) {
|
|
|
+ if(didSuc){
|
|
|
+ [weakSelf gotoGuideViewFunBy:sn];
|
|
|
+ }else{
|
|
|
+ [[iToast makeText:NSLocalizedString(@"guide_qrcoede_tips_get_SdnID_fail",nil)] show];
|
|
|
+ dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(3.0 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
|
|
|
+ [self.navigationController popViewControllerAnimated:YES];
|
|
|
+ });
|
|
|
+ }
|
|
|
+ }];
|
|
|
+}
|
|
|
+
|
|
|
+#pragma mark GuideViewController
|
|
|
+
|
|
|
+- (void)gotoGuideViewFunBy:(NSString*)sn
|
|
|
+{
|
|
|
+ NSDictionary *newDict = [[NSDictionary alloc] initWithObjectsAndKeys:sn,Const_Have_Add_Device_SN, nil];
|
|
|
+ [HWDataManager setObjectWithKey:Const_Have_Add_Device value:newDict];
|
|
|
+
|
|
|
/*下一步*/
|
|
|
GuideViewController *nextVC = [[GuideViewController alloc] init];
|
|
|
nextVC.sn = sn;
|
|
@@ -358,11 +382,37 @@ bool isDownType = YES;
|
|
|
////获取相册图片btn点击方法
|
|
|
|
|
|
-(void)photoBtnClick:(UIButton*)sender{
|
|
|
- UIImagePickerController *imagePicker = [[UIImagePickerController alloc] init];
|
|
|
- imagePicker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
|
|
|
- // imagePicker.allowsEditing = YES;
|
|
|
- imagePicker.delegate=self;
|
|
|
- [self.navigationController presentViewController:imagePicker animated:YES completion:nil];
|
|
|
+// UIImagePickerController *imagePicker = [[UIImagePickerController alloc] init];
|
|
|
+// imagePicker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
|
|
|
+// // imagePicker.allowsEditing = YES;
|
|
|
+// imagePicker.delegate=self;
|
|
|
+// [self.navigationController presentViewController:imagePicker animated:YES completion:nil];
|
|
|
+
|
|
|
+ [self photoClickFun];
|
|
|
+}
|
|
|
+
|
|
|
+- (void)photoClickFun
|
|
|
+{
|
|
|
+ TZImagePickerController *imagePicker = [[TZImagePickerController alloc] initWithMaxImagesCount:1 delegate:self];
|
|
|
+
|
|
|
+ imagePicker.allowPickingVideo=NO;
|
|
|
+ //imagePicker.isStatusBarDefault=YES;
|
|
|
+ imagePicker.allowTakePicture=NO;
|
|
|
+ imagePicker.allowPreview = NO;
|
|
|
+ // 4. 照片排列按修改时间升序
|
|
|
+ imagePicker.sortAscendingByModificationDate = YES;
|
|
|
+ [self presentViewController:imagePicker animated:YES completion:nil];
|
|
|
+
|
|
|
+}
|
|
|
+
|
|
|
+- (void)imagePickerController:(TZImagePickerController *)picker didFinishPickingPhotos:(NSArray<UIImage *> *)photos sourceAssets:(NSArray *)assets isSelectOriginalPhoto:(BOOL)isSelectOriginalPhoto
|
|
|
+{
|
|
|
+ if(photos && photos.count >= 1){
|
|
|
+ [self detectImageFunBy:photos.firstObject];
|
|
|
+ }
|
|
|
+ else{
|
|
|
+ [[iToast makeText:NSLocalizedString(@"guide_qrcoede_tips_error",nil)] show];
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
//UIImagePickerControllerDelegate选择图片的回调
|
|
@@ -370,6 +420,18 @@ bool isDownType = YES;
|
|
|
-(void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary<UIImagePickerControllerInfoKey,id> *)info {
|
|
|
//把UIimage类型转换成CIimage类型
|
|
|
UIImage *pickedImage = info[UIImagePickerControllerEditedImage] ?: info[UIImagePickerControllerOriginalImage];
|
|
|
+
|
|
|
+ [picker dismissViewControllerAnimated:YES completion:^{
|
|
|
+
|
|
|
+ }];
|
|
|
+
|
|
|
+ [self detectImageFunBy:pickedImage];
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+#pragma mark 解析Uiimage
|
|
|
+- (void)detectImageFunBy:(UIImage*)pickedImage
|
|
|
+{
|
|
|
CIImage*detectImage = [CIImage imageWithData:UIImagePNGRepresentation(pickedImage)];
|
|
|
//解析扫描二维码结果字符串
|
|
|
CIDetector *detector = [CIDetector detectorOfType:CIDetectorTypeQRCode context:nil options:@{CIDetectorAccuracy: CIDetectorAccuracyLow}];
|
|
@@ -385,20 +447,21 @@ bool isDownType = YES;
|
|
|
break;
|
|
|
}
|
|
|
}
|
|
|
- [picker dismissViewControllerAnimated:YES completion:^{
|
|
|
- if(curQRCodeStr) {
|
|
|
- NSLog(@"=================二维码结果为%@",curQRCodeStr);
|
|
|
- [self handleScanCodeResultFun:curQRCodeStr];
|
|
|
+
|
|
|
+ if(curQRCodeStr) {
|
|
|
+ NSLog(@"=================二维码结果为%@",curQRCodeStr);
|
|
|
+ [self handleScanCodeResultFun:curQRCodeStr];
|
|
|
|
|
|
- }else{
|
|
|
- [[iToast makeText:NSLocalizedString(@"guide_qrcoede_tips_error",nil)] show];
|
|
|
- NSLog(@"没有扫描到数据");
|
|
|
- }
|
|
|
+ }else{
|
|
|
+ [[iToast makeText:NSLocalizedString(@"guide_qrcoede_tips_error",nil)] show];
|
|
|
+ NSLog(@"没有扫描到数据");
|
|
|
+ }
|
|
|
+
|
|
|
// //停止会话对象扫描
|
|
|
// [self.session stopRunning];
|
|
|
// //移除扫描层layer
|
|
|
// [self.layer removeFromSuperlayer];
|
|
|
- }];
|
|
|
+
|
|
|
}
|
|
|
|
|
|
@end
|