Răsfoiți Sursa

20170310

GRANITE EXPO 1.30
Ray Zhang 9 ani în urmă
părinte
comite
207584c02d

BIN
Ants Contract/AntsContract.xcworkspace/xcuserdata/Ray.xcuserdatad/UserInterfaceState.xcuserstate


+ 128 - 48
Ants Contract/AntsContract.xcworkspace/xcuserdata/Ray.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist

@@ -666,11 +666,11 @@
             ignoreCount = "0"
             continueAfterRunningActions = "No"
             filePath = "common/ExtDocumentsViewController.m"
-            timestampString = "511069805.53406"
+            timestampString = "511082707.406014"
             startingColumnNumber = "9223372036854775807"
             endingColumnNumber = "9223372036854775807"
-            startingLineNumber = "335"
-            endingLineNumber = "335"
+            startingLineNumber = "339"
+            endingLineNumber = "339"
             landmarkName = "-tableView:cellForRowAtIndexPath:"
             landmarkType = "7">
          </BreakpointContent>
@@ -682,11 +682,11 @@
             ignoreCount = "0"
             continueAfterRunningActions = "No"
             filePath = "common/ExtDocumentsViewController.m"
-            timestampString = "511069805.53406"
+            timestampString = "511082707.406014"
             startingColumnNumber = "9223372036854775807"
             endingColumnNumber = "9223372036854775807"
-            startingLineNumber = "310"
-            endingLineNumber = "310"
+            startingLineNumber = "314"
+            endingLineNumber = "314"
             landmarkName = "-numberOfSectionsInTableView:"
             landmarkType = "7">
          </BreakpointContent>
@@ -698,11 +698,11 @@
             ignoreCount = "0"
             continueAfterRunningActions = "No"
             filePath = "common/ExtDocumentsViewController.m"
-            timestampString = "511069805.53406"
+            timestampString = "511082707.406014"
             startingColumnNumber = "9223372036854775807"
             endingColumnNumber = "9223372036854775807"
-            startingLineNumber = "321"
-            endingLineNumber = "321"
+            startingLineNumber = "325"
+            endingLineNumber = "325"
             landmarkName = "-tableView:numberOfRowsInSection:"
             landmarkType = "7">
          </BreakpointContent>
@@ -714,11 +714,11 @@
             ignoreCount = "0"
             continueAfterRunningActions = "No"
             filePath = "common/ExtDocumentsViewController.m"
-            timestampString = "511069805.53406"
+            timestampString = "511082707.406014"
             startingColumnNumber = "9223372036854775807"
             endingColumnNumber = "9223372036854775807"
-            startingLineNumber = "342"
-            endingLineNumber = "342"
+            startingLineNumber = "346"
+            endingLineNumber = "346"
             landmarkName = "-tableView:cellForRowAtIndexPath:"
             landmarkType = "7">
          </BreakpointContent>
@@ -730,11 +730,11 @@
             ignoreCount = "0"
             continueAfterRunningActions = "No"
             filePath = "common/ExtDocumentsViewController.m"
-            timestampString = "511069805.53406"
+            timestampString = "511082707.406014"
             startingColumnNumber = "9223372036854775807"
             endingColumnNumber = "9223372036854775807"
-            startingLineNumber = "347"
-            endingLineNumber = "347"
+            startingLineNumber = "351"
+            endingLineNumber = "351"
             landmarkName = "-tableView:cellForRowAtIndexPath:"
             landmarkType = "7">
          </BreakpointContent>
@@ -746,11 +746,11 @@
             ignoreCount = "0"
             continueAfterRunningActions = "No"
             filePath = "common/ExtDocumentsViewController.m"
-            timestampString = "511069805.53406"
+            timestampString = "511082707.406014"
             startingColumnNumber = "9223372036854775807"
             endingColumnNumber = "9223372036854775807"
-            startingLineNumber = "345"
-            endingLineNumber = "345"
+            startingLineNumber = "349"
+            endingLineNumber = "349"
             landmarkName = "-tableView:cellForRowAtIndexPath:"
             landmarkType = "7">
          </BreakpointContent>
@@ -762,11 +762,11 @@
             ignoreCount = "0"
             continueAfterRunningActions = "No"
             filePath = "common/ExtDocumentsViewController.m"
-            timestampString = "511069805.53406"
+            timestampString = "511082707.406014"
             startingColumnNumber = "9223372036854775807"
             endingColumnNumber = "9223372036854775807"
-            startingLineNumber = "336"
-            endingLineNumber = "336"
+            startingLineNumber = "340"
+            endingLineNumber = "340"
             landmarkName = "-tableView:cellForRowAtIndexPath:"
             landmarkType = "7">
          </BreakpointContent>
@@ -1208,11 +1208,11 @@
             ignoreCount = "0"
             continueAfterRunningActions = "No"
             filePath = "common/AddExtDocumentViewController.m"
-            timestampString = "511069509.19339"
+            timestampString = "511080517.183879"
             startingColumnNumber = "9223372036854775807"
             endingColumnNumber = "9223372036854775807"
-            startingLineNumber = "489"
-            endingLineNumber = "489"
+            startingLineNumber = "493"
+            endingLineNumber = "493"
             landmarkName = "-imagePickerController:didFinishPickingMediaWithInfo:"
             landmarkType = "7">
             <Locations>
@@ -1256,11 +1256,11 @@
             ignoreCount = "0"
             continueAfterRunningActions = "No"
             filePath = "common/AddExtDocumentViewController.m"
-            timestampString = "511069509.19339"
+            timestampString = "511080517.183879"
             startingColumnNumber = "9223372036854775807"
             endingColumnNumber = "9223372036854775807"
-            startingLineNumber = "500"
-            endingLineNumber = "500"
+            startingLineNumber = "504"
+            endingLineNumber = "504"
             landmarkName = "-imagePickerController:didFinishPickingMediaWithInfo:"
             landmarkType = "7">
          </BreakpointContent>
@@ -1272,11 +1272,11 @@
             ignoreCount = "0"
             continueAfterRunningActions = "No"
             filePath = "common/AddExtDocumentViewController.m"
-            timestampString = "511069509.19339"
+            timestampString = "511080517.183879"
             startingColumnNumber = "9223372036854775807"
             endingColumnNumber = "9223372036854775807"
-            startingLineNumber = "347"
-            endingLineNumber = "347"
+            startingLineNumber = "351"
+            endingLineNumber = "351"
             landmarkName = "-tableView:cellForRowAtIndexPath:"
             landmarkType = "7">
          </BreakpointContent>
@@ -1288,11 +1288,11 @@
             ignoreCount = "0"
             continueAfterRunningActions = "No"
             filePath = "common/AddExtDocumentViewController.m"
-            timestampString = "511069509.19339"
+            timestampString = "511080517.183879"
             startingColumnNumber = "9223372036854775807"
             endingColumnNumber = "9223372036854775807"
-            startingLineNumber = "335"
-            endingLineNumber = "335"
+            startingLineNumber = "339"
+            endingLineNumber = "339"
             landmarkName = "-tableView:numberOfRowsInSection:"
             landmarkType = "7">
          </BreakpointContent>
@@ -1304,11 +1304,11 @@
             ignoreCount = "0"
             continueAfterRunningActions = "No"
             filePath = "common/AddExtDocumentViewController.m"
-            timestampString = "511069509.19339"
+            timestampString = "511080517.183879"
             startingColumnNumber = "9223372036854775807"
             endingColumnNumber = "9223372036854775807"
-            startingLineNumber = "418"
-            endingLineNumber = "418"
+            startingLineNumber = "422"
+            endingLineNumber = "422"
             landmarkName = "-tableView:didSelectRowAtIndexPath:"
             landmarkType = "7">
          </BreakpointContent>
