Skip to content

Commit

Permalink
chore: add initial support
Browse files Browse the repository at this point in the history
  • Loading branch information
hansemannn committed Sep 8, 2019
0 parents commit d39bff9
Show file tree
Hide file tree
Showing 14 changed files with 820 additions and 0 deletions.
23 changes: 23 additions & 0 deletions .gitignore
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
17 changes: 17 additions & 0 deletions Classes/TiScannerModule.h
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
88 changes: 88 additions & 0 deletions Classes/TiScannerModule.m
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
12 changes: 12 additions & 0 deletions Classes/TiScannerModuleAssets.h
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
24 changes: 24 additions & 0 deletions Classes/TiScannerModuleAssets.m
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
7 changes: 7 additions & 0 deletions LICENSE
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.
69 changes: 69 additions & 0 deletions README.md
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
5 changes: 5 additions & 0 deletions TiScanner_Prefix.pch
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
42 changes: 42 additions & 0 deletions example/app.js
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();
18 changes: 18 additions & 0 deletions manifest
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
15 changes: 15 additions & 0 deletions module.xcconfig
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
11 changes: 11 additions & 0 deletions timodule.xml
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>
Loading

0 comments on commit d39bff9

Please sign in to comment.