Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

App crash on scan success #101

Open
DouglasHennrich opened this issue Jan 18, 2019 · 4 comments
Open

App crash on scan success #101

DouglasHennrich opened this issue Jan 18, 2019 · 4 comments

Comments

@DouglasHennrich
Copy link

DouglasHennrich commented Jan 18, 2019

[ERROR] The application has crashed with an uncaught exception 'NSRangeException'.
[ERROR] Reason:
[ERROR] *** -[__NSArray0 objectAtIndex:]: index 0 beyond bounds for empty NSArray
[ERROR] Stack trace:
[ERROR] 0   CoreFoundation                      0x0000000209d4cedc <redacted> + 252
[ERROR] 1   libobjc.A.dylib                     0x0000000208f1da40 objc_exception_throw + 56
[ERROR] 2   CoreFoundation                      0x0000000209c5e9b0 <redacted> + 0
[ERROR] 3   Kyddo Empresa                       0x000000010451ed68 Kyddo Empresa + 1994088
[ERROR] 4   Kyddo Empresa                       0x000000010451d4c8 Kyddo Empresa + 1987784
[ERROR] 5   Kyddo Empresa                       0x00000001045194f0 Kyddo Empresa + 1971440
[ERROR] 6   AVFoundation                        0x000000020feb47cc <redacted> + 1288
[ERROR] 7   AVFoundation                        0x000000020feb4084 <redacted> + 100
[ERROR] 8   CoreMedia                           0x000000020d353df8 <redacted> + 280
[ERROR] 9   CoreMedia                           0x000000020d3714c8 <redacted> + 224
[ERROR] 10  libdispatch.dylib                   0x0000000209786484 <redacted> + 16
[ERROR] 11  libdispatch.dylib                   0x000000020972982c <redacted> + 412
[ERROR] 12  libdispatch.dylib                   0x0000000209739b9c <redacted> + 1704
[ERROR] 13  libdispatch.dylib                   0x000000020972da9c <redacted> + 284
[ERROR] 14  libdispatch.dylib                   0x000000020972e74c <redacted> + 484
[ERROR] 15  libdispatch.dylib                   0x0000000209732888 <redacted> + 784
[ERROR] 16  CoreFoundation                      0x0000000209cdcdf4 <redacted> + 12
[ERROR] 17  CoreFoundation                      0x0000000209cd7cbc <redacted> + 1964
[ERROR] 18  CoreFoundation                      0x0000000209cd71f0 CFRunLoopRunSpecific + 436
[ERROR] 19  GraphicsServices                    0x000000020bf50584 GSEventRunModal + 100
[ERROR] 20  UIKitCore                           0x0000000236eded40 UIApplicationMain + 212
[ERROR] 21  Kyddo Empresa                       0x000000010433f080 Kyddo Empresa + 28800
[ERROR] 22  libdyld.dylib                       0x0000000209796bb4 <redacted> + 4

Only happenning on iOS
TiSDK 7.4.2.GA
Module version: 2.0.4

Code test:

/* ===============================
@ Vars
=============================== */
const Barcode = require('ti.barcode')

let alreadyScanned

/* ===============================
@ Functions
=============================== */
/*
@ Initialize
*/
const Initialize = () => {
	Barcode.allowRotation = true
	Barcode.displayedMessage = ''
	Barcode.allowMenu = false
	Barcode.allowInstructions = false

	//
	Barcode.addEventListener('error', event => {
		console.warn('============')
		console.warn(`[on errror]: ${JSON.stringify(event)}`)

		$.trigger('error', {
			msg: event,
			callback: () => $.getView().close(),
		})
	})

	//
	Barcode.addEventListener('cancel', event => {
		$.trigger('error', {
			msg: 'Cancelado',
			callback: () => $.getView().close(),
		})
	})

	//
	Barcode.addEventListener('success', event => {
		if (alreadyScanned) return
		alreadyScanned = true
		console.warn('============')
		console.warn(`[event]: ${event.result}`)

		Ti.Media.vibrate()

		$.trigger('scanned', {
			barcode: event.result,
			callback: () => $.getView().close(),
		})
	})
}

/*
 * openWin
 */
function openWin() {
	const hasCameraPermissions = Ti.Media.hasCameraPermissions()
	console.warn('============')
	console.warn(`[hasCameraPermissions]: ${hasCameraPermissions}`)

	if (hasCameraPermissions) {
		Barcode.capture({
			animate: true,
			showCancel: true,
			showRectangle: false,
			keepOpen: false,
			acceptedFormats: [Barcode.FORMAT_EAN_13, Barcode.FORMAT_QR_CODE],
		})

		// _.delay(() => {
		// 	$.trigger('scanned', {
		// 		barcode: '1d2d3d',
		// 		callback: () => $.getView().close(),
		// 	})
		// }, 3000)
	} else {
		//
		Ti.Media.requestCameraPermissions(e => {
			console.warn('============')
			console.warn(`[requestCameraPermissions]: ${JSON.stringify(e)}`)
			if (e.success) {
				openWin()
			} else {
				$.trigger('error', {
					msg: 'Media não autorizada',
					callback: () => $.getView().close(),
				})
			}
		})
	}
}

/* ===============================
@ Exports
=============================== */
//
exports.cleanUp = () => {
	$.destroy()
	$.off()
}

/* ===============================
@
=============================== */
Initialize()
@vijaysingh-axway
Copy link
Contributor

@DouglasHennrich Is it happening for any barcode scanned or any special barcode?

@DouglasHennrich
Copy link
Author

Any kind of code, but I'm testing on QR Code and FORMAT_EAN_13

@vijaysingh-axway
Copy link
Contributor

@DouglasHennrich I have tried app given in example of barcode. It is giving proper result. I try to run your code but is giving error in building. Can you please share complete code which I can run. It is better if you can share classic app for this code. Thanks!

@DouglasHennrich
Copy link
Author

I don't know if it's related but I open a new window just to do this scan logic and I get the crash when I call: $.trigger('scanned', { barcode: event.result, callback: () => $.getView().close(), })

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants