edismooth / ionic2-firebase

[DEPRECATED] Easy example of Firebase working with Ionic 2.
33 stars 16 forks source link

No push notification? #1

Closed ericmachine88 closed 8 years ago

ericmachine88 commented 8 years ago

When I first load the app on my iphone 6s, got this error

<FIRInstanceID/WARNING> Failed to fetch default token Error Domain=com.firebase.iid Code=0 "(null)" Unable to connect to FCM. Error Domain=com.google.fcm

my app which i signed up was com.mydomain.firebase

already changed the bundle in xcode, but not sure how did the com.firebase.iid and com.google.fcm came into the picture...

when i tried to push a few messages, noticed in my debug xcode ...

DEV Test[6723:3911240] {"collapse_key":"com.mydomain.firebase","wasTapped":false,"notification":{"e":"1","body":"aloha"},"from":"54674477610"}

Any idea what's the issue? Thanks.

snehoo commented 8 years ago

Android went fine, in IOS I get an error while trying to Build on device on the file FCMPlugin.m on line [self.webViewEngine evaluateJavaScript:notifyJS completionHandler:nil];

error >> Property 'webViewEngine' not found on object of type 'FCMPlugin *'

if i comment that line, app runs okay then returns error like ericmachine88

any idea?

edismooth commented 8 years ago

@snehoo Hi, I don't have that error, but it's weird. @ericmachine88 It looks like your device received a message. Did you make all certificates?

snehoo commented 8 years ago

Yes all okay now but xCode returns the error if i uncomment that line, yes created all certificates, Notifications are received in iOS and Android now.

edismooth commented 8 years ago

@snehoo It should be something with Firebase plugin.

snehoo commented 8 years ago

Yes thats actually the Cordova FCM plugin files. will post it there too.

edismooth commented 8 years ago

@snehoo @ericmachine88 Please open Xcode and check: Capabilities -> Background Modes -> Remote notifications It should help:)

snehoo commented 8 years ago

Yes did that, now all okay, but that line remains commented, so you can close this

ericmachine88 commented 8 years ago

okay, i will try that tonight.

by the way, is there any ionic 1 example using this plugin?

snehoo commented 7 years ago

@ericmachine88 i wrote a Ionic 1 example using the same steps written by @edismooth , pretty straight forward, the code is not the hard part, the hard part is to get all aspects in place so they all work together and fire than damn notification.

the ionic ready code block is the only thing you'll need for this to work from Ionic point of view, this bit is exactly same.

 this.platform.ready().then(() => {
            // Okay, so the platform is ready and our plugins are available.
            // Here you can do any higher level native things you might need.
            StatusBar.styleDefault();

            FCMPlugin.getToken(
                function (token) {
                    console.log(token);
                    alert(token);
                },
                function (err) {
                    console.log('error retrieving token: ' + err);
                }
            );

            FCMPlugin.onNotification(
                function(data){
                    if(data.wasTapped){
                        //Notification was received on device tray and tapped by the user.
                        alert( JSON.stringify(data) );
                    }else{
                        //Notification was received in foreground. Maybe the user needs to be notified.
                        alert( JSON.stringify(data) );
                    }
                },
                function(msg){
                    console.log('onNotification callback successfully registered: ' + msg);
                },
                function(err){
                    console.log('Error registering onNotification callback: ' + err);
                }
            );
ericmachine88 commented 7 years ago

Thanks @snehoo

But I got error running it ... even enabled like the one suggested by @edismooth (not working).


28A77C64-7C65-475A-8881-95B580421D37/HelloCordova.app/www/index.html
2016-07-15 01:37:55.705 HelloCordova[8311:5026029] Cordova view ready
2016-07-15 01:37:55.729 HelloCordova[8311:5026029] get Token
2016-07-15 01:37:55.729 HelloCordova[8311:5026029] view registered for notifications
2016-07-15 01:37:55.729 HelloCordova[8311:5026029] FCMPlugin.js: is created
2016-07-15 01:37:55.729 HelloCordova[8311:5026029] FCMPlugin Ready OK
2016-07-15 01:37:55.732 HelloCordova[8311:5026029] onNotification callback successfully registered: null
2016-07-15 01:37:56.621 HelloCordova[8311:] <FIRAnalytics/INFO> Firebase Analytics enabled
2016-07-15 01:37:56.901 HelloCordova[8311:5026029] app become active
2016-07-15 01:37:56.902 HelloCordova[8311:5026029] Set state foreground
2016-07-15 01:37:56.914 HelloCordova[8311:5026029] null
2016-07-15 01:37:57.064 HelloCordova[8311:5026029] InstanceID token: (null)
2016-07-15 01:37:57.064 HelloCordova[8311:5026029] Unable to connect to FCM. Error Domain=com.google.fcm Code=2001 "(null)"
2016-07-15 01:37:58.130 HelloCordova[8311:5026029] Connected to FCM.
2016-07-15 01:37:58.140: <FIRMessaging/WARNING> Failed to subscribe to topic Error Domain=com.google.fcm Code=5 "(null)"
2016-07-15 01:37:58.140: <FIRMessaging/WARNING> Failed to subscribe to topic Error Domain=com.google.fcm Code=5 "(null)"
2016-07-15 01:38:02.913: <FIRInstanceID/WARNING> Failed to fetch default token Error Domain=com.firebase.iid Code=0 "(null)"
2016-07-15 01:38:16.534: <FIRInstanceID/WARNING> Failed to fetch default token Error Domain=com.firebase.iid Code=0 "(null)"

Any idea? Thanks.

snehoo commented 7 years ago

yes this happened a couple of times, finally it worked everytime, try deleting the app in iOS and doing a fresh build. btw the logs still return an error like above, but the device token gets generated and also subscription works. try subscription doing a timeout delay, without a token it wont subscribe.