EddyVerbruggen / cordova-plugin-3dtouch

:point_down: Quick Home Icon Actions and Link Previews

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

onHomeIconPressed pass nothing when app wasn't run previously

OleksandrPoltavets opened this issue · comments

Hello, maybe it is not an issue and I missed something in plugin documentation but I have the following behaviour, when I run app and make it foreground I have 3D touch icons and all actions works good with pressing them but if I close app (unload it from memory), I have 3D icons but they just run my app from the default state and doesn't pass any 3D touch type events. Could someone please advice what I'm doing wrong or maybe it is not available in this plugin?

That should be supported by this plugin; a cold start should invoke that function.

Are you sure the function is available as soon as the app starts? Perhaps sharing your project would help us figure it out.

In this case maybe something wrong with my code, I'll try something different and share results, if this will not help I'll share my code.
Thanks for reply!

@OleksandrPoltavets Did you find a solution? I have the same problem

@Jarvey feel free to share your project and I'll take a look.

@EddyVerbruggen
I've created a demo that you can clone at https://github.com/Maziar-Fotouhi/3DTouch-Demo.git
The demo app will show an alert when the ThreeDeeTouch.onHomeIconPressed method is called.
The problem is this method is not called from a cold start.

I open the project in xcode by typing meteor run ios-device.
I'm testing the app on a real device (iPhone6s plus running iOS 9.2)

I run the app from xcode, then hit the home button to put the app in the background. After that I can force touch to open the quick action menu and select a menu item. The app resumes and successfully shows the alert dialog.

Then double tap the home button and swipe close the app and try the same thing again. This time the alert does not appear.

Thanks a lot @Maziar-Fotouhi, I love it when folks take the effort of providing a sample app to reproduce the problem. Because I was able to debug your projects I quickly saw what the problem was. I've never used Meteor, so I learned from your project that there is a two-step launch going on, where Meteor needs to do a lot of initialization after deviceready has fired. The plugin assumed everything to be ready upon deviceready, so it immediately tries to invoke your onHomeIconPressed function. In a Meteor app however this method is not yet available, so the plugin will now check for the function to exist during the first 5 seconds after launch. That works nicely for Meteor and probably for any similar framework out there.

Available in the (now published) 1.3.3 version.

Thanks @EddyVerbruggen .
I really appreciate your professional and quick response.
New version fixed the problem.

A new issue has surfaced though.
The first time that I install the app through xcode, the quick action menu does not work at all. I have to swipe close the app and try again. After closing the app once, the menu starts working.

That's expected as your app's JS logic will add those home actions and your JS hasn't run before your app is launched for the first time.

That's why I added the chapter 'Static Home Icon Actions' to the readme, I hope that helps.

@EddyVerbruggen I think it should be working, since when we install the app with xcode, it does launch the app too, and we are initiating the quick action menu on "onDeviceReady".

I did revert to the previous version (1.3.2) and it is working from the first run.
The new version does not work the first time the app is run though.

Thanks again.

@Maziar-Fotouhi When you run it from Xcode the apps runs immediately. That's not the same as when installing it from the AppStore (where it doesn't immediately run). So I'm not sure we're on the same page here.

@EddyVerbruggen Thank you for all the great work and cool plugins.
Could you please give us access to set the "remaining attempts" variable or the amount of timeout that is begin used here ?