@@ -1320,11 +1320,11 @@
             ignoreCount = "0"
             continueAfterRunningActions = "No"
             filePath = "common/AddExtDocumentViewController.m"
-            timestampString = "511069509.19339"
+            timestampString = "511080517.183879"
             startingColumnNumber = "9223372036854775807"
             endingColumnNumber = "9223372036854775807"
-            startingLineNumber = "474"
-            endingLineNumber = "474"
+            startingLineNumber = "478"
+            endingLineNumber = "478"
             landmarkName = "-imagePickerController:didFinishPickingMediaWithInfo:"
             landmarkType = "7">
          </BreakpointContent>
@@ -1336,11 +1336,11 @@
             ignoreCount = "0"
             continueAfterRunningActions = "No"
             filePath = "common/AddExtDocumentViewController.m"
-            timestampString = "511069509.19339"
+            timestampString = "511080517.183879"
             startingColumnNumber = "9223372036854775807"
             endingColumnNumber = "9223372036854775807"
-            startingLineNumber = "498"
-            endingLineNumber = "498"
+            startingLineNumber = "502"
+            endingLineNumber = "502"
             landmarkName = "-imagePickerController:didFinishPickingMediaWithInfo:"
             landmarkType = "7">
          </BreakpointContent>
@@ -1368,11 +1368,11 @@
             ignoreCount = "0"
             continueAfterRunningActions = "No"
             filePath = "common/AddExtDocumentViewController.m"
-            timestampString = "511069509.19339"
+            timestampString = "511080517.183879"
             startingColumnNumber = "9223372036854775807"
             endingColumnNumber = "9223372036854775807"
-            startingLineNumber = "472"
-            endingLineNumber = "472"
+            startingLineNumber = "476"
+            endingLineNumber = "476"
             landmarkName = "-imagePickerController:didFinishPickingMediaWithInfo:"
             landmarkType = "7">
          </BreakpointContent>
@@ -1448,11 +1448,11 @@
             ignoreCount = "0"
             continueAfterRunningActions = "No"
             filePath = "common/AddExtDocumentViewController.m"
-            timestampString = "511069509.19339"
+            timestampString = "511080517.183879"
             startingColumnNumber = "9223372036854775807"
             endingColumnNumber = "9223372036854775807"
-            startingLineNumber = "356"
-            endingLineNumber = "356"
+            startingLineNumber = "360"
+            endingLineNumber = "360"
             landmarkName = "-tableView:cellForRowAtIndexPath:"
             landmarkType = "7">
          </BreakpointContent>
@@ -1601,5 +1601,85 @@
             landmarkType = "7">
          </BreakpointContent>
       </BreakpointProxy>
+      <BreakpointProxy
+         BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
+         <BreakpointContent
+            shouldBeEnabled = "No"
+            ignoreCount = "0"
+            continueAfterRunningActions = "No"
+            filePath = "common/AddExtDocumentViewController.m"
+            timestampString = "511079337.795097"
+            startingColumnNumber = "9223372036854775807"
+            endingColumnNumber = "9223372036854775807"
+            startingLineNumber = "284"
+            endingLineNumber = "284"
+            landmarkName = "-onUploadClicked:"
+            landmarkType = "7">
+         </BreakpointContent>
+      </BreakpointProxy>
+      <BreakpointProxy
+         BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
+         <BreakpointContent
+            shouldBeEnabled = "No"
+            ignoreCount = "0"
+            continueAfterRunningActions = "No"
+            filePath = "common/ExtDocumentsViewController.m"
+            timestampString = "511082707.406014"
+            startingColumnNumber = "9223372036854775807"
+            endingColumnNumber = "9223372036854775807"
+            startingLineNumber = "535"
+            endingLineNumber = "535"
+            landmarkName = "-tableView:didSelectRowAtIndexPath:"
+            landmarkType = "7">
+         </BreakpointContent>
+      </BreakpointProxy>
+      <BreakpointProxy
+         BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
+         <BreakpointContent
+            shouldBeEnabled = "No"
+            ignoreCount = "0"
+            continueAfterRunningActions = "No"
+            filePath = "common/ExtDocumentsViewController.m"
+            timestampString = "511082707.406014"
+            startingColumnNumber = "9223372036854775807"
+            endingColumnNumber = "9223372036854775807"
+            startingLineNumber = "539"
+            endingLineNumber = "539"
+            landmarkName = "-tableView:didSelectRowAtIndexPath:"
+            landmarkType = "7">
+         </BreakpointContent>
+      </BreakpointProxy>
+      <BreakpointProxy
+         BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
+         <BreakpointContent
+            shouldBeEnabled = "No"
+            ignoreCount = "0"
+            continueAfterRunningActions = "No"
+            filePath = "common/ExtDocumentsViewController.m"
+            timestampString = "511082707.406014"
+            startingColumnNumber = "9223372036854775807"
+            endingColumnNumber = "9223372036854775807"
+            startingLineNumber = "67"
+            endingLineNumber = "67"
+            landmarkName = "-onAddClick:"
+            landmarkType = "7">
+         </BreakpointContent>
+      </BreakpointProxy>
+      <BreakpointProxy
+         BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
+         <BreakpointContent
+            shouldBeEnabled = "No"
+            ignoreCount = "0"
+            continueAfterRunningActions = "No"
+            filePath = "common/AddExtDocumentViewController.m"
+            timestampString = "511082756.429923"
+            startingColumnNumber = "9223372036854775807"
+            endingColumnNumber = "9223372036854775807"
+            startingLineNumber = "287"
+            endingLineNumber = "287"
+            landmarkName = "-onUploadClicked:"
+            landmarkType = "7">
+         </BreakpointContent>
+      </BreakpointProxy>
    </Breakpoints>
 </Bucket>

+ 24 - 24
Ants Contract/Granite Expo eSign/Granite Expo eSign/Info.plist

@@ -4,6 +4,25 @@
 <dict>
 	<key>CFBundleDevelopmentRegion</key>
 	<string>en</string>
+	<key>CFBundleDocumentTypes</key>
+	<array>
+		<dict>
+			<key>CFBundleTypeName</key>
+			<string>GE-eSign</string>
+			<key>LSItemContentTypes</key>
+			<array>
+				<string>com.microsoft.powerpoint.ppt</string>
+				<string>com.microsoft.word.doc</string>
+				<string>com.microsoft.excel.xls</string>
+				<string>com.adobe.pdf</string>
+				<string>public.image</string>
+				<string>public.archive</string>
+				<string>public.audio</string>
+				<string>public.movie</string>
+				<string>public.text</string>
+			</array>
+		</dict>
+	</array>
 	<key>CFBundleExecutable</key>
 	<string>$(EXECUTABLE_NAME)</string>
 	<key>CFBundleIdentifier</key>
@@ -15,28 +34,9 @@
 	<key>CFBundlePackageType</key>
 	<string>APPL</string>
 	<key>CFBundleShortVersionString</key>
-	<string>1.21</string>
+	<string>1.30</string>
 	<key>CFBundleVersion</key>
 	<string>31142</string>
-    <key>CFBundleDocumentTypes</key>
-    <array>
-        <dict>
-            <key>CFBundleTypeName</key>
-            <string>GE-eSign</string>
-            <key>LSItemContentTypes</key>
-            <array>
-                <string>com.microsoft.powerpoint.ppt</string>
-                <string>com.microsoft.word.doc</string>
-                <string>com.microsoft.excel.xls</string>
-                <string>com.adobe.pdf</string>
-                <string>public.image</string>
-                <string>public.archive</string>
-                <string>public.audio</string>
-                <string>public.movie</string>
-                <string>public.text</string>
-            </array>
-        </dict>
-    </array>
 	<key>LSRequiresIPhoneOS</key>
 	<true/>
 	<key>NSAppTransportSecurity</key>
