Phonegap Sencha Touch Pin Code feature

A couple of days ago, I added the Pin Code locking functionality in Diary Mobile mobile app. It required some tinkering with iOS Objective-C, Android Java and HTML5 javascript code.

First I added a code in the onReady function of Sencha Touch


Ext.setup({
  //...
  onReady: function() {
  //...
    appActive = function() {
      Util.logger('===app is now active in function====');
      showVerifyPinCB();
    };
  //...
}

The showVerifyPinCB() function displays the pin code panel in the form:

Pin Code/Lock screen

 

 

This screen is also reused as a setting up the pin code screen. Now comes the Objective-C code:

- (void)applicationDidBecomeActive:(UIApplication *)application { 
 // delay of 1ms ensures code will be executed in new stack trace 
 // that way, event listener can't block applicationDidBecomeActive 
 // and crash the app 
 NSLog(@"%@",@"applicationDidBecomeActive\n"); 
 NSString *fireActiveEvent = @"window.setTimeout(appActive, 1);"; 
 [self.webView stringByEvaluatingJavaScriptFromString:fireActiveEvent]; 
} 

As mentioned in the comments, it calls the javascript appActive function after a 1 nanosecond delay. This code is placed in the diary_mobileAppDelegate.m file.
Similarly, for Android the code to be placed in the class that extends DroidGap is:


public class DiaryMobile extends DroidGap
{
//...
    @Override
    public void onStart()
    {
      appView.loadUrl("javascript:window.setTimeout(appActive, 1);");
      super.onStart();
    }
//...
}

For me this got the job done and cleared a major hurdle of firing an event from Objective-C/Java and catching it from javascript. After that I just had to write up the code to enable/disable pin code and verify the pin code to unlock the screen.

Advertisements

3 Comments

  1. I actually was basically hunting for recommendations for
    my site and noticed your own blog post, “Phonegap Sencha Touch Pin Code feature
    | disturbance under still waters”, do you mind in the event I actually employ
    a few of your own concepts? I am grateful ,Dylan

    • Sure, go ahead but remember Sencha Touch has been vastly updated since then

  2. My approach is based on the article cited in this entry. Its only drawback is that the generated TIFF is 16 bits per channel, and some tools (namely G Click http://www.l33turl.com/dukcc091745


Comments RSS TrackBack Identifier URI

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s