nativescript-community / push

Apache License 2.0
9 stars 3 forks source link

Missing delegate #7

Open Reached opened 2 years ago

Reached commented 2 years ago

Hi there,

First of all, thanks for providing this!

I installed the plugin, however upon building my project, I get this error:

Cannot find module 'nativescript-plugin-firebase/scripts/entitlements-before-prepare.js'
Require stack:
- /Users/caspersorensen/Developer/egtved-app/hooks/before-prepare/nativescript-plugin-firebase.js
- /usr/local/lib/node_modules/nativescript/lib/common/services/hooks-service.js
- /usr/local/lib/node_modules/nativescript/lib/common/yok.js
- /usr/local/lib/node_modules/nativescript/lib/bootstrap.js
- /usr/local/lib/node_modules/nativescript/lib/nativescript-cli.js
- /usr/local/lib/node_modules/nativescript/bin/tns

Nativescript: 8.3.3 iOS 16 iPhone XR (real device, but seems to also happen on simulator)

Any help is appreciated here!

farfromrefug commented 2 years ago

@Reached you must have had nativescript-plugin-firebase installed before and some hooks are remaining. maybe try to run ns clean

Reached commented 2 years ago

@farfromrefug I did some more digging, and the issue was probably the order of execution (since I am using NS-vue), so I moved the init() into the created method and wrapped it in a method which is provided by vue, and now the code runs, so thank you for leading me down that path :)

For anyone bumping into this with Nativescript Vue:

import * as messaging from "@nativescript-community/push";

new Vue({
  render: (h) => h(App),
  created() {
    this.$nextTick(() => {
      messaging.init();

      setTimeout(() => {
        this.requestPermission();
      }, 3000);
    });
  },
  methods: {
    requestPermission() {
      Dialogs.confirm("Do you want to register for push?").then((result) => {
        messaging.registerForPushNotifications({
          onPushTokenReceivedCallback: (token) => {
            console.log("Firebase plugin received a push token: " + token);
          },

          onMessageReceivedCallback: (message) => {
            console.log("Push message received:", message);
          },

          // Whether you want this plugin to automatically display the notifications or just notify the callback. Currently used on iOS only. Default true.
          showNotifications: true,

          // Whether you want this plugin to always handle the notifications when the app is in foreground. Currently used on iOS only. Default false.
          showNotificationsWhenInForeground: true
        }).then(() => console.log("Registered for push"));
      });
    }
  }
}).$start()

After accepting the push, the token always seem to come back as undefined though, I feel like I must be missing something, could you have a look?

Info.plist (shortened for brevity):

    ...
    <key>UIBackgroundModes</key>
    <array>
        <string>remote-notification</string>
    </array>
    <key>UseExternalPushProvider</key>
    <true/>
</dict>
</plist>

entitlements file:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
    <key>com.apple.security.cs.allow-unsigned-executable-memory</key>
    <true/>
    <key>com.apple.security.network.client</key>
    <true/>
    <key>aps-environment</key>
    <string>development</string>
</dict>
</plist>
farfromrefug commented 2 years ago

@Reached great you fixed it but clearly the error you posted first had nothing to do with order nor with this plugin actually. it had to do with the plugin nativescript-plugin-firebase

Reached commented 2 years ago

That might be yes, it's fixed now, and now there is a new error. Do you have any idea? Or a demo repository perhaps? :)

Reached commented 2 years ago

Also my example will serve to help people solve issues with this in the future :)

farfromrefug commented 2 years ago

@Reached no i dont know right now. You need to add logs and see what s happening. You can for example print the callstack. And no demo app cause it requires setting a full working app and we dont have a "community" account.

VitorHFLopes commented 1 year ago

@Reached you must have had nativescript-plugin-firebase installed before and some hooks are remaining. maybe try to run ns clean

thanks!

totally forgot this command 🤣

robertoamorim7 commented 1 year ago

@Reached you must have had nativescript-plugin-firebase installed before and some hooks are remaining. maybe try to run ns clean

Dude I love you so much