EddyVerbruggen / cordova-plugin-3dtouch

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

onHomeIconPressed not working (even after reading all issues about it) #48

Open clampinou opened 3 years ago

clampinou commented 3 years ago

Hi!

I saw all issues about it but nothing working for me... Subscribing to onHomeIconPressed does nothing, even in "platform.ready().then()"... Besides, I have another error that I can't explain:

To Native Cordova ->  ThreeDeeTouch configureQuickActions INVALID ["options": [<__NSArrayM 0x280038690>(
{
    iconType = Compose;
    title = "New test";
    type = newtest;
}
)
]]

Maybe my problem comes from here? 👆

I'm using:

Ionic 4 with Capacitor
Angular 10
cordova-plugin-3dtouch 1.3.8
@ionic-native/three-dee-touch 5.29.0
Developping / Running on iPhone X on iOS 14

In my app.module.ts (am I forgetting something here maybe?):

import { ThreeDeeTouch } from '@ionic-native/three-dee-touch/ngx';
...
and put "ThreeDeeTouch" in providers

My app.component.ts code:

this.platform.ready().then(() => {
      this.statusBar.styleDefault();

      **// Trigger 3D Touch options ---> SAME CODE AS IONIC DOC
      this.threeDeeTouch.isAvailable().then(isAvailable => console.log('3D Touch available? ' + isAvailable));

      this.threeDeeTouch.watchForceTouches()
        .subscribe(
          (data: ThreeDeeTouchForceTouch) => {
            console.log('Force touch %' + data.force);
            console.log('Force touch timestamp: ' + data.timestamp);
            console.log('Force touch x: ' + data.x);
            console.log('Force touch y: ' + data.y);
          }
        );

      let actions: ThreeDeeTouchQuickAction[] = [
        {
          type: 'newtest',
          title: 'New test',
          iconType: 'Compose'
        }
      ];

      this.threeDeeTouch.configureQuickActions(actions);

      this.threeDeeTouch.onHomeIconPressed().subscribe(
        (payload) => {
          // returns an object that is the button you presed
          console.log('Pressed the ${payload.title} button');
          console.log(payload);
        },
        error => console.log('Error on 3D Touch action', error)
      );**

      // Trigger the push setup 
      this.fcmService.initPush();

      this.splashScreen.hide();
    });

And here is my XCode log:

⚡️  [log] - onscript loading complete
⚡️  WebView loaded
⚡️  [log] - Angular is running in development mode. Call enableProdMode() to enable production mode.
**To Native Cordova ->  ThreeDeeTouch deviceIsReady INVALID ["options": []]**
⚡️  [log] - Ionic Native: deviceready event fired after 400 ms
To Native Cordova ->  ThreeDeeTouch isAvailable ThreeDeeTouch251958499 ["options": []]
To Native Cordova ->  ThreeDeeTouch watchForceTouches ThreeDeeTouch251958500 ["options": []]
⚡️  [log] - [{"type":"newtest","title":"New test","iconType":"Compose"}]
**To Native Cordova ->  ThreeDeeTouch configureQuickActions INVALID ["options": [<__NSArrayM 0x280038690>(
{
    iconType = Compose;
    title = "New test";
    type = newtest;
}
)
]]**
⚡️  [log] - 3D Touch available? true
⚡️  [info] - [WDS] Live Reloading enabled.

If anybody can help... 🙏

binchik commented 3 years ago

I'm having the same issue. My project is built on top of capacitor.

The performActionForShortcutItem is never called.

@clampinou did you find any solution to this?

sertal70 commented 3 years ago

Hi all, I'm having the same issue. Here it is my project env:

Ionic:

   Ionic CLI                     : 6.12.1
   Ionic Framework               : @ionic/angular 5.3.1
   @angular-devkit/build-angular : 0.1000.5
   @angular-devkit/schematics    : 9.1.12
   @angular/cli                  : 9.1.12
   @ionic/angular-toolkit        : 2.2.0

Capacitor:

   Capacitor CLI   : 2.4.0
   @capacitor/core : 2.4.0

Utility:

   cordova-res (update available: 0.15.2) : 0.15.1
   native-run                             : not installed

System:

   NodeJS : v12.16.1 
   npm    : 6.13.4
   OS     : macOS Catalina

@EddyVerbruggen any chance you can have a look at it?

csmark97 commented 3 years ago

Here is a way to avoid this problem:

Native part:

Add this code to AppDelegate.swift

func application(_ application: UIApplication, performActionFor shortcutItem: UIApplicationShortcutItem, completionHandler: @escaping (Bool) -> Void) {
        let webView = self.window?.rootViewController?.view as? WKWebView;

        webView?.evaluateJavaScript("window.shortcutItemType = '\(shortcutItem.type)'")
}

TypeScript part:

When the application starts you can exmine this variable eg.: (window as any).shortcutItemType. So if this variable is not null, quick start is needed.

NLueg commented 3 years ago

@csmark97 thank you very much for your suggestion, works perfectly for me! To also make it work when the app is still in background I use this piece of code for my capacitor app:

      App.addListener("appStateChange", (change) => {
        if (change.isActive && (window as any).shortcutItemType) {
          this.navigateToPageById((window as any).shortcutItemType);
          (window as any).shortcutItemType = null;
        }
      });
Rom3ik commented 2 years ago

@NLueg Hi, Sir. i have the same problem, but your method doesn't helped :( shortcuts appears but no reaction on onHomeIconPressed. i got the same error about INVALID options. I'l be glad if you share a piece of your code. maybe i'm doing it wrong.

NLueg commented 2 years ago

Hey @Rom3ik, I actually don't use this plugin, but I moved to https://github.com/NePheus/capacitor-android-shortcuts which works pretty well for me. But I don't think that the opening of Item is different here. I can still share you my code which is a bit different from what I mentioned above:

AppDelegate.swift:

    func application(_ application: UIApplication, performActionFor shortcutItem: UIApplicationShortcutItem, completionHandler: @escaping (Bool) -> Void) {
        let webView = self.window?.rootViewController?.view as? WKWebView;
        webView?.evaluateJavaScript("window.shortcutItemType = '\(shortcutItem.type)'")
    }

x.service.ts:

constructor(deviceService: DeviceService) {
  if (this.deviceService.isIos) {
    if ((window as any).shortcutItemType) {
      this.navigateToPageById((window as any).shortcutItemType);
      (window as any).shortcutItemType = null;
    }

    App.addListener('appStateChange', (change) => {
      if (change.isActive && (window as any).shortcutItemType) {
        this.navigateToPageById((window as any).shortcutItemType);
        (window as any).shortcutItemType = null;
      }
    });
  }
}

For Android, it's actually pretty straightforward with the mentioned plugin. Only iOS requires this workaround.

Rom3ik commented 2 years ago

NLueg Thanks a lot for reply. I'll check it out. Have a good day.

mobileias commented 1 year ago

we also face same issue

does anyone fix issue

Ionic:

Ionic CLI : 6.20.8 (/usr/local/lib/node_modules/@ionic/cli) Ionic Framework : 7.0.5 @angular-devkit/build-angular : 15.2.6 @angular-devkit/schematics : 15.2.6 @angular/cli : 15.2.6 @ionic/angular-toolkit : 9.0.0

Capacitor:

Capacitor CLI : 4.7.3 @capacitor/android : 4.7.3 @capacitor/core : 4.7.3 @capacitor/ios : 4.7.3

Utility:

cordova-res : 0.15.4 native-run : 1.7.2

System:

NodeJS : v14.20.0 (/usr/local/bin/node) npm : 6.14.17 OS : macOS