Open Reached opened 2 years ago
@Reached you must have had nativescript-plugin-firebase
installed before and some hooks are remaining. maybe try to run ns clean
@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>
@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
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? :)
Also my example will serve to help people solve issues with this in the future :)
@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.
@Reached you must have had
nativescript-plugin-firebase
installed before and some hooks are remaining. maybe try to runns clean
thanks!
totally forgot this command 🤣
@Reached you must have had
nativescript-plugin-firebase
installed before and some hooks are remaining. maybe try to runns clean
Dude I love you so much
Hi there,
First of all, thanks for providing this!
I installed the plugin, however upon building my project, I get this error:
Nativescript: 8.3.3 iOS 16 iPhone XR (real device, but seems to also happen on simulator)
Any help is appreciated here!