Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-24489] iOS: Ti.TouchID - Callback error with Ti.Network.createHTTPClient

GitHub Issuen/a
TypeBug
PriorityCritical
StatusClosed
ResolutionFixed
Resolution Date2017-04-12T09:44:53.000+0000
Affected Version/sn/a
Fix Version/sRelease 6.1.0
Componentsn/a
Labels6.0.1, httpclient, sdk, touchid
ReporterClément Blanco
AssigneeHans Knöchel
Created2017-03-16T13:50:48.000+0000
Updated2017-05-16T16:40:20.000+0000

Description

This doesn't seem to work:
var touchId = require("ti.touchid");
touchId.authenticate({
    reason: "Place your finger on the home button to login",
    callback: function(e) {
        if (e.success === true) {
            // Success
        } else {
            // Cancel
        }
    }
});
But this works:
var touchId = require("ti.touchid");
touchId.authenticate({
    reason: "Place your finger on the home button to login",
    callback: function(e) {
        if (e.success === true) {
            // if you don't do this, Ti.Network fails later if it's
            // called from an event running in this callback
            setTimeout(function() {
                    // Success
            },0);
        } else {
            // Cancel
        }
    }
});
If you don’t use the timeout 0: - on simulator *it’s fine* (with our without liveview) - on device with liveview *it’s fine* - on device without liveview *it fails*

Comments

  1. Hans Knöchel 2017-03-16

    Please attach a full use-case that also includes the failing HTTPClient call. Use [httpbin](https://httpbin.org/) to call a demo-API.
  2. Clément Blanco 2017-03-16

       var touchId = Ti.require("ti.touchid");
       touchId.authenticate({
           reason: "Place your finger on the home button to login",
           callback: function(e) {
               if (e.success === true) {
                   var http = Ti.Network.createHTTPClient({
                       onload : function(e) {
                           Ti.API.info("Received text: " + this.responseText);
                           alert('success');
                       },
                       onerror : function(e) {
                           Ti.API.debug(e.error);
                           alert('error');
                       },
                       timeout : 5000
                   });
                   client.setRequestHeader("Accept", "application/json");
                   client.open("GET", "http://httpbin.org/get");
                   client.send();
               } else {
                   // Cancel
               }
           }
       });
       
  3. Hans Knöchel 2017-03-18

    Thanks! What's interesting is that if you use the main-thread instead of the kroll-thread, it works just fine. I'm also wondering if this used to work before and if other Ti-namespaces API's like Ti.Media or Ti.Geolocation have the same behavior.
  4. Hans Knöchel 2017-03-26

    PR: https://github.com/appcelerator-modules/ti.touchid/pull/30 Packaged module: https://github.com/appcelerator-modules/ti.touchid/releases/tag/ios-2.1.2 Test-case (test with both kroll- and main-thread):
       var touchId = require("ti.touchid");
       
       var win = Ti.UI.createWindow({
           backgroundColor: '#fff'
       });
       
       var btn = Ti.UI.createButton({
           title: 'Trigger'
       });
       
       btn.addEventListener('click', function() {
           touchId.authenticate({
               reason: "Place your finger on the home button to login",
               callback: function(e) {
                   if (e.success === true) {
                       var http = Ti.Network.createHTTPClient({
                           onload: function(e) {
                               Ti.API.info("Received text: " + this.responseText);
                               alert('success');
                           },
                           onerror: function(e) {
                               Ti.API.debug(e.error);
                               alert('error');
                           },
                           timeout: 5000
                       });
                       http.setRequestHeader("Accept", "application/json");
                       http.open("GET", "http://httpbin.org/get");
                       http.send();
                   } else {
                       // Ignore case
                   }
               }
           });
       });
       
       win.add(btn);
       win.open();
       
  5. Clément Blanco 2017-04-03

    I've tried 2.1.2, this problem seems to have been solved but touchId.authenticate() seems to always return the following, no matter what:
       {
           "type": "callback",
           "success": true,
           "source": {}
       }
       
    Should I raise a different ticket?
  6. Hans Knöchel 2017-04-06

    Please note that iOS 10.2 (\?), the user response is cached after a few recurring authorizations. You can force to show the dialog again by calling invalidate() in the success handling. But this behavior was the same before and did not change.
  7. Clément Blanco 2017-04-06

    Ok good to know. I'll try again with 2.1.2.
  8. Hans Knöchel 2017-04-11

    [~clement] Did you test it?
  9. Clément Blanco 2017-04-12

    Seems okay now with invalidate(). Can this be added to the readme.md on the github repo and/or in the official documentation?
  10. Hans Knöchel 2017-04-12

    Thanks! Done so in [this commit](https://github.com/appcelerator-modules/ti.touchid/commit/7586d447982426843a1cab0dffcc8bd51791afe5). Also see [this discussion](http://stackoverflow.com/questions/38379125/touchid-activatetouchwithresponse-returns-success-without-requesting-fingerprint) in the native world and this Apple note {quote} The duration for which Touch ID authentication reuse is allowable. If the device was successfully authenticated using Touch ID within the specified time interval, then authentication for the receiver succeeds automatically, without prompting the user for Touch ID. The default value is 0, meaning that Touch ID authentication cannot be reused. The maximum allowable duration for Touch ID authentication reuse is specified by the LATouchIDAuthenticationMaximumAllowableReuseDuration constant. You cannot specify a longer duration by setting this property to a value greater than this constant. {quote} To restrict the reuse of an instance to a specific time, specify the allowableReuseDuration property in Titanium.
  11. Eric Wieber 2017-05-16

    Verified fixed, using: MacOS 10.12 (16A323) Studio 4.8.1.201612050850 Ti SDK 6.0.4.GA Appc NPM 4.2.9 Appc CLI 6.2.1 Alloy 1.9.11 Xcode 8.3.2 (8E2002) No longer encounter error when using createHTTPClient and authenticate is returning correct values. Tested using provided samples codes and with additional projects from other touchID ticket tests.

JSON Source