diff --git a/README.md b/README.md index 5366999..579b621 100644 --- a/README.md +++ b/README.md @@ -131,5 +131,6 @@ To disable the link preview feature again, do: ``` ## 5. Changelog +* 1.1.0 Found a solid way to deal with timing when to call into `onHomeIconPressed`. Should always work now, even on coldstart. * 1.0.1 Increased the timeouts a bit, so there is a better chance `onHomeIconPressed` gets called on coldstart. Thanks [#1](https://github.com/EddyVerbruggen/cordova-plugin-3dtouch/issues/1). * 1.0.0 Initial release (untagged) diff --git a/package.json b/package.json index 1cec3c3..2cf7f70 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "cordova-plugin-3dtouch", - "version": "1.0.1", + "version": "1.1.0", "description": "Add Quick Actions to your Home Screen which can be triggered by 3D Touch. Also, you can enable Link Preview with this plugin. Supported on iPhone6S an up.", "cordova": { "id": "cordova-plugin-3dtouch", diff --git a/plugin.xml b/plugin.xml index de0d41e..271f837 100644 --- a/plugin.xml +++ b/plugin.xml @@ -1,7 +1,7 @@ 3D Touch diff --git a/src/ios/app/AppDelegate+threedeetouch.m b/src/ios/app/AppDelegate+threedeetouch.m index cd37662..bba3d26 100644 --- a/src/ios/app/AppDelegate+threedeetouch.m +++ b/src/ios/app/AppDelegate+threedeetouch.m @@ -19,7 +19,7 @@ - (void) callJavascriptFunctionWhenAvailable:(NSString*)function { if (threeDeeTouch.initDone) { [threeDeeTouch.webView stringByEvaluatingJavaScriptFromString:function]; } else { - dispatch_after(dispatch_time(DISPATCH_TIME_NOW, 100 * NSEC_PER_MSEC), dispatch_get_main_queue(), ^{ + dispatch_after(dispatch_time(DISPATCH_TIME_NOW, 25 * NSEC_PER_MSEC), dispatch_get_main_queue(), ^{ [self callJavascriptFunctionWhenAvailable:function]; }); } diff --git a/src/ios/app/ThreeDeeTouch.h b/src/ios/app/ThreeDeeTouch.h index b3e436b..eb29fc5 100644 --- a/src/ios/app/ThreeDeeTouch.h +++ b/src/ios/app/ThreeDeeTouch.h @@ -4,6 +4,8 @@ @property BOOL initDone; +- (void) deviceIsReady:(CDVInvokedUrlCommand*)command; + - (void) isAvailable:(CDVInvokedUrlCommand*)command; - (void) configureQuickActions:(CDVInvokedUrlCommand*)command; diff --git a/src/ios/app/ThreeDeeTouch.m b/src/ios/app/ThreeDeeTouch.m index 9ddbe34..58ff172 100644 --- a/src/ios/app/ThreeDeeTouch.m +++ b/src/ios/app/ThreeDeeTouch.m @@ -5,11 +5,8 @@ @implementation ThreeDeeTouch -- (void)pluginInitialize { - // make sure the app is awake - dispatch_after(dispatch_time(DISPATCH_TIME_NOW, 300 * NSEC_PER_MSEC), dispatch_get_main_queue(), ^{ - self.initDone = YES; - }); +- (void) deviceIsReady:(CDVInvokedUrlCommand *)command { + self.initDone = YES; } - (void) isAvailable:(CDVInvokedUrlCommand *)command { diff --git a/www/ThreeDeeTouch.js b/www/ThreeDeeTouch.js index 39a54d9..c338a7b 100644 --- a/www/ThreeDeeTouch.js +++ b/www/ThreeDeeTouch.js @@ -20,3 +20,9 @@ ThreeDeeTouch.prototype.configureQuickActions = function (icons, onSuccess, onEr }; module.exports = new ThreeDeeTouch(); + +// call the plugin as soon as deviceready fires, this makes sure the webview is loaded, +// way more solid than relying on native's pluginInitialize. +document.addEventListener('deviceready', function() { + exec(null, null, "ThreeDeeTouch", "deviceIsReady", []); +}, false);