Marino Faggiana 6 years ago
parent
commit
14c0bfb8e6

+ 2 - 0
iOSClient/Brand/iOSClient.plist

@@ -103,6 +103,8 @@
 		<key>NSAllowsArbitraryLoads</key>
 		<true/>
 	</dict>
+	<key>NSCameraUsageDescription</key>
+	<string>The use of Camera is used to scan documet</string>
 	<key>NSLocationAlwaysAndWhenInUseUsageDescription</key>
 	<string>The use of GPS is used to detect new photos from camera roll, continued use of GPS running in the background can dramatically decrease battery life.</string>
 	<key>NSLocationAlwaysUsageDescription</key>

+ 93 - 0
iOSClient/Create/CCCreateCloud.swift

@@ -69,6 +69,12 @@ class CreateMenuAdd: NSObject {
             appDelegate.activeMain.openAssetsPickerController()
         })
         
+        if #available(iOS 10.0, *) {
+            actionSheet.addButton(withTitle: NSLocalizedString("_scans_document_", comment: ""), image: CCGraphics.changeThemingColorImage(UIImage(named: "scan"), multiplier:2, color: colorGray), backgroundColor: NCBrandColor.sharedInstance.backgroundView, height: 50.0, type: AHKActionSheetButtonType.default, handler: {(AHKActionSheet) -> Void in
+                NCCreateScanDocument.sharedInstance.openScannerDocument(viewController: appDelegate.activeMain)
+            })
+        }
+        
         actionSheet.addButton(withTitle: NSLocalizedString("_upload_file_", comment: ""), image: CCGraphics.changeThemingColorImage(UIImage(named: "file"), multiplier:2, color: colorGray), backgroundColor: NCBrandColor.sharedInstance.backgroundView, height: 50.0, type: AHKActionSheetButtonType.default, handler: {(AHKActionSheet) -> Void in
             appDelegate.activeMain.openImportDocumentPicker()
         })
@@ -671,4 +677,91 @@ class CreateFormUploadFile: XLFormViewController, CCMoveDelegate {
     }
 }
 
+//MARK: -
+
+class NCCreateScanDocument : NSObject, ImageScannerControllerDelegate {
+    
+    @objc static let sharedInstance: NCCreateScanDocument = {
+        let instance = NCCreateScanDocument()
+        return instance
+    }()
+    
+    let appDelegate = UIApplication.shared.delegate as! AppDelegate
+    
+    @available(iOS 10, *)
+    func openScannerDocument(viewController: UIViewController) {
+        let scannerVC = ImageScannerController()
+        scannerVC.imageScannerDelegate = self
+        viewController.present(scannerVC, animated: true, completion: nil)
+    }
+    
+    @available(iOS 10, *)
+    func imageScannerController(_ scanner: ImageScannerController, didFinishScanningWithResults results: ImageScannerResults) {
+        
+        scanner.dismiss(animated: true, completion: nil)
+        
+        guard let image = getScannedImage(inputImage: results.scannedImage) else {
+            return
+        }
+        
+        let fileName = CCUtility.createFileName("scan", fileDate: Date(), fileType: PHAssetMediaType.image, keyFileName: k_keyFileNameMask, keyFileNameType: k_keyFileNameType, keyFileNameOriginal: k_keyFileNameOriginal)!
+        let fileNamePath = CCUtility.getDirectoryGroup().appendingPathComponent(k_DirectoryProviderStorage).appendingPathComponent(fileName)
+        
+        do {
+            try UIImagePNGRepresentation(image)?.write(to: fileNamePath, options: .atomic)
+        } catch { }
+        
+        
+        //        let imageData = UIImageJPEGRepresentation(imageBN, 0.8)!
+        //        try? imageData.write(to: fileNamePath)
+        
+        /*
+         do {
+         let page: [PDFPage] = [
+         .whitePage(PDFPageSize.A4),
+         .image(imageBN)
+         ]
+         
+         let path = CCUtility.getDirectoryGroup().appendingPathComponent(k_DirectoryProviderStorage).path+"/"+"scan1.pdf"
+         try PDFGenerator.generate(page, to: path)
+         
+         } catch let error {
+         print(error)
+         }
+         */
+    }
+    
+    @available(iOS 10, *)
+    func imageScannerControllerDidCancel(_ scanner: ImageScannerController) {
+        scanner.dismiss(animated: true, completion: nil)
+    }
+    
+    @available(iOS 10, *)
+    func imageScannerController(_ scanner: ImageScannerController, didFailWithError error: Error) {
+        appDelegate.messageNotification("_error_", description: error.localizedDescription, visible: true, delay: TimeInterval(k_dismissAfterSecond), type: TWMessageBarMessageType.error, errorCode: Int(k_CCErrorInternalError))
+        print(error)
+    }
+    
+    func getScannedImage(inputImage: UIImage) -> UIImage? {
+        
+        let openGLContext = EAGLContext(api: .openGLES2)
+        let context = CIContext(eaglContext: openGLContext!)
+        
+        let filter = CIFilter(name: "CIColorControls")
+        let coreImage = CIImage(image: inputImage)
+        
+        filter?.setValue(coreImage, forKey: kCIInputImageKey)
+        //Key value are changable according to your need.
+        filter?.setValue(7, forKey: kCIInputContrastKey)
+        filter?.setValue(1, forKey: kCIInputSaturationKey)
+        filter?.setValue(1.2, forKey: kCIInputBrightnessKey)
+        
+        if let outputImage = filter?.value(forKey: kCIOutputImageKey) as? CIImage {
+            let output = context.createCGImage(outputImage, from: outputImage.extent)
+            return UIImage(cgImage: output!)
+        }
+        return nil
+    }
+}
+
 

+ 23 - 0
iOSClient/Images.xcassets/scan.imageset/Contents.json

@@ -0,0 +1,23 @@
+{
+  "images" : [
+    {
+      "idiom" : "universal",
+      "filename" : "scan.png",
+      "scale" : "1x"
+    },
+    {
+      "idiom" : "universal",
+      "filename" : "scan@2x.png",
+      "scale" : "2x"
+    },
+    {
+      "idiom" : "universal",
+      "filename" : "scan@3x.png",
+      "scale" : "3x"
+    }
+  ],
+  "info" : {
+    "version" : 1,
+    "author" : "xcode"
+  }
+}

BIN
iOSClient/Images.xcassets/scan.imageset/scan.png


BIN
iOSClient/Images.xcassets/scan.imageset/scan@2x.png


BIN
iOSClient/Images.xcassets/scan.imageset/scan@3x.png


+ 2 - 0
iOSClient/Supporting Files/en.lproj/Localizable.strings

@@ -561,6 +561,8 @@
 
 // Scan Document
 
+"_scans_document_"                   = "Scans document";
+
 /* The title on the navigation bar of the Scanning screen. */
 "wescan.scanning.title"             = "Scanning";
 /* The "Next" button on the right side of the navigation bar on the Edit screen. */