-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit d39bff9
Showing
14 changed files
with
820 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
.DS_Store | ||
tmp | ||
bin | ||
build | ||
|
||
*/*/modules | ||
*/*/modules* | ||
.apt_generated | ||
build.properties | ||
.svn | ||
*.pyc | ||
*~.nib/ | ||
*.pbxuser | ||
*.perspective | ||
*.perspectivev3 | ||
*.xcworkspace/ | ||
xcuserdata | ||
*.xcuserstate | ||
*.xcuserdata* | ||
|
||
/metadata.json | ||
/dist | ||
/metadata.json |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
/** | ||
* titanium-scanner | ||
* | ||
* Created by Your Name | ||
* Copyright (c) 2019 Your Company. All rights reserved. | ||
*/ | ||
|
||
#import <Vision/Vision.h> | ||
#import <VisionKit/VisionKit.h> | ||
#import "TiModule.h" | ||
|
||
@interface TiScannerModule : TiModule<VNDocumentCameraViewControllerDelegate> { | ||
VNDocumentCameraViewController *_scannerViewController; | ||
VNDocumentCameraScan *_currentScan; | ||
} | ||
|
||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
/** | ||
* titanium-scanner | ||
* | ||
* Created by Your Name | ||
* Copyright (c) 2019 Your Company. All rights reserved. | ||
*/ | ||
|
||
#import <TitaniumKit/TitaniumKit.h> | ||
#import "TiScannerModule.h" | ||
#import "TiBase.h" | ||
#import "TiHost.h" | ||
#import "TiUtils.h" | ||
|
||
@implementation TiScannerModule | ||
|
||
#pragma mark Internal | ||
|
||
- (id)moduleGUID | ||
{ | ||
return @"558d8ef6-a01d-4474-ac25-777fdecf86a8"; | ||
} | ||
|
||
- (NSString *)moduleId | ||
{ | ||
return @"ti.scanner"; | ||
} | ||
|
||
#pragma Public APIs | ||
|
||
- (NSNumber *)isSupported:(id)unused | ||
{ | ||
return @(VNDocumentCameraViewController.supported); | ||
} | ||
|
||
- (void)showScanner:(id)value | ||
{ | ||
[[TiApp app] showModalController:[self scannerViewController] animated:YES]; | ||
} | ||
|
||
- (TiBlob *)imageOfPageAtIndex:(id)index | ||
{ | ||
ENSURE_SINGLE_ARG(index, NSNumber); | ||
|
||
if (_currentScan == nil) { | ||
return nil; | ||
} | ||
|
||
UIImage *image = [_currentScan imageOfPageAtIndex:[(NSNumber *)index integerValue]]; | ||
TiBlob *blob = [[TiBlob alloc] initWithImage:image]; | ||
|
||
return blob; | ||
} | ||
|
||
#pragma mark Utils | ||
|
||
- (VNDocumentCameraViewController *)scannerViewController | ||
{ | ||
if (_scannerViewController == nil) { | ||
_scannerViewController = [VNDocumentCameraViewController new]; | ||
_scannerViewController.delegate = self; | ||
} | ||
|
||
return _scannerViewController; | ||
} | ||
|
||
#pragma mark VNDocumentCameraViewControllerDelegate | ||
|
||
- (void)documentCameraViewControllerDidCancel:(VNDocumentCameraViewController *)controller | ||
{ | ||
[self fireEvent:@"cancel"]; | ||
[controller dismissViewControllerAnimated:YES completion:nil]; | ||
} | ||
|
||
- (void)documentCameraViewController:(VNDocumentCameraViewController *)controller didFailWithError:(NSError *)error | ||
{ | ||
[self fireEvent:@"error" withObject:@{ @"error": error.localizedDescription }]; | ||
[controller dismissViewControllerAnimated:YES completion:nil]; | ||
} | ||
|
||
- (void)documentCameraViewController:(VNDocumentCameraViewController *)controller didFinishWithScan:(VNDocumentCameraScan *)scan | ||
{ | ||
_currentScan = scan; | ||
|
||
[self fireEvent:@"success" withObject:@{ @"count": @(scan.pageCount), @"title": NULL_IF_NIL(scan.title) }]; | ||
[controller dismissViewControllerAnimated:YES completion:nil]; | ||
} | ||
|
||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
/** | ||
* This is a generated file. Do not edit or your changes will be lost | ||
*/ | ||
|
||
@interface TiScannerModuleAssets : NSObject { | ||
|
||
} | ||
|
||
- (NSData *)moduleAsset; | ||
- (NSData *)resolveModuleAsset:(NSString*)path; | ||
|
||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
/** | ||
* This is a generated file. Do not edit or your changes will be lost | ||
*/ | ||
#import "TiScannerModuleAssets.h" | ||
|
||
extern NSData* filterDataInRange(NSData* thedata, NSRange range); | ||
|
||
@implementation TiScannerModuleAssets | ||
|
||
- (NSData *)moduleAsset | ||
{ | ||
|
||
|
||
return nil; | ||
} | ||
|
||
- (NSData *)resolveModuleAsset:(NSString *)path | ||
{ | ||
|
||
|
||
return nil; | ||
} | ||
|
||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
Copyright 2019 Hans Knöchel | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
# Titanium iOS 13+ Document Scanner | ||
|
||
Use the iOS 13+ `VisionKit` document scanner API in Appcelerator Titanium. | ||
|
||
## Requirements | ||
|
||
- [x] Titanium SDK 8.2.0+ | ||
- [x] iOS 13+ | ||
|
||
## Example | ||
|
||
```js | ||
var Scanner = require('ti.scanner'); | ||
|
||
var win = Ti.UI.createWindow({ | ||
backgroundColor: '#fff' | ||
}); | ||
|
||
var btn = Ti.UI.createButton({ | ||
title: 'Scan Document' | ||
}); | ||
|
||
btn.addEventListener('click', function () { | ||
Ti.Media.requestCameraPermissions(event => { | ||
if (!event.success) { | ||
alert('No camera permissions'); | ||
return; | ||
} | ||
Scanner.showScanner(); | ||
}); | ||
}); | ||
|
||
Scanner.addEventListener('cancel', function () { | ||
Ti.API.warn('Cancelled …'); | ||
}); | ||
|
||
Scanner.addEventListener('error', function (event) { | ||
Ti.API.error('Errored …'); | ||
Ti.API.error(event.error); | ||
}); | ||
|
||
Scanner.addEventListener('success', function (event) { | ||
Ti.API.warn('Succeeded …'); | ||
Ti.API.warn(event); | ||
|
||
var win2 = Ti.UI.createWindow({ | ||
backgroundColor: '#333' | ||
}); | ||
|
||
var image = Ti.UI.createImageView({ | ||
height: '70%', | ||
image: Scanner.imageOfPageAtIndex(0) /* Or many images via "event.pageCount" */ | ||
}); | ||
|
||
win2.add(image); | ||
win2.open(); | ||
}); | ||
|
||
win.add(btn); | ||
win.open(); | ||
``` | ||
|
||
## License | ||
|
||
MIT | ||
|
||
## Author | ||
|
||
Hans Knöchel |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
|
||
#ifdef __OBJC__ | ||
#import <Foundation/Foundation.h> | ||
#import <UIKit/UIKit.h> | ||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
var Scanner = require('ti.scanner'); | ||
|
||
var win = Ti.UI.createWindow({ | ||
backgroundColor: '#fff' | ||
}); | ||
|
||
var btn = Ti.UI.createButton({ | ||
title: 'Scan Document' | ||
}); | ||
|
||
btn.addEventListener('click', function () { | ||
Ti.Media.requestCameraPermissions(event => { | ||
if (!event.success) { | ||
alert('No camera permissions'); | ||
return; | ||
} | ||
Scanner.showScanner({}); | ||
}); | ||
}); | ||
|
||
Scanner.addEventListener('cancel', function () { | ||
Ti.API.warn('Cancelled …'); | ||
}); | ||
|
||
Scanner.addEventListener('error', function (event) { | ||
Ti.API.error('Errored …'); | ||
Ti.API.error(event.error); | ||
}); | ||
|
||
Scanner.addEventListener('success', function (event) { | ||
Ti.API.warn('Succeeded …'); | ||
Ti.API.warn(event); | ||
|
||
var win2 = Ti.UI.createWindow({ backgroundColor: '#333' }); | ||
var image = Ti.UI.createImageView({ height: '70%', image: Scanner.imageOfPageAtIndex(0) /* Or many images via "event.pageCount" */ }); | ||
|
||
win2.add(image); | ||
win2.open(); | ||
}); | ||
|
||
win.add(btn); | ||
win.open(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
# | ||
# this is your module manifest and used by Titanium | ||
# during compilation, packaging, distribution, etc. | ||
# | ||
version: 1.0.0 | ||
apiversion: 2 | ||
architectures: armv7 arm64 i386 x86_64 | ||
description: titanium-scanner | ||
author: Hans Knöchel | ||
license: MIT | ||
copyright: Copyright (c) 2019 by Hans Knöchel | ||
|
||
# these should not be edited | ||
name: titanium-scanner | ||
moduleid: ti.scanner | ||
guid: 558d8ef6-a01d-4474-ac25-777fdecf86a8 | ||
platform: iphone | ||
minsdk: 8.2.0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
// | ||
// PLACE ANY BUILD DEFINITIONS IN THIS FILE AND THEY WILL BE | ||
// PICKED UP DURING THE APP BUILD FOR YOUR MODULE | ||
// | ||
// see the following webpage for instructions on the settings | ||
// for this file: | ||
// https://developer.apple.com/library/content/featuredarticles/XcodeConcepts/Concept-Build_Settings.html | ||
// | ||
|
||
// | ||
// How to manually add a Framework (example) | ||
// Note: Titanium SDK 6.2.2+ detects and links frameworks automatically | ||
// | ||
|
||
OTHER_LDFLAGS=$(inherited) -weak_framework Vision -weak_framework VisionKit |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<ti:module xmlns:ti="http://ti.appcelerator.org" xmlns:android="http://schemas.android.com/apk/res/android"> | ||
<!-- | ||
Similar to tiapp.xml, but contains module/platform specific | ||
configuration in <iphone> and <android> sections | ||
--> | ||
<iphone> | ||
</iphone> | ||
<android xmlns:android="http://schemas.android.com/apk/res/android"> | ||
</android> | ||
</ti:module> |
Oops, something went wrong.