EddyVerbruggen / nativescript-plugin-firebase

:fire: NativeScript plugin for Firebase
https://firebase.google.com
MIT License
1.01k stars 444 forks source link

Not receiving notification in IOS both foreground and background #1511

Closed donny08 closed 4 years ago

donny08 commented 4 years ago

Hi @EddyVerbruggen I'm unable to receive the notification on IOS, its working fine on android. I followed the steps on both the firebase console and on the plugin github page.

I'm using "nativescript-plugin-firebase": "^8.3.2" version.

Here is my app.components.ts file: `import { Component, OnInit } from "@angular/core"; const firebase = require("nativescript-plugin-firebase");

@Component({ selector: "ns-app", moduleId: module.id, templateUrl: "./app.component.html" }) export class AppComponent implements OnInit {

ngOnInit() {
  firebase.init({
        showNotifications: true,
        showNotificationsWhenInForeground: true
    }).then(function(instance) {
        console.log("firebase.init done");
    }, function(error) {
        console.log("firebase.init error: " + error);
    });

    firebase.addOnPushTokenReceivedCallback(
        function(token) {
            console.log("Firebase push token: " + token);
            if (token) {
                localStorage.setItem('firebaseToken', token);
            }
        }
    );

    firebase.addOnMessageReceivedCallback(
        function(message) {
            console.log("Push message received: " + JSON.stringify(message));
            let options = {
                title: "",
                message: message.title,
                okButtonText: "Ok",
                cancelButtonText: ""
            };

            confirm(options).then((result: boolean) => {
            });
        }
    );

}` Please find repo: https://github.com/donny08/flow-firebase.git

EddyVerbruggen commented 4 years ago

Your repo looks pretty good. One thing I'd suggest is moving those addOnPushTokenReceivedCallback and addOnMessageReceivedCallback inside the init function because those will now run before init has completed. There are properties for those in the init method where you can add these.

Three further questions:

donny08 commented 4 years ago

@EddyVerbruggen Do you receive the push token? Yes, I am receiving Did you try sending a notification with the CURL command in the readme? (if not, please do), No Are you testing this on a real device (iOS sim doesn't support push notifications), Yes via Wifi

donny08 commented 4 years ago

@EddyVerbruggen I tried curl command I am receiving below error: {"multicast_id":6785295490326455016,"success":0,"failure":1,"canonical_ids":0,"results":[{"error":"InvalidApnsCredential"}]}

EddyVerbruggen commented 4 years ago

That's a problem with your APNs certificate then. Has nothing to do with the client side.

donny08 commented 4 years ago

@EddyVerbruggen Now it is showing notification only if i trigger from firbase console. If i trigger from curl i m getting same error

donny08 commented 4 years ago

Working fine !!!. Thanks