Use the iOS 13+ VisionKit
document scanner API in Appcelerator Titanium. Pro tip: Combine with
Ti.Vision to apply machine learning to the detected
document.
- iOS 13+
- Titanium SDK 8.2.0+
- Granted camera permissions
-
showScanner
-
imageOfPageAtIndex(index)
(after thesuccess
event) -
pdfOfPageAtIndex(index)
(after thesuccess
event) -
pdfOfAllPages(params)
(after thesuccess
event - the params includeresizeImages
andpadding
to be used to generate resized A4 PDF's)
-
success
-
error
-
cancel
import Scanner from 'ti.scanner';
const win = Ti.UI.createWindow({
backgroundColor: '#fff'
});
const btn = Ti.UI.createButton({
title: 'Scan Document'
});
btn.addEventListener('click', () => {
Ti.Media.requestCameraPermissions(event => {
if (!event.success) {
alert('No camera permissions');
return;
}
Scanner.showScanner();
});
});
Scanner.addEventListener('cancel', () => {
Ti.API.warn('Cancelled …');
});
Scanner.addEventListener('error', event => {
Ti.API.error('Errored …');
Ti.API.error(event.error);
});
Scanner.addEventListener('success', event => {
Ti.API.warn('Succeeded …');
Ti.API.warn(event);
const win2 = Ti.UI.createWindow({
backgroundColor: '#333'
});
const image = Ti.UI.createImageView({
height: '70%',
image: Scanner.imageOfPageAtIndex(0) /* Or pdfOfPageAtIndex(0) if you need the PDF of it, or many images via "event.count" */
});
win2.add(image);
win2.open();
});
win.add(btn);
win.open();
MIT
Hans Knöchel