EddyVerbruggen / cordova-plugin-3dtouch

:point_down: Quick Home Icon Actions and Link Previews
MIT License
176 stars 50 forks source link

onHomeIconPressed not working but configureQuickActions works fine #32

Open enzor77 opened 7 years ago

enzor77 commented 7 years ago

Hi added the plugin to a project but I have some issues; QuickActions added properly but not fired when I use it. I'm working with an iphone7 with iOS 10.3

Below is the code I used inside the app.run JS:

$ionicPlatform.ready(function ($cordovaGlobalization) {

    ThreeDeeTouch.configureQuickActions([
      {
        iconType: 'Search', // optional   
        type: 'searchapplication', // optional, but can be used in the onHomeIconPressed callback
        title: 'Application', // mandatory
        subtitle: 'Search by Application' // optional
      },
      {
        iconType: 'Search', // optional, case insensitive     
        type: 'searchcode',
        title: 'Code',
        subtitle: 'Search by Code' // optional
      },
      {
        iconType: 'Search', // iconType is case insensitive   
        type: 'searchproduct',
        title: 'Product',
        subtitle: 'Search by Product' // optional       
      },
      {
        iconType: 'CapturePhoto', // iconType is case insensitive     
        type: 'searchbarcode',
        title: 'Barcode',
        subtitle: 'Scan Barcode' // optional        
      }
    ]);

    ThreeDeeTouch.onHomeIconPressed = function(payload) {
      console.log("Icon pressed. Type: " + payload.type + ". Title: " + payload.title + ".");
      if 
      (payload.type == 'searchapplication') {$state.go('app.vehicles');} 
      else if 
      (payload.type == 'searchcode') {$state.go('app.code');} 
      else if 
      (payload.type == 'searchproduct') {$location.path('app/product');} 
      else if 
      (payload.type == 'searchbarcode') {$location.path('app/barcode');} 
      else {
        // wrapping in a timeout, otherwise it collides with the splashscreen
        setTimeout(function() {
          alert(JSON.stringify(payload));
        }, 500);
      }
    };
        $rootScope.isWindows = device.platform == "windows";

        if (window.cordova && window.cordova.plugins && window.cordova.plugins.Keyboard && cordova.plugins.Keyboard.hideKeyboardAccessoryBar) {
            cordova.plugins.Keyboard.hideKeyboardAccessoryBar(false);
        }
        cordova.plugins.Keyboard.disableScroll( true );

        setTimeout(function() {
            navigator.splashscreen.hide();
        }, 100);
                $rootScope.$apply(); // This resolved!
    });
EddyVerbruggen commented 7 years ago

Have you also tried it as shown in the readme?

enzor77 commented 7 years ago

Any idea on how override the splashscreen collision? Any help will be much appreciated

enzor77 commented 7 years ago

Hi, what is teh difference between what I used and what is showed on readme? I'm using same procedure, if not wrong... Thanks a lot for your prompt reply

enzor77 commented 7 years ago

Hi all,

is not working from both, cold start and hot start!

santekotturi commented 7 years ago

@enzor77 try wrapping onHomeIconPressed in addEventListener

document.addEventListener('deviceready', function () {
 ThreeDeeTouch.onHomeIconPressed = function(payload) {
     console.log("Icon pressed. Type: " + payload.type + ". Title: " + payload.title + ".");
     if 
     (payload.type == 'searchapplication') {$state.go('app.vehicles');} 
     else if 
     (payload.type == 'searchcode') {$state.go('app.code');} 
     else if 
     (payload.type == 'searchproduct') {$location.path('app/product');} 
     else if 
     (payload.type == 'searchbarcode') {$location.path('app/barcode');} 
     else {
       // wrapping in a timeout, otherwise it collides with the splashscreen
       setTimeout(function() {
         alert(JSON.stringify(payload));
       }, 500);
     }
   };
})

[edit]: also, are your injecting $state and $location ? can you try without those and just get it to console.log the payload?

toriqo commented 7 years ago

hi,

the plugin stopped working for me as well. I had some custom icon templates, working fine and all of a sudden it stopped working. i've removed the plugin and re-added it, i've used the stock example code, nothing. should i remove and re-add the ios platform? though i wouldn't want to do that and go through all the hassle with the pods etc.

might have something to do with ios 10.3 (iphone7)