@@ -44,6 +44,10 @@
 		<key>NSAllowsArbitraryLoads</key>
 		<true/>
 	</dict>
+	<key>NSCameraUsageDescription</key>
+	<string></string>
+	<key>NSPhotoLibraryUsageDescription</key>
+	<string></string>
 	<key>UILaunchStoryboardName</key>
 	<string>LaunchScreen</string>
 	<key>UIMainStoryboardFile</key>
@@ -58,9 +62,5 @@
 	<array>
 		<string>UIInterfaceOrientationPortrait</string>
 	</array>
-	<key>NSCameraUsageDescription</key>
-	<string></string>
-	<key>NSPhotoLibraryUsageDescription</key>
-	<string></string>
 </dict>
 </plist>

+ 9 - 5
Ants Contract/common/AddExtDocumentViewController.m

@@ -283,15 +283,19 @@
             
             if([[json valueForKey:@"result"] intValue]==2)
             {
-                
-//                if(self.is_present)
+                NSMutableArray* arr = [json[@"documents"] mutableCopy];
+                if(self.is_present)
                 [weakSelf dismissViewControllerAnimated:false completion:^{
                                     if(weakSelf.uploadSuccess)
-                                        weakSelf.uploadSuccess(weakSelf.arr_documents);
+                                        weakSelf.uploadSuccess(arr);
                     
                 }];
-//                else
-//                    [self.navigationController popViewControllerAnimated:false];
+                else
+                {
+                    if(weakSelf.uploadSuccess)
+                        weakSelf.uploadSuccess(arr);
+                    [self.navigationController popViewControllerAnimated:false];
+                }
                 
 //                if(self.uploadSuccess)
 //                    self.uploadSuccess(self.arr_documents);

+ 8 - 4
Ants Contract/common/ExtDocumentsViewController.m

@@ -61,14 +61,18 @@
     AddExtDocumentViewController * addVC = [self.storyboard instantiateViewControllerWithIdentifier:@"AddExtDocumentViewController"];
     addVC.doc_number = self.docNumber;
     addVC.uploadSuccess = ^(NSMutableArray* arr_upload){
-//        [weakself.arr_documents addObjectsFromArray:arr_upload];
-//        [weakself.tableView reloadData];
+        
+        if(weakself.arr_documents==nil)
+            weakself.arr_documents=arr_upload;
+        else
+            [weakself.arr_documents addObjectsFromArray:arr_upload];
+        [weakself.tableView reloadData];
 //        [weakself dismissViewControllerAnimated:false completion:^{
 //
 //        }];
         
-        if(weakself.closeExtDoc)
-            weakself.closeExtDoc(true);
+//        if(weakself.closeExtDoc)
+//            weakself.closeExtDoc(true);
         
     };
     [self.navigationController pushViewController:addVC animated:false];

+ 24 - 0
common/SCShapeView.h

@@ -0,0 +1,24 @@
+/*
+ Copyright 2013 Scott Logic Ltd
+ 
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+ 
+ http://www.apache.org/licenses/LICENSE-2.0
+ 
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+ */
+
+
+#import <UIKit/UIKit.h>
+
+@interface SCShapeView : UIView
+
+@property (nonatomic, strong) NSArray *corners;
+
+@end

+ 66 - 0
common/SCShapeView.m

@@ -0,0 +1,66 @@
+/*
+ Copyright 2013 Scott Logic Ltd
+ 
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+ 
+ http://www.apache.org/licenses/LICENSE-2.0
+ 
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+ */
+
+
+#import "SCShapeView.h"
+
+@interface SCShapeView () {
+    CAShapeLayer *_outline;
+}
+@end
+
+@implementation SCShapeView
+
+- (id)initWithFrame:(CGRect)frame
+{
+    self = [super initWithFrame:frame];
+    if (self) {
+        // Initialization code
+        _outline = [CAShapeLayer new];
+        _outline.strokeColor = [[[UIColor blueColor] colorWithAlphaComponent:0.8] CGColor];
+        _outline.lineWidth = 2.0;
+        _outline.fillColor = [[UIColor clearColor] CGColor];
+        [self.layer addSublayer:_outline];
+    }
+    return self;
+}
+
+- (void)setCorners:(NSArray *)corners
+{
+    if(corners != _corners) {
+        _corners = corners;
+        _outline.path = [[self createPathFromPoints:corners] CGPath];
+    }
+}
+
+- (UIBezierPath *)createPathFromPoints:(NSArray *)points
+{
+    UIBezierPath *path = [UIBezierPath new];
+    // Start at the first corner
+    [path moveToPoint:[[points firstObject] CGPointValue]];
+    
+    // Now draw lines around the corners
+    for (NSUInteger i = 1; i < [points count]; i++) {
+        [path addLineToPoint:[points[i] CGPointValue]];
+    }
+    
+    // And join it back to the first corner
+    [path addLineToPoint:[[points firstObject] CGPointValue]];
+    
+    return path;
+}
+
+@end

+ 13 - 0
common/ScannerControllerView.h

@@ -0,0 +1,13 @@
+//
+//  ScannerView.h
+//  CodeScanner
+//
+//  Created by Ray on 14-7-24.
+//  Copyright (c) 2014年 Shinobi Controls. All rights reserved.
+//
+
+#import <UIKit/UIKit.h>
+
+@interface ScannerControllerView : UIView
+@property CGRect highLightRect;
+@end

+ 60 - 0
common/ScannerControllerView.m

@@ -0,0 +1,60 @@
+//
+//  ScannerView.m
+//  CodeScanner
+//
+//  Created by Ray on 14-7-24.
+//  Copyright (c) 2014年 Shinobi Controls. All rights reserved.
+//
+
+#import "ScannerControllerView.h"
+
+@implementation ScannerControllerView
+
+- (id)initWithFrame:(CGRect)frame
+{
+    self = [super initWithFrame:frame];
+    if (self) {
+        // Initialization code
+    }
+    return self;
+}
+
+
+// Only override drawRect: if you perform custom drawing.
+// An empty implementation adversely affects performance during animation.
+- (void)drawRect:(CGRect)rect
+{
+    CGContextRef con = UIGraphicsGetCurrentContext();
+    
+    CGContextSetFillColorWithColor(con, [[UIColor colorWithRed:0 green:0 blue:0 alpha:0.5] CGColor]);
+    
+    CGContextFillRect(con, rect);
+    //CGRect frame =CGRectMake(100,100,300,300);
+    
+    CGContextClearRect(con, self.highLightRect);
+    // Drawing code
+    
+    
+    
+    
+
+    //    CGRect frame = self.contentView.frame;
+    
+    // //   CGContextAddRect(context,frame);
+       CGContextSetLineWidth(con, 1.0);
+    //
+        CGContextSetStrokeColorWithColor(con, [[UIColor redColor] CGColor]);
+    //
+//        CGRect selrect = self.highLightRect;
+    
+        CGContextMoveToPoint(con, self.highLightRect.origin.x, self.highLightRect.origin.y+ self.highLightRect.size.height/2.0);
+    
+        CGContextAddLineToPoint(con, self.highLightRect.origin.x+ self.highLightRect.size.width, self.highLightRect.origin.y+self.highLightRect.size.height/2.0);
+    //    
+       CGContextStrokePath(con);
+    
+    [super drawRect:rect];
+}
+
+
+@end

+ 36 - 0
common/ScannerViewController.h

@@ -0,0 +1,36 @@
+/*
+ Copyright 2013 Scott Logic Ltd
+ 
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+ 
+ http://www.apache.org/licenses/LICENSE-2.0
+ 
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+ */
+
+
+#import <UIKit/UIKit.h>
+//#import "ScannerControlViewController.h"
+#import "ScannerControllerView.h"
+@interface ScannerViewController : UIViewController
+@property bool handelOutput;
+@property (strong, nonatomic) IBOutlet UIButton *scanButton;
+//@property (strong,nonatomic) ScannerControlViewController * ScannerControl;
+@property (strong, nonatomic) IBOutlet ScannerControllerView *backgroundView;
+//@property (strong,nonatomic) ScannerControllerView* scannerController;
+@property (strong, nonatomic) IBOutlet UIImageView *focusZone;
+
+@property (strong, nonatomic) IBOutlet UIButton *targetButton;
+@property  int target;
+
+@property (strong, nonatomic)  NSString *scan_val;
+
+@property (nonatomic , copy) void (^returnCode)(NSString* code);
+
+@end

+ 872 - 0
common/ScannerViewController.m

@@ -0,0 +1,872 @@
+/*
+ Copyright 2013 Scott Logic Ltd
+ 
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+ 
+ http://www.apache.org/licenses/LICENSE-2.0
+ 
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+ */
+
+
+#import "ScannerViewController.h"
+@import AVFoundation;
+#import <AudioToolbox/AudioToolbox.h>
+#import "SCShapeView.h"
+#import "ScannerControllerView.h"
+//#import "DetailViewController.h"
+#import "const.h"
+#import "AppDelegate.h"
+//#import "MainViewController.h"
+//#import "ContactListViewController.h"
+//#import "CartUtils.h"
+
+#define SCANNER_TARGET_DETAIL 0
+#define SCANNER_TARGET_CART 1
+
+
+//#import "ScannerControlViewController.h"
+@interface ScannerViewController () <AVCaptureMetadataOutputObjectsDelegate> {
+    AVCaptureVideoPreviewLayer *_previewLayer;
+    SCShapeView *_boundingBox;
+    NSTimer *_boxHideTimer;
+    UILabel *_decodedMessage;
+}
+@end
+
+@implementation ScannerViewController
+
+//- (UIInterfaceOrientationMask)supportedInterfaceOrientations
+//{
+//    return UIInterfaceOrientationMaskPortrait;
+//}
+//- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation
+//{
+//    
+//    return (toInterfaceOrientation == UIInterfaceOrientationPortrait);
+//    
+//}
+- (BOOL)shouldAutorotate
+{
+    
+    return false;
+    
+}
+
+-(void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation
+{
+    
+
+    [super didRotateFromInterfaceOrientation:fromInterfaceOrientation];
+    CGRect rect=self.view.bounds;
+    
+    DebugLog(NSStringFromCGRect(self.focusZone.frame));
+    //    rect.origin.y=rect.origin.y+40;
+    //    rect.size.height = rect.size.height-40;
+    
+    
+    
+    
+    
+    
+    
+    [CATransaction begin];
+    [CATransaction setAnimationDuration:0.5];
+    [CATransaction setAnimationTimingFunction:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut]];
+//    [self updatePreviewLayerForOrientation:toInterfaceOrientation];
+    _previewLayer.position = CGPointMake(CGRectGetMidX(rect), CGRectGetMidY(rect));
+    
+ //   self.backgroundView.highLightRect = CGRectInset(self.focusZone.frame,6,6);
+    _previewLayer.bounds = rect;
+    
+    UIInterfaceOrientation orientation = [[UIApplication sharedApplication]statusBarOrientation];
+    switch (orientation) {
+            
+            
+            
+        case UIInterfaceOrientationPortrait:
+           // [_previewLayer setAffineTransform:CGAffineTransformMakeRotation(0)];
+           
+            _previewLayer.connection.videoOrientation=AVCaptureVideoOrientationPortrait;
+            break;
+        case UIInterfaceOrientationPortraitUpsideDown:
+            //[_previewLayer setAffineTransform:CGAffineTransformMakeRotation(M_PI)];
+            _previewLayer.connection.videoOrientation=AVCaptureVideoOrientationPortraitUpsideDown;
+            break;
+        case UIInterfaceOrientationLandscapeLeft:
+           // [_previewLayer setAffineTransform:CGAffineTransformMakeRotation(M_PI/2)];
+            _previewLayer.connection.videoOrientation=AVCaptureVideoOrientationLandscapeLeft;
+            break;
+        case UIInterfaceOrientationLandscapeRight:
+           // [_previewLayer setAffineTransform:CGAffineTransformMakeRotation(-M_PI/2)];
+            _previewLayer.connection.videoOrientation=AVCaptureVideoOrientationLandscapeRight;
+            break;
+        default:
+            break;
+    }
+    [CATransaction commit];
+
+    
+}
+//- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
+//{
+//    return UIInterfaceOrientationPortrait;
+//}
+-(void) playSound
+{
+    
+    /*
+    SystemSoundID sameViewSoundID;
+    //    NSString *filePath = [[NSBundle mainBundle]pathForResource:@"sound" ofType:@"m4r"];
+    //    NSString *thesoundFilePath = [[NSBundle mainBundle] pathForResource:@"sound" ofType:@"wav"]; //音乐文件路径
+    NSString *path = @"/System/Library/Audio/UISounds/begin_video_record.caf";
+    CFURLRef thesoundURL = (__bridge CFURLRef) [NSURL fileURLWithPath:path] ;
+    AudioServicesCreateSystemSoundID(thesoundURL, &sameViewSoundID);
+    //变量SoundID与URL对应
+    DebugLog(@"%u",(unsigned int)sameViewSoundID);
+    AudioServicesPlaySystemSound(1112); //播放SoundID声音
+     
+     
+     */
+    CFBundleRef mainBundle;
+    SystemSoundID soundFileObject;
+    mainBundle = CFBundleGetMainBundle ();
+    CFURLRef soundFileURLRef  = CFBundleCopyResourceURL (
+                                                         mainBundle,
+                                                         CFSTR ("softScanBeep" ),
+                                                         CFSTR ("wav" ),
+                                                         NULL
+                                                         );
+    AudioServicesCreateSystemSoundID (
+                                      soundFileURLRef,
+                                      &soundFileObject
+                                      );
+    AudioServicesPlaySystemSound(soundFileObject);
+}
+- (void)viewWillAppear:(BOOL)animated
+{
+    [super viewWillAppear:animated];
+    [[self navigationController] setNavigationBarHidden:NO animated:NO];
+    
+    
+    //
+    //[ attemptRotationToDeviceOrientation];
+    
+    //[UIViewController attemptRotationToDeviceOrientation];
+    
+//    
+//    [[UIApplication sharedApplication] setStatusBarOrientation:UIInterfaceOrientationPortrait];
+//    self.view.transform = CGAffineTransformMakeRotation(M_PI/2);
+//    CGRect frame = [UIScreen mainScreen].applicationFrame;
+//    self.view.bounds = CGRectMake(0, 0, 768, 1024);
+}
+
+- (void)onBackClick:(UIButton *)sender {
+    
+    
+    [self.navigationController popViewControllerAnimated:FALSE];
+}
+- (void)viewDidLoad
+{
+    [super viewDidLoad];
+    UIBarButtonItem *closeButton = [[UIBarButtonItem alloc] initWithImage:[[UIImage imageNamed:@"back"] imageWithRenderingMode:UIImageRenderingModeAutomatic]
+                                                                    style:UIBarButtonItemStylePlain
+                                                                   target:self
+                                                                   action:@selector( onBackClick:)];
+    
+  //  closeButton.tintColor = UIColorFromRGB(0x996633);
+    
+    self.navigationItem.leftBarButtonItem = closeButton;
+    
+    //        return;
+    [self.backgroundView removeFromSuperview];
+    //self.back = (ScannerControllerView*)self.view;
+    self.backgroundView.highLightRect = CGRectInset(self.focusZone.frame,6,6);
+   // self.backgroundView.autoresizingMask=0xff;
+    self.handelOutput = false;
+    
+    
+    
+    //    self.ScannerControl =[self.storyboard instantiateViewControllerWithIdentifier:@"ScannerControlViewController"];
+    //    self.ScannerControl.Scannerdelegate = self;
+    
+    //   self.view.layer.
+    
+    // Do any additional setup after loading the view, typically from a nib.
+    
+    // Create a new AVCaptureSession
+    AVCaptureSession *session = [[AVCaptureSession alloc] init];
+    
+    session.sessionPreset = AVCaptureSessionPresetHigh;
+    
+    AVCaptureDevice *device = [AVCaptureDevice defaultDeviceWithMediaType:AVMediaTypeVideo];
+    
+    //    float factor =     device.videoZoomFactor;
+    //    float up = device.activeFormat.videoZoomFactorUpscaleThreshold;
+    //    [device lockForConfiguration:nil];
+    //    device.videoZoomFactor = device.activeFormat.videoZoomFactorUpscaleThreshold;
+    //    [device unlockForConfiguration];
+    NSError *error = nil;
+    
+    // Want the normal device
+    AVCaptureDeviceInput *input = [AVCaptureDeviceInput deviceInputWithDevice:device error:&error];
+    
+    if(input) {
+        // Add the input to the session
+        [session addInput:input];
+        
+    } else {
+        DebugLog(@"error: %@", error);
+        return;
+    }
+    
+    
+    
+    AVCaptureMetadataOutput *output = [[AVCaptureMetadataOutput alloc] init];
+    // Have to add the output before setting metadata types
+    [session addOutput:output];
+    // What different things can we register to recognise?
+    DebugLog(@"%@", [output availableMetadataObjectTypes]);
+    // We're only interested in QR Codes
+    [output setMetadataObjectTypes:@[AVMetadataObjectTypeUPCECode,AVMetadataObjectTypeCode39Code,AVMetadataObjectTypeCode39Mod43Code,AVMetadataObjectTypeEAN13Code,AVMetadataObjectTypeEAN8Code,AVMetadataObjectTypeCode93Code,AVMetadataObjectTypeCode128Code,AVMetadataObjectTypePDF417Code,AVMetadataObjectTypeQRCode,AVMetadataObjectTypeAztecCode]];
+    DebugLog(@"%@", [output metadataObjectTypes]);
+    //  NSArray* supporttype=output.availableMetadataObjectTypes;
+    //   [output setMetadataObjectTypes:output.availableMetadataObjectTypes];
+    // This VC is the delegate. Please call us on the main queue
+    [output setMetadataObjectsDelegate:self queue:dispatch_get_main_queue()];
+    //
+    //    CGRect rt1 = self.ScannerControl.scannerZone.frame;
+    
+    
+    
+    // Display on screen
+    _previewLayer = [AVCaptureVideoPreviewLayer layerWithSession:session];
+    _previewLayer.videoGravity = AVLayerVideoGravityResizeAspectFill;
+    
+//    _previewLayer.orientation= AVCaptureVideoOrientationLandscapeRight;
+    UIInterfaceOrientation orientation = [[UIApplication sharedApplication]statusBarOrientation];
+    switch (orientation) {
+            
+//            UIInterfaceOrientationPortrait           = UIDeviceOrientationPortrait,
+//            UIInterfaceOrientationPortraitUpsideDown = UIDeviceOrientationPortraitUpsideDown,
+//            UIInterfaceOrientationLandscapeLeft      = UIDeviceOrientationLandscapeRight,
+//            UIInterfaceOrientationLandscapeRight
+            
+            
+//            AVCaptureVideoOrientationPortrait           = 1,
+//            AVCaptureVideoOrientationPortraitUpsideDown = 2,
+//            AVCaptureVideoOrientationLandscapeRight     = 3,
+//            AVCaptureVideoOrientationLandscapeLeft      = 4,
+        case UIInterfaceOrientationPortrait:
+            _previewLayer.connection.videoOrientation=AVCaptureVideoOrientationPortrait;
+            break;
+        case UIInterfaceOrientationPortraitUpsideDown:
+            _previewLayer.connection.videoOrientation=AVCaptureVideoOrientationPortraitUpsideDown;
+            break;
+        case UIInterfaceOrientationLandscapeLeft:
+            _previewLayer.connection.videoOrientation=AVCaptureVideoOrientationLandscapeLeft;
+            break;
+        case UIInterfaceOrientationLandscapeRight:
+            _previewLayer.connection.videoOrientation=AVCaptureVideoOrientationLandscapeRight;
+            break;
+        default:
+            break;
+    }
+    
+    CGRect rect=self.view.bounds;
+    //    rect.origin.y=rect.origin.y+40;
+    //    rect.size.height = rect.size.height-40;
+    
+    _previewLayer.bounds = rect;
+    _previewLayer.position = CGPointMake(CGRectGetMidX(self.view.bounds), CGRectGetMidY(self.view.bounds));
+    [self.view.layer addSublayer:_previewLayer];
+    
+    
+    
+    [self.view addSubview:self.backgroundView];
+    
+    //    [self.view addSubview:self.ScannerControl.view];
+    //    CGRect rt = self.ScannerControl.scannerZone.bounds;
+    
+    //    CGRect rt1 =output.rectOfInterest;
+    //    output.rectOfInterest = CGRectMake(0, 0, 300, 300); //self.ScannerControl.scannerZone.frame;
+    //    ScannerControllerView* view =[[ ScannerControllerView alloc] initWithFrame:self.view.frame];
+    //    view.backgroundColor = [UIColor clearColor];
+    
+    
+    
+    //    ScannerLayer * layer = [[ScannerLayer alloc] init];
+    //    [self.view.layer addSublayer:layer];
+    
+    
+    // Add the view to draw the bounding box for the UIView
+    _boundingBox = [[SCShapeView alloc] initWithFrame:self.view.bounds];
+    _boundingBox.backgroundColor = [UIColor clearColor];
+    _boundingBox.hidden = YES;
+    [self.view addSubview:_boundingBox];
+    
+    // Add a label to display the resultant message
+    _decodedMessage = [[UILabel alloc] initWithFrame:CGRectMake(0, CGRectGetHeight(self.view.bounds) - 75, CGRectGetWidth(self.view.bounds), 75)];
+    _decodedMessage.numberOfLines = 0;
+    _decodedMessage.backgroundColor = [UIColor colorWithWhite:0.8 alpha:0.9];
+    _decodedMessage.textColor = [UIColor darkGrayColor];
+    _decodedMessage.textAlignment = NSTextAlignmentCenter;
+    [self.view addSubview:_decodedMessage];
+    
+    self.scanButton.layer.shadowColor = [UIColor blackColor].CGColor;
+    self.scanButton.layer.shadowOffset = CGSizeMake(0, 0);
+    self.scanButton.layer.shadowOpacity = 0.5;
+    self.scanButton.layer.shadowRadius = 2.0;
+    self.scanButton.layer.borderColor = [[UIColor darkGrayColor] CGColor];
+    self.scanButton.layer.borderWidth = 15;
+    // Start the AVSession running
+    [session startRunning];
+}
+//#pragma mark - ScannerControllerDelegate
+//-(void)BeginScan:(bool)begin
+//{
+//    self.handelOutput = begin;
+//}
+#pragma mark - AVCaptureMetadataOutputObjectsDelegate
+- (void)captureOutput:(AVCaptureOutput *)captureOutput didOutputMetadataObjects:(NSArray *)metadataObjects fromConnection:(AVCaptureConnection *)connection
+{
+    if(!self.handelOutput)
+        return;
+    AVMetadataObject * cadedate = nil;
+    CGPoint centerzone =CGPointMake(CGRectGetMidX(self.focusZone.frame), CGRectGetMidY(self.focusZone.frame));
+    
+    float distance = MAXFLOAT;
+    for (AVMetadataObject *metadata in metadataObjects) {
+        DebugLog(@"%@",metadata);
+        //  if ([metadata.type isEqualToString:AVMetadataObjectTypeQRCode])
+        {
+            // Transform the meta-data coordinates to screen coords
+            AVMetadataMachineReadableCodeObject *transformed = (AVMetadataMachineReadableCodeObject *)[_previewLayer transformedMetadataObjectForMetadataObject:metadata];
+            // Update the frame on the _boundingBox view, and show it
+            CGRect rt = transformed.bounds;
+            
+            CGRectGetMidX(rt);
+            CGPoint centermeta =CGPointMake(CGRectGetMidX(rt), CGRectGetMidY(rt));
+            if(CGRectContainsPoint(self.focusZone.frame, centermeta))
+            {
+                if(cadedate == nil)
+                    cadedate = metadata;
+                float distancemeta = (centermeta.x-centerzone.x)*(centermeta.x-centerzone.x)+(centermeta.y-centerzone.y)*(centermeta.y-centerzone.y);
+                if(distancemeta<distance)
+                {
+                    distance = distancemeta;
+                    cadedate = metadata;
+                }
+                
+            }
+        }
+    }
+    if(cadedate==nil)
+        return;
+    AVMetadataMachineReadableCodeObject *transformed = (AVMetadataMachineReadableCodeObject *)[_previewLayer transformedMetadataObjectForMetadataObject:cadedate];
+    // Update the frame on the _boundingBox view, and show it
+    //   CGRect rt = transformed.bounds;
+    _boundingBox.frame = transformed.bounds;
+    _boundingBox.hidden = NO;
+    // Now convert the corners array into CGPoints in the coordinate system
+    //  of the bounding box itself
+    
+    //    NSArray * corners = transformed.corners;
+    NSArray *translatedCorners = [self translatePoints:transformed.corners
+                                              fromView:self.view
+                                                toView:_boundingBox];
+    
+    // Set the corners array
+    _boundingBox.corners = translatedCorners;
+    
+    // Update the view with the decoded text
+    _decodedMessage.text = [transformed stringValue];
+    
+    // Start the timer which will hide the overlay
+    [self startOverlayHideTimer];
+    [self playSound];
+    
+    
+    
+    self.handelOutput = false;
+    [self StopScan];
+    
+    
+    
+    self.scan_val = [transformed stringValue];
+    
+    [self dismissViewControllerAnimated:false completion:^{
+        if(self.returnCode)
+            self.returnCode(self.scan_val);
+    }];
+
+    
+//    switch (self.target) {
+//        case SCANNER_TARGET_DETAIL:
+//        {
+//            DetailViewController* dvc = [self.storyboard instantiateViewControllerWithIdentifier:@"DetailViewController" ];
+//            //            dvc
+//            
+//            
+//            dvc.use_model_name = true;
+//            dvc.model_name=[transformed stringValue];
+//            dvc.category_id=nil;
+//            dvc.ispush = true;
+//            
+//            [dvc reload];
+//            [self.navigationController pushViewController:dvc animated:true];
+//        }
+//            break;
+//        case SCANNER_TARGET_CART:
+//        {
+//            
+//            
+//            [CartUtils add_to_cart:self selectorholder:self selector:@selector(addtocart)];
+////            return;
+////            [self add_toCart];
+//            //            DetailViewController* dvc = [self.storyboard instantiateViewControllerWithIdentifier:@"DetailViewController" ];
+//            //            //            dvc
+//            //
+//            //
+//            //            dvc.use_model_name = true;
+//            //            dvc.model_name=[transformed stringValue];
+//            //            dvc.category_id=nil;
+//            //            dvc.ispush = true;
+//            //
+//            //            [dvc reload];
+//            //            [self.navigationController pushViewController:dvc animated:true];
+//        }
+//            break;
+//        default:
+//            break;
+//    }
+    
+}
+
+
+
+//-(void)add_toCart
+//{
+//    
+//    
+//    
+//    UIApplication * app = [UIApplication sharedApplication];
+//    AppDelegate *appDelegate = (AppDelegate *)[app delegate];
+//    MainViewController* main_vc=(MainViewController*)appDelegate.main_vc;
+//    if(appDelegate.bLogin==false)
+//    {
+//        LoginViewController * loginvc =[ self.storyboard instantiateViewControllerWithIdentifier:@"LoginViewController"];
+//
+//        
+//        loginvc.returnValue = ^(bool blogin){
+//            
+//            
+//
+//            
+//            
+//            if(blogin)
+//            {
+//                if(/*appDelegate.user_type==USER_ROLE_EMPLOYEE*/ true)
+//                {
+//                    [((MainViewController*)appDelegate.main_vc) reloadCategory:true immediately:false];
+//                    [main_vc checklogin:false];
+//                    UIAlertView * alert = [[UIAlertView alloc] initWithTitle:NSLocalizedString(@"Add to cart", nil) message:NSLocalizedString(@"Do you want to add to pending a order or a new order", nil) delegate:self cancelButtonTitle:NSLocalizedString(@"Cancel", nil) otherButtonTitles:NSLocalizedString(@"Add to pending order", nil),NSLocalizedString(@"Add to new order", nil), nil];
+//                    
+//                    
+//                    
+//                    // alert.
+//                    [alert show];
+//                }
+//                else
+//                {
+//                    [main_vc checklogin:true];
+//                }
+//            }
+//            
+//
+//            
+//        };
+//        
+//        UINavigationController* navi = [[UINavigationController alloc] initWithRootViewController:loginvc] ;
+//        
+//        
+//        
+//        
+//        
+//        //    [self hackModalSheetSize:CGSizeMake(450, 200) ofVC:navi];
+//        
+//        navi.modalPresentationStyle = UIModalTransitionStyleCrossDissolve;//有三种状态,自己看看是哪种
+//        [self presentViewController:navi animated:YES completion:^{
+//            
+//            //        navi.view.superview.bounds = CGRectMake(0, 0, 480, 320);
+//            
+//            DebugLog(@"LoginViewController present.........");
+//            
+//            //   self.btop = false;
+//            //  <#code#>
+//        }];
+//    }
+//    else
+//    {
+//        
+//        
+//        if(/*appDelegate.user_type==USER_ROLE_EMPLOYEE&&/*appDelegate.contact_id==nil&&*/appDelegate.order_code==nil)
+//        {
+//            [main_vc checklogin:false];
+//            
+//            if(appDelegate.can_create_order)
+//            {
+//                NSString* msg =@"";
+//                if(appDelegate.contact_id.length>0)
+//                {
+//                    msg = [msg stringByAppendingString:@"\n\nCustomer:"];
+//                    msg = [msg stringByAppendingString:appDelegate.customerInfo[@"customer_name"]];
+//                    
+//                }
+//                UIAlertView * alert = [[UIAlertView alloc] initWithTitle:NSLocalizedString(@"Add to cart", nil) message:msg delegate:self cancelButtonTitle:NSLocalizedString(@"Cancel", nil) otherButtonTitles:NSLocalizedString(@"Add to pending order", nil),NSLocalizedString(@"Add to new order", nil), nil];
+//                
+//                // alert.
+//                [alert show];
+//            }
+//            else
+//            {
+//                UIAlertView * alert = [[UIAlertView alloc] initWithTitle:NSLocalizedString(@"Add to cart", nil) message:NSLocalizedString(@"", nil) delegate:self cancelButtonTitle:NSLocalizedString(@"Cancel", nil) otherButtonTitles:NSLocalizedString(@"Add to pending order", nil), nil];
+//                
+//                // alert.
+//                [alert show];
+//            }
+//        }
+//        else
+//        {
+//            
+//            
+//            if(appDelegate.order_code==nil)
+//                [ self neworder];
+//            else
+//                [self addtocart];
+//            
+//            
+//        }
+//    }
+//    
+//    
+//    
+//    
+//    
+//    
+//    
+//    
+//}
+
+
+
+//-(void) neworder
+//{
+//    
+//    UIAlertView * waitalert = [RAUtils waiting_alert:@"Please wait" title:@"Create Order"];
+//    dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
+//        
+//        NSDictionary* return_json = [iSalesNetwork new_Order];
+//        
+//        dispatch_async(dispatch_get_main_queue(), ^{
+//            [waitalert dismissWithClickedButtonIndex:0 animated:FALSE];
+//            
+//            
+//            if([[return_json valueForKey:@"result"] intValue]==2)
+//            {
+//                int result=[[return_json valueForKey:@"result"] intValue];
+//                if(result==2)
+//                {
+//                    //successed.
+//                    
+//                    NSString* order_code = [return_json valueForKey:@"orderCode"];
+//                    AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
+//                    appDelegate.order_code = order_code;
+//                    appDelegate.order_status = [[return_json valueForKey:@"orderStatus"] intValue];
+//   
+//                    
+//                    [self addtocart];
+//                    
+//                
+//                    
+//                }
+//            }
+//            else
+//            {
+//               
+//                [RAUtils message_alert:[return_json valueForKey:@"err_msg"] title:@"Add To Cart" controller:self] ;
+//            }
+//            
+//            
+//            
+//            
+//        });
+//    });
+//}
+//-(void) addtocart
+//{
+//
+//
+//    
+//        dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
+//            
+//            NSDictionary* return_json = [iSalesNetwork add_toCart_byName: self.scan_val];
+//            
+//            dispatch_async(dispatch_get_main_queue(), ^{
+//                
+//                
+//                
+//                if([[return_json valueForKey:@"result"] intValue]==2)
+//                {
+//                    
+//                    
+//                    AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
+//
+//                    [((MainViewController*)appDelegate.main_vc) reloadCart:true immediately:false];
+//                    
+//                    
+//                    
+//                    
+//                    
+//                }
+//                else
+//                {
+//                   
+//                    [RAUtils message_alert:[return_json valueForKey:@"err_msg"] title:@"Add To Cart" controller:self] ;
+//                }
+//                
+//                
+//                
+//                
+//            });
+//        });
+//    
+//    
+//}
+//- (IBAction)TargetButtonClick:(id)sender {
+//    
+//    UIAlertController *alertControl = [UIAlertController alertControllerWithTitle:@"Change scanner target to" message:nil preferredStyle:UIAlertControllerStyleAlert];
+//    //block代码块取代了delegate
+//    
+//    
+//    
+//    UIAlertAction *actionOne = [UIAlertAction actionWithTitle:@"Model Detail" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
+//        
+//        [self.targetButton setTitle:@"Target: Model Detail" forState:UIControlStateNormal];
+//        
+//        self.target = SCANNER_TARGET_DETAIL;
+//        //        UIAlertView * waitalert = [RAUtils waiting_alert:@"Please wait..." title:@"Remove Models From Cart"];
+//        //        dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
+//        //
+//        //            NSDictionary* cart_json = [iSalesNetwork cart_remove:ids];
+//        //
+//        //            dispatch_async(dispatch_get_main_queue(), ^{
+//        //
+//        //                [waitalert dismissWithClickedButtonIndex:0 animated:FALSE];
+//        //
+//        //                if([[cart_json valueForKey:@"result"] intValue]==2)
+//        //                {
+//        //
+//        //                    [self end_edit];
+//        //                    AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
+//        //                    [((MainViewController*)appDelegate.main_vc) reloadCart:true immediately:true];
+//        //                    [((MainViewController*)appDelegate.main_vc) reloadCategory:true immediately:true];
+//        //                }
+//        //                else
+//        //                {
+//        //                    [RAUtils message_alert:[cart_json valueForKey:@"err_msg"] title:@"Delete Model" controller:self] ;
+//        //                }
+//        //
+//        //
+//        //
+//        //            });
+//        //        });
+//        
+//        
+//    }];
+//    
+//    UIAlertAction *alertthree = [UIAlertAction actionWithTitle:@"Cart" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
+//        
+//        
+//        [self.targetButton setTitle:@"Target: Cart" forState:UIControlStateNormal];
+//        self.target = SCANNER_TARGET_CART;
+//        
+//        DebugLog(@"No");
+//    }];
+//    [alertControl addAction:actionOne];
+//    
+//    [alertControl addAction:alertthree];
+//    
+//    //UIAlertControllerStyle类型为UIAlertControllerStyleAlert可以添加addTextFieldWithConfigurationHandler:^(UITextField *textField)
+//    
+//    
+//    [self presentViewController:alertControl animated:YES completion:nil];
+//    
+//    
+//    
+//    
+//    
+//}
+- (IBAction)ScanButtonClick:(id)sender {
+    self.scanButton.backgroundColor = [UIColor greenColor];
+    
+    
+    [self.scanButton setTitle:@"Scanning" forState:UIControlStateNormal];
+//    self.scanButton.layer.borderWidth = 1;
+    
+    
+
+    self.handelOutput = true;
+    
+    //    if (self.Scannerdelegate && [self.Scannerdelegate respondsToSelector:@selector(BeginScan:)]) {
+    //        [self.Scannerdelegate BeginScan:true];
+    //    }
+}
+-(void) StopScan
+{
+    self.scanButton.backgroundColor = [UIColor redColor];
+  [self.scanButton setTitle:@"Tap" forState:UIControlStateNormal];
+}
+
+#pragma mark - Utility Methods
+- (void)startOverlayHideTimer
+{
+    // Cancel it if we're already running
+    if(_boxHideTimer) {
+        [_boxHideTimer invalidate];
+    }
+    
+    // Restart it to hide the overlay when it fires
+    _boxHideTimer = [NSTimer scheduledTimerWithTimeInterval:0.2
+                                                     target:self
+                                                   selector:@selector(removeBoundingBox:)
+                                                   userInfo:nil
+                                                    repeats:NO];
+}
+
+- (void)removeBoundingBox:(id)sender
+{
+    // Hide the box and remove the decoded text
+    _boundingBox.hidden = YES;
+    //  _decodedMessage.text = @"";
+}
+
+- (NSArray *)translatePoints:(NSArray *)points fromView:(UIView *)fromView toView:(UIView *)toView
+{
+    NSMutableArray *translatedPoints = [NSMutableArray new];
+    
+    // The points are provided in a dictionary with keys X and Y
+    for (NSDictionary *point in points) {
+        // Let's turn them into CGPoints
+        CGPoint pointValue = CGPointMake([point[@"X"] floatValue], [point[@"Y"] floatValue]);
+        // Now translate from one view to the other
+        CGPoint translatedPoint = [fromView convertPoint:pointValue toView:toView];
+        // Box them up and add to the array
+        [translatedPoints addObject:[NSValue valueWithCGPoint:translatedPoint]];
+    }
+    
+    return [translatedPoints copy];
+}
+
+//#pragma mark - UIAlertViewDelegate
+//// Called when a button is clicked. The view will be automatically dismissed after this call returns
+//- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
+//{
+//    UIApplication * app = [UIApplication sharedApplication];
+//    AppDelegate *appDelegate = (AppDelegate *)[app delegate];
+//
+//    
+//    //   int count=[self.quantity_text.text intValue];
+//    
+//    MainViewController* main_vc=(MainViewController*)appDelegate.main_vc;
+//    if(buttonIndex==alertView.cancelButtonIndex)
+//    {
+//        
+//        
+//        
+//    }
+//    else if(buttonIndex==1)
+//    {
+//        //open exist
+//                OrderListViewController* ovc =[ self.storyboard instantiateViewControllerWithIdentifier:@"OrderListViewController"];
+//        ovc.showNavibar = true;
+//        ovc.selectOrder = ^(NSMutableDictionary* order_detail){
+//            if(appDelegate.order_code==nil)
+//            {
+//                [self neworder];
+//            }
+//            else
+//            {
+//                [((MainViewController*)appDelegate.main_vc) reloadCart:true immediately:false];
+//                
+//
+//                [self addtocart];
+//                [main_vc checklogin:true];
+//                
+//                
+//            }
+//            
+//        };
+//        ovc.init_style = OL_OPEN;
+//        ovc.onCancel = ^(){
+//            
+//            [main_vc checklogin:true];
+//            
+//        };
+//        
+//        [self.navigationController pushViewController:ovc animated:true];
+//    }
+//    else
+//    {
+//        //create new;
+//        if(appDelegate.customerInfo==nil)// select contact if current contact not exist
+//        {
+//           
+//            
+//            ContactListViewController* cvc = [self.storyboard instantiateViewControllerWithIdentifier:@"ContactListViewController" ];
+//            cvc.showNavibar = true;
+//            cvc.contact_type = @"Sales_Order_Customer";
+//            cvc.returnValue = ^(NSMutableDictionary* value,NSIndexPath* source){
+//                
+//                appDelegate.contact_id=[value valueForKey:@"customer_cid"];
+//                appDelegate.customerInfo = value;
+//                
+//                
+//                if(appDelegate.order_code==nil)
+//                    [self neworder];
+//                
+//                [main_vc checklogin:true];
+//                //            [self handle_action_return:value indexPath:indexPath action:ACTION_FILL_SECTION];
+//                
+//                //
+//                //                if(self.returnValue)
+//                //                    self.returnValue(value);
+//            };
+//            
+//            cvc.onCancel = ^(){
+//                
+//                UIViewController *vc= [RAUtils getViewController:self];
+//                [RAUtils message_alert:@"Cannot create order without cursomer infomation." title:@"New Order" controller:vc];
+//                
+//            };
+//            cvc.onReset = ^(){
+//                [main_vc checklogin:true];
+//            };
+//            
+//            [self.navigationController pushViewController:cvc animated:true];
+//        }
+//        else
+//        {
+//            [self neworder];
+//        }
+//        
+//        
+//    }
+//}
+@end

+ 70 - 0
common/cam_scan.storyboard

@@ -0,0 +1,70 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="11762" systemVersion="16D32" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" colorMatched="YES">
+    <device id="ipad9_7" orientation="portrait">
+        <adaptation id="fullscreen"/>
+    </device>
+    <dependencies>
+        <plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="11757"/>
+        <capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
+    </dependencies>
+    <scenes>
+        <!--ScannerViewController-->
+        <scene sceneID="ujq-xf-Oml">
+            <objects>
+                <viewController storyboardIdentifier="ScannerViewController" title="ScannerViewController" useStoryboardIdentifierAsRestorationIdentifier="YES" id="kVd-Bz-inR" customClass="ScannerViewController" sceneMemberID="viewController">
+                    <layoutGuides>
+                        <viewControllerLayoutGuide type="top" id="NEh-qa-oua"/>
+                        <viewControllerLayoutGuide type="bottom" id="yWx-4n-MjG"/>
+                    </layoutGuides>
+                    <view key="view" contentMode="scaleToFill" id="Ls8-b3-CO0">
+                        <rect key="frame" x="0.0" y="0.0" width="768" height="1024"/>
+                        <autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
+                        <subviews>
+                            <view contentMode="scaleToFill" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="YsE-DF-hiM" customClass="ScannerControllerView">
+                                <rect key="frame" x="0.0" y="0.0" width="768" height="1024"/>
+                                <autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
+                                <subviews>
+                                    <button opaque="NO" contentMode="scaleToFill" fixedFrame="YES" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="wordWrap" translatesAutoresizingMaskIntoConstraints="NO" id="r3N-1u-7iO" userLabel="Button scan">
+                                        <rect key="frame" x="613" y="694" width="108" height="108"/>
+                                        <autoresizingMask key="autoresizingMask" flexibleMinX="YES" flexibleMinY="YES"/>
+                                        <color key="backgroundColor" red="1" green="0.0" blue="0.0" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
+                                        <fontDescription key="fontDescription" type="system" pointSize="17"/>
+                                        <state key="normal">
+                                            <color key="titleColor" red="0.0" green="0.0" blue="0.0" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
+                                            <color key="titleShadowColor" red="0.5" green="0.5" blue="0.5" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
+                                        </state>
+                                        <userDefinedRuntimeAttributes>
+                                            <userDefinedRuntimeAttribute type="number" keyPath="layer.cornerRadius">
+                                                <integer key="value" value="54"/>
+                                            </userDefinedRuntimeAttribute>
+                                        </userDefinedRuntimeAttributes>
+                                        <connections>
+                                            <action selector="ScanButtonClick:" destination="kVd-Bz-inR" eventType="touchUpInside" id="yma-nd-AN9"/>
+                                        </connections>
+                                    </button>
+                                    <imageView userInteractionEnabled="NO" contentMode="scaleToFill" horizontalHuggingPriority="251" verticalHuggingPriority="251" fixedFrame="YES" image="pick_bg" translatesAutoresizingMaskIntoConstraints="NO" id="XWh-0J-sDJ">
+                                        <rect key="frame" x="134" y="362" width="500" height="300"/>
+                                        <autoresizingMask key="autoresizingMask" flexibleMinX="YES" flexibleMaxX="YES" flexibleMinY="YES" flexibleMaxY="YES"/>
+                                    </imageView>
+                                </subviews>
+                                <color key="backgroundColor" red="0.0" green="0.0" blue="0.0" alpha="0.0" colorSpace="custom" customColorSpace="sRGB"/>
+                            </view>
+                        </subviews>
+                        <color key="backgroundColor" red="1" green="1" blue="1" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
+                    </view>
+                    <navigationItem key="navigationItem" title="Scanner" id="Q4Z-q4-4V4"/>
+                    <connections>
+                        <outlet property="backgroundView" destination="YsE-DF-hiM" id="IER-tw-aql"/>
+                        <outlet property="focusZone" destination="XWh-0J-sDJ" id="0Yv-QM-d8Y"/>
+                        <outlet property="scanButton" destination="r3N-1u-7iO" id="Eeq-vI-mME"/>
+                    </connections>
+                </viewController>
+                <placeholder placeholderIdentifier="IBFirstResponder" id="hQT-6P-tva" userLabel="First Responder" sceneMemberID="firstResponder"/>
+            </objects>
+            <point key="canvasLocation" x="2844" y="-4325"/>
+        </scene>
+    </scenes>
+    <resources>
+        <image name="pick_bg" width="16" height="16"/>
+    </resources>
+</document>