It would be nice to be able to set either of these through a plugin method call.
That is because, for me when the app is closed , the quick action menu may or may not work (and again, I'm using Meteor). I would like to be able to change this amount of time to make sure it is not because of the fact that onDeviceReady is not triggered yet occasionally (times that it does not work).

Thanks!

So your app now has 5 seconds to get ready. I don't want to overcomplicate things so rather not expose it. But would 10 or 15 secs suffice?

Of course. It makes sense.

10 or 15 should be more than enough. If it doesn't work with 15 sec timeout, then I can be sure that it is not the onDeviceReady.

Thanks a lot.

15 it is! 3.3.4 has just been released.

I'm just posting this for all the people out there who are using this plugin with meteor.

The quick action menu did not work with meteor on cold starts of the app (when the app is closed and you try to use one of the menu items to start it). But update 1.3.3 took care of it to some extent.

With update 1.3.3 the plugin started working but it was not consistent and it still did not work sometimes. The problem was that onDeviceReady was triggered and it was capturing the menu button that was chosen, but, some of the other methods that I was using for these events (e.g. inAppBrowser), were not loaded yet.

So this is what I ended up doing:

  1. I set the session when onDeviceReady is triggered.
    screen shot 2016-02-02 at 9 27 29 am
  2. I also call a setup function in onDeviceReady (We will see what this does in a bit).
    screen shot 2016-02-02 at 9 27 44 am
  3. Then I call a process and reset function in autorun which handles reactive variables.
    screen shot 2016-02-02 at 9 28 06 am
  4. I also set the default for these session variables.
    screen shot 2016-02-02 at 9 28 25 am
  5. Then I capture the payload in a session variable in the setup function and do whatever I want with it (just as described in the plugin tutorial) in the process function.
    screen shot 2016-02-02 at 9 29 54 am
  6. Finally, the reset function sets the session variable to an empty state so we can capture two successive quick action menu buttons when the same button is chosen again. (note that autorun only triggers when at least one of the variables is changed )
    screen shot 2016-02-02 at 9 30 04 am

This will give other methods and plugins a little extra time to load before you can use them in the 3dtouch plugin.

Thanks to @EddyVerbruggen and my genius colleague @mjwheatley who figured all of these out!
Hope this helps.

Hello Maziar-Fotouhi, i'm trying this plugin in meteor I've tested this plugin on iPhone 6s (iOS ver.-9.2) and app was build with Xcode 7 as per the minimum requirements of this plugin to work, but when i'm checking the availability of the plugin, the following code returns me false, am i doing something wrong?

ThreeDeeTouch.isAvailable(function (avail) {
// 'avail' is a boolean
alert("avail? " + avail)
});

@array-addu, your comment from issue #11

yes, actually i'm implementing this in meteor, in meteor, Meteor.startup() is equivalent to device ready.

This is not 100% accurate. Just to be safe you should use an onDeviceReady callback

Meteor.startup(function () {
    ThreeDeeTouch.isAvailable(function (avail) {
        // 'avail' is a boolean
        console.log("Meteor.startup() ThreeDeeTouch.isAvailable: " + avail);  // true
    });
    if (Meteor.isCordova) {
        document.addEventListener('deviceready', onDeviceReady, false);
    }
});

function onDeviceReady() {
    ThreeDeeTouch.isAvailable(function (avail) {
        // 'avail' is a boolean
        console.log("onDeviceReady() ThreeDeeTouch.isAvailable: " + avail);  // true
    });
};

In this case isAvailable() is true in both places as long as you are testing on a real device. It seems the emulator will always return false as this feature is not available on emulators.

Ah ! It's working now. Thank you mjwheatley. One more thing i want to confirm, onHomeIconPressed would work only for App home icon but if we want to implement 3d touch inside the app, do we have to make the custom list after getting the coordinates from watchForceTouches?

For this purpose it is necessary to prescribe ThreeDeeTouch.enableLinkPreview();

I'm using v1.3.7 with ionic and I have the similar problem here. What's the suggestion to get the payload when the app wasn't run previously?

I'm using it in deviceready and the code works fine when the App is running in the background. But if it's killed or hasn't be running previously, there would be no payload information because the stream was subscribed after the event was fired.

document.addEventListener('deviceready', () => {
      console.log('-------------- device ready');
      this._initTouch();
});

  protected _initTouch() {
    this.threeDeeTouch.isAvailable()
      .then(isAvailable => {
        this._log('isAvailable: ' + isAvailable);
      });

    this.threeDeeTouch.onHomeIconPressed().subscribe(payload => {
      this._log('playload: ' + JSON.stringify(payload));
    });
  }