also, if i add your example code in the .plist file, both of those actions open my front camera (opening the front camera is one of the options i have set in the configureQuickActions)

thanks

toriqo commented 7 years ago

@EddyVerbruggen is this repo still maintained?

EddyVerbruggen commented 7 years ago

@toriqo Sure, all PR's are welcome as always.

toriqo commented 7 years ago

@EddyVerbruggen well, i was expecting some feedback regarding this issue :) do you know what's happening or should i do a pull request for a fix? :)

thanks

EddyVerbruggen commented 7 years ago

Do you have one?

toriqo commented 7 years ago

nope. but i could investigate and see what's wrong. just wanted to know if it's something you know about.

JoxieMedina commented 6 years ago

Anyone can help me , I'm experiencing the same problem with ionic v1 (1.3.1), the actions are correctly added but I can't make the method assigned to ThreeDeeTouch.onHomeIconPressed get trigger, I tried many ways to do it but no luck at the end I have an implementation pretty much like this : https://github.com/ashteya/ionic-tutorial-quickactions , If anyone can make it works please let me kwon how to do it

Greetings and thanks for your time and effort

akaNightmare commented 6 years ago

Guys, any movements to fix this issue?

JoxieMedina commented 6 years ago

Hi @akaNightmare , I managed to make this works with the following steps:

  1. Configure the Quick Actions in the config function in the angular module like this: ...

    .config(function () {
    document
      .addEventListener("deviceready", function () {
        ThreeDeeTouch.isAvailable(function (available) {
          if (available) { // Comment out this check if testing in simulator
            console.log('Configure 3D touch, available');
            // Configure Quick Actions
            ThreeDeeTouch.configureQuickActions([
              {
                type: 'send', // optional, but can be used in the onHomeIconPressed callback
                title: 'Enviar Dinero', // mandatory
                iconType: 'location' // optional
              }, {
                type: 'pay',
                title: 'Pay',
                iconType: 'compose' // optional
              }, {
                type: 'locations',
                title: 'Locations',
                iconType: 'markLocation' // optional
              }
            ]);
    
          }
        })
    
      }, false);

    ...

  2. Add the actions listener in the run function in the angular module like this: ...

    
    .run(function ($rootScope) {
    document
      .addEventListener('deviceready', function () {
        ThreeDeeTouch.onHomeIconPressed = function (payload) {
          console.log("Icon pressed. Type: " + payload.type + ". Title: " + payload.title + ".");
          if (payload.type == 'send') {
            $rootScope.$broadcast('openQuickSend');
          } else if (payload.type == 'pay') {
            $rootScope.$broadcast('openQuickPay');
          } else if (payload.type == 'locations') {
            $rootScope.$broadcast('openQuickSendLocations');
          }
        };
      }, false)
...
3. Note that I'm using `$rootScope.$broadcast()` to emit another event in the rootScope so  the actions can be trigger in the controllers for example I handle all the actions in the `
MainCtrl`, each one look like this: 

...

$rootScope.$on('openQuickSendLocations', function () { console.log('opening locations') $state.go('locations'); });



...

I hope this helps you!
akaNightmare commented 6 years ago

@enzor77 thanks, however, I using ionic3. Also, I found how to fix this issue, just need to update ionic/native package and particular commit for this fix -> https://github.com/ionic-team/ionic-native/commit/6cd97ca

jesobreira commented 4 years ago

Did we run into the same issue again?

The modification posted by @akaNightmare was done in a file that does not exist anymore on Ionic Native's codebase.

And onHomeIconPressed does not fire for me either, although configureQuickActions works. From my debugging, the plugin's performActionForShortcutItem is not running (using with Ionic/Capacitor).

stevenleija commented 4 years ago

Did we run into the same issue again?

The modification posted by @akaNightmare was done in a file that does not exist anymore on Ionic Native's codebase.

And onHomeIconPressed does not fire for me either, although configureQuickActions works. From my debugging, the plugin's performActionForShortcutItem is not running (using with Ionic/Capacitor).

I have the same issue. Were you able to get it to work?

jesobreira commented 4 years ago

Hi, @stevenleija ! I didn't. My codebase has changed recently to React Native, so I won't be looking at solutions anymore.

mobileias commented 1 year ago

hello

does anyone solve this issue into ionic 5 and capacitor?

My end also same issue, it not called onHomeIconPressed

Thanks