Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-23751] Hyperloop iOS: Block callback arguments are null

GitHub Issuen/a
TypeBug
PriorityCritical
StatusClosed
ResolutionFixed
Resolution Date2016-09-12T23:05:33.000+0000
Affected Version/sRelease 5.4.0
Fix Version/sRelease 5.5.0, hyperloop 1.2.7
ComponentsHyperloop, iOS
Labelsqe-5.4.0
ReporterWilson Luu
AssigneeJan Vennemann
Created2016-08-09T21:44:23.000+0000
Updated2016-09-13T01:51:39.000+0000

Description

*Details:* If you call LAContext.evaluatePolicyLocalizedReasonReply, null is returned for the success parameter instead of true or false. *Steps to reproduce:*

Create a classic app: appc new --classic

In the Resources folder, add/replace the following code:

*app.js*
/**
 * Appcelerator Titanium Mobile
 * Copyright (c) 2009-2014 by Appcelerator, Inc. All Rights Reserved.
 * Licensed under the terms of the Apache Public License
 * Please see the LICENSE included with this distribution for details.
 *
 */

// WARNING!
//
// THIS MODULE WILL ONLY RUN ON AN IOS 8 DEVICE
//

var TiTouchId = require('ti.touchid');

var win = Ti.UI.createWindow();

var btn = Ti.UI.createButton({
	title: 'authenticate'
});

win.add(btn);
win.open();

btn.addEventListener('click', function(){

	if(!TiTouchId.isSupported()) {
		alert("Touch ID is not supported on this device!");
		return;
	}

	TiTouchId.authenticate({
		reason: '#### We need your fingerprint to continue.',
		callback: function(e) {
			if (!e.success) {
				console.log("Success? - " + e.success);
                console.log("Error? - " + e.error);
                console.log("Code? - " + e.code);
			}
            else {
			  	// do something useful
				alert('YAY! success');
			}
		}
	});

});
*ti.touchid.js*
/**
 * Ti.TouchID
 *
 * Summary:	Support native Touch ID with Hyperloop in Titanium Mobile.
 * Author: 	Hans Knoechel | Appcelerator, Inc
 * Date: 	03/22/2016
 * Version:	0.1.0
 * Example
 *
 *	var touchID = require("ti.touchid");
 *	if (touchID.isSupported()) {
 *		touchID.authenticate({
 *			reason : "Please verify to reset all devices",
 *			callback : function(e) {
 * 				Ti.API.warn("Success? - " + e.success);
 *				Ti.API.warn("Error? - " + e.error);
 *				Ti.API.warn("Code? - " + e.code);
 *			}
 *		});
 *	}
 */

var UIDevice = require("UIKit/UIDevice");
var NSNumericSearch = require("Foundation").NSNumericSearch;
var NSOrderedAscending = require("Foundation").NSOrderedAscending;
var LAContext = require('LocalAuthentication/LAContext');
var LocalAuthentication = require('LocalAuthentication/LocalAuthentication');
var context = new LAContext();

function isSupported() {
	var currentOSSupported = UIDevice.currentDevice().systemVersion.compareOptions("8.0", NSNumericSearch) != NSOrderedAscending;
	var touchIDSupported = context.canEvaluatePolicyError(LocalAuthentication.LAPolicyDeviceOwnerAuthenticationWithBiometrics);

	return currentOSSupported && touchIDSupported;
}

function authenticate(args) {
	var reason = args.reason || null;
	var callback = args.callback || null;

	if (!reason || !callback) {
		Ti.API.error("Ti.TouchID: Please provide a valid 'reason' and 'callback' parameter.");
		return;
	}

	context.evaluatePolicyLocalizedReasonReply(LocalAuthentication.LAPolicyDeviceOwnerAuthenticationWithBiometrics, reason, function(success, error) {
		var attrs = {
			success : success
		};

		if (error) {
			attrs["error"] = error.localizedDescription;
			attrs["code"] = error.code;
		}

		callback(attrs);
	});
}

exports.isSupported = isSupported;
exports.authenticate = authenticate;

Install the app to an iOS device that is *touch id supported*; make sure the touch id is enabled first before installing

Launch the app and press on the *authenticate* button

Use your fingerprint to continue

*Actual:* In the console, success is null:
[INFO]  Success? - null
[INFO]  Error? - undefined
[INFO]  Code? - undefined
*Expected:* Success should either be true or false with the appropriate error message and error code.

Comments

  1. Hans Knöchel 2016-08-21

    Ok, some investigation: - It is caused by [this commit](https://github.com/appcelerator/hyperloop.next/pull/10/commits/f57ff6e427fad0b80ab608db538af417d0bf341e) and most probably around [this line](https://github.com/appcelerator/hyperloop.next/pull/10/files#diff-90680d080481b4bc4e5c23fcdf677533L100) that manages the block arguments (which we want aight?) - The fix proposed in that commit was to remove the manual retains and fix the general crash of blocks, so we may cleaned up too much - We now need to compare the generated block arguments before and after the commit to see what's different
  2. Rodolfo Perottoni 2016-08-29

    Can this be fixed in 5.5.0.GA or we'll have to wait for 6.0 ?
  3. Rodolfo Perottoni 2016-09-12

    Hans, Kiat or Wilson. I think this ticket deserves way more attention that it is receiving right now. Why should we wait 2 months (or more in case 6.0 is delayed, like it has been lately...) just to make use of callbacks? Returning values from an asynchronous operation is the only usage of callbacks, and if we don't have this working then it makes no sense to use them at all. ----- This is kind of off topic, but I'd also like to ask you guys what happened to the ticket that I've opened reporting that Android does not work with Hyperloop 1.2.6 anymore. It simply disappeared and no one gave any feedback on what happened to it. Much appreciated!
  4. Hans Knöchel 2016-09-12

    [~rdperottoni] Hyperloop releases are not linked to SDK releases, so it will very likely be available before the 6.0.0 timeline. For your OT question, it was made private to be discussed internally. It is fixed and is already fixed in a patched 1.2.6 version that is online in production. You may need to delete the Hyperloop-plugin from your ~/Library/Application Support/Titanium/modules/android/hyperloop directory (best is to delete iOS as well and fetch it clean) and it will work. The fix is also included in the tomorrows 1.2.7 version.
  5. Rodolfo Perottoni 2016-09-12

    This is great news. So does that mean that the *fix version* in this ticket is wrong?
  6. Hans Knöchel 2016-09-12

    Well, 2.0.0 with 6.0.0 is correct, but there might be a 1.2.8 between 1.2.7 (along with 5.5.0) and 2.0.0 (along with 6.0.0). Ok? :-)
  7. Jan Vennemann 2016-09-12

    PR (master): https://github.com/appcelerator/hyperloop.next/pull/72 PR (1_2_X): https://github.com/appcelerator/hyperloop.next/pull/73
  8. Rodolfo Perottoni 2016-09-12

    Wooooooot!
  9. Hans Knöchel 2016-09-12

    PR's merged. @ QE: Please use the above demo-code to test the arguments of blocks and compare the fixed behavior.
  10. Eric Wieber 2016-09-13

    Verified fixed, using: MacOS 10.12 (16A239m) Studio 4.7.1.201609100950 Ti SDK 5.5.0.v20160912150826 Appc NPM 4.2.7 Appc CLI 5.5.0-6 Alloy 1.9.2 Xcode 8.0 (8A218a) Hyperloop 1.2.7 The success parameter is correctly returned as true or false. Callbacks and error attributes can be properly set by referencing it and are called appropriately. Tested by using the provided test case and by modifying it to check attribute/parameter differences.

JSON Source