Giter Club home page Giter Club logo

cordova-plugin-fcm's Introduction

Google Firebase Cloud Messaging Cordova Push Plugin

Extremely easy plug&play push notification plugin for Cordova applications with Google Firebase FCM.

paypal

Version 2.1.2 (03/06/2017)

  • Tested on Android and iOS using Cordova cli 6.4.0, Cordova android 6.0.0 and Cordova ios 4.3.1
  • Available sdk functions: onTokenRefresh, getToken, subscribeToTopic, unsubscribeFromTopic and onNotification
  • 'google-services.json' and 'GoogleService-Info.plist' are added automatically from Cordova project root to platform folders
  • Added data payload parameter to check whether the user tapped on the notification or was received while in foreground.
  • Free testing server available for free! https://cordova-plugin-fcm.appspot.com

Installation

Make sure you have ‘google-services.json’ for Android or ‘GoogleService-Info.plist’ for iOS in your Cordova project root folder. You don´t need to configure anything else in order to have push notification working for both platforms, everything is magic.

cordova plugin add cordova-plugin-fcm

Firebase configuration files

Get the needed configuration files for Android or iOS from the Firebase Console (see docs: https://firebase.google.com/docs/).

Android compilation details

Put the downloaded file 'google-services.json' in the Cordova project root folder.

You will need to ensure that you have installed the appropiate Android SDK libraries.

⚠️ For Android >5.0 status bar icon, you must include transparent solid color icon with name 'fcm_push_icon.png' in the 'res' folder in the same way you add the other application icons. If you do not set this resource, then the SDK will use the default icon for your app which may not meet the standards for Android >5.0.

iOS compilation details

Put the downloaded file 'GoogleService-Info.plist' in the Cordova project root folder.

Usage

⚠️ It's highly recommended to use REST API to send push notifications because Firebase console does not have all the functionalities. Pay attention to the payload example in order to use the plugin properly.
You can also test your notifications with the free testing server: https://cordova-plugin-fcm.appspot.com

Receiving Token Refresh

//FCMPlugin.onTokenRefresh( onTokenRefreshCallback(token) );
//Note that this callback will be fired everytime a new token is generated, including the first time.
FCMPlugin.onTokenRefresh(function(token){
    alert( token );
});

Get token

//FCMPlugin.getToken( successCallback(token), errorCallback(err) );
//Keep in mind the function will return null if the token has not been established yet.
FCMPlugin.getToken(function(token){
    alert(token);
});

Subscribe to topic

//FCMPlugin.subscribeToTopic( topic, successCallback(msg), errorCallback(err) );
//All devices are subscribed automatically to 'all' and 'ios' or 'android' topic respectively.
//Must match the following regular expression: "[a-zA-Z0-9-_.~%]{1,900}".
FCMPlugin.subscribeToTopic('topicExample');

Unsubscribe from topic

//FCMPlugin.unsubscribeFromTopic( topic, successCallback(msg), errorCallback(err) );
FCMPlugin.unsubscribeFromTopic('topicExample');

Receiving push notification data

//FCMPlugin.onNotification( onNotificationCallback(data), successCallback(msg), errorCallback(err) )
//Here you define your application behaviour based on the notification data.
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) );
    }
});

Send notification. Payload example (REST API)

Full documentation: https://firebase.google.com/docs/cloud-messaging/http-server-ref
Free testing server: https://cordova-plugin-fcm.appspot.com

//POST: https://fcm.googleapis.com/fcm/send
//HEADER: Content-Type: application/json
//HEADER: Authorization: key=AIzaSy*******************
{
  "notification":{
    "title":"Notification title",
    "body":"Notification body",
    "sound":"default",
    "click_action":"FCM_PLUGIN_ACTIVITY",
    "icon":"fcm_push_icon"
  },
  "data":{
    "param1":"value1",
    "param2":"value2"
  },
    "to":"/topics/topicExample",
    "priority":"high",
    "restricted_package_name":""
}
//sound: optional field if you want sound with the notification
//click_action: must be present with the specified value for Android
//icon: white icon resource name for Android >5.0
//data: put any "param":"value" and retreive them in the JavaScript notification callback
//to: device token or /topic/topicExample
//priority: must be set to "high" for delivering notifications on closed iOS apps
//restricted_package_name: optional field if you want to send only to a restricted app package (i.e: com.myapp.test)

How it works

Send a push notification to a single device or topic.

  • 1.a Application is in foreground:
  • The notification data is received in the JavaScript callback without notification bar message (this is the normal behaviour of mobile push notifications).
  • 1.b Application is in background or closed:
  • The device displays the notification message in the device notification bar.
  • If the user taps the notification, the application comes to foreground and the notification data is received in the JavaScript callback.
  • If the user does not tap the notification but opens the applicacion, nothing happens until the notification is tapped.

License

The MIT License

Copyright (c) 2017 Felipe Echanique Torres (felipe.echanique in the gmail.com)

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.

cordova-plugin-fcm's People

Contributors

aparedes avatar bryant1410 avatar fechanique avatar fechaniqueleadclic avatar jach145 avatar jorchg avatar lp1bp avatar nikmartin avatar vlavrynovych avatar wilsonpinto avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

cordova-plugin-fcm's Issues

Ios push

android push Ok

ios how to push Notification ?

The message comes
How notifications are alert?(background)

Receive callback with data ?

What Is the correct way to get the data/message from the notification to the app via a callback?

There is 2 different scenarios:

  • Background/ App off
    Show Notification in toolbar
    When notification is clicked, receive callback with data (not working, android 6.0 cordova 6.2).
  • Foreground (working):
    Receive callback with data.

onNotification listener is never trigger when first scenario occurs.

How do I set the plugin in Phonegap ?

How do I set the plugin in Phonegap ?

Hello , I installed the cord -plugin- fcm plugin in my app project.

I added the project root google - services.json file as well.

But I did not understand the configuration steps in Usage .

Someone would have a tutorial on how to set up , which has to be added in config.xml and index.js ?

Solving the GoogleService-Info.plist inclusion

Just a question: Is there a way to include the GoogleService-Info.plist via a hook? Because I don't want to checkin the complete iOS project into my repository and I'm using CI. The following hook is already working fine for the Android part:

/*
This hook expects the files 'fcmconfig/google-services.json' 'fcmconfig/GoogleService-Info.plist'
in the cordova root directory and copies them in the ios or android project.
*/

module.exports = function(ctx) {
    var fs = require('fs');

    // checks for existing file and folder
    var checkForFile = function(folder, file) {
        var result = false;
        try {
            var stats = fs.lstatSync(folder + '/' + file);
            if (stats.isFile()) {
                result = true;
            }
        } catch (e) {
            result = false;
        }
        return result;
    }

    // if android platform is part of build
    if (ctx.opts.platforms.indexOf('android') >= 0) {
        if (checkForFile('fcmconfig', 'google-services.json')) {
            fs.createReadStream('fcmconfig/google-services.json')
                .pipe(fs.createWriteStream('platforms/android/google-services.json'));
            console.log('Installing FCM configuration for android');
        } else {
            console.error('ERROR: Could not install FCM configuration for android, fcmconfig/google-services.json missing.');
        }
    }

    // if ios platform is part of build (need also to be added to xcode project!)
    if (ctx.opts.platforms.indexOf('ios') >= 0) {
        if (checkForFile('fcmconfig', 'GoogleService-Info.plist')) {
            fs.createReadStream('fcmconfig/GoogleService-Info.plist')
                .pipe(fs.createWriteStream('platforms/ios/GoogleService-Info.plist'));
            console.log('Installing FCM configuration for ios');
        } else {
            console.error('ERROR: Could not install FCM configuration for android, fcmconfig/GoogleService-Info.plist missing.');
        }
    }
}

But the GoogleService-Info.plist file need to be added to the Xcode project file. Any ideas?

erro execute in ios

i'm having a problem for emulate in ios

libc++abi.dylib: terminating with uncaught exception of type NSException

Plugin Conflict?

When I have both cordova-plugin-fcm and cordova-plugin-request-location-accuracy plugins installed my build fails. Here is the output:

Found com.google.android.gms:play-services-location:+, but version 9.2.0 is needed for the google-services plugin.
:processDebugGoogleServices FAILED

FAILURE: Build failed with an exception.

When I have one or the other installed the build is successful.

Build Fail

Build fails after I have added the plugin. I am using google-services 9.2.0 Build fails asking to update google-services but succesfully builds if I remove the plugin
noticed plugin uses 9.0.0 and gradle 1.1.0. Need guidance how to setup the plugin in my project
I cannot downgrade google-services since firebase require to use latest sdks

Badge not disappearing

If i post "badge":1 I get a badge on my app. If I open the app, the badge is not removed. Is it possible to get rid of the badge if the user opens the app?

Pinned version of firebase plugin causing build problems

The plugin currently forces version 9.0.0 exactly of firebase which in turn causes all other plugins that use a more general version of google play services to fail. See:

dpa99c/cordova-plugin-request-location-accuracy#8
https://github.com/intercom/intercom-cordova/issues/58

Could the firebase version be 9+ or something equivalent to prevent this?

The error is:

:processDebugGoogleServices
Found com.google.android.gms:play-services-gcm:8.+, but version 9.0.0 is needed for the google-services plugin.
:processDebugGoogleServices FAILED

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':processDebugGoogleServices'.
> Please fix the version conflict either by updating the version of the google-services plugin (information about the latest version is available at https://bintray.com/android/android-tools/com.google.gms.google-services/) or updating the version of com.google.android.gms to 9.0.0.

Notification not triggered for background/foreground app (but working if killed)

Similar to other (resolved) issues, yet different:
Foreground: notification not received, callback not called (I understand it's normal not to get a notification, but the callback shall be called)
Background: notification received, but callback not called when notification clicked
app not started/killed: notification received and ... callback called when notification clicked (that's strange that this use case works perfectly when the 2 others fail...)

I've the same code than in the Readme, where I subscribe to the "topicExample". I send a notification, exactly like in the Readme too, including "click_action":"FCM_PLUGIN_ACTIVITY".

More interestingly, I can see the payload in the Android Studio console (both foreground/background):

Sent PUSH to view: javascript:FCMPlugin.onNotificationReceived({"from":"\/topics\/topicExample","collapse_key":"com.xxx.fastrack","param1":"value1","param2":"value2","wasTapped":true})

but the next line shows this hint: D/JsMessageQueue: Dropping Native->JS message due to disabled bridge. This one feels suspect, but what could be the issue?

NB: I'm calling FCMPlugin when the deviceready event is fired - my phone is a Samsung S4, Android 5.0.1

onNotification callback not fired when comming from device tray.

FCMPlugin.onNotification(
function (data) {
log(JSON.stringify(data));
},
function success(data) {
log('success:' + JSON.stringify(data));
},
function error(data) {
log('error:' + JSON.stringify(data));
}
);
The first callback function is not called when comming from device tray

IOS not receiving a token from getToken

Android getToken is working fine, but I had to bump the versions in FCMPlugin.gradle from 9.0.0 to 9.0.2.

dependencies { compile 'com.google.firebase:firebase-core:9.0.2' compile 'com.google.firebase:firebase-messaging:9.0.2' }

For some reason, IOS is not receiving a token at all. I have imported the GoogleService-info.plist through Xcode and I get the notification permission display when I install the app. Anybody else experiencing this?

Trouble getting event if app in background or off

The code I have to receive the event works great:

window.FCMPlugin.onNotification(function(data) { alert(JSON.stringify(data)); }, function() { console.log("fcm success") }, function() { console.log("fcm error")})

if and only if the app is open. If the app is closed or in background, I get the notification in the status bar, clicking it opens the app, but then onNotification callback never happens for that event. Is there some step I'm missing?

Build failure

Hi

I currently get a build failure when I try to build the project.

* What went wrong:

A problem occurred configuring root project 'android'.


Could not find method registerResGeneratingTask() for arguments [task ':processDebugGoogleServices', 
/Users/n/Downloads/ionic2-firebase-master/platforms/android/build/generated/res/google-services/debug] on
 com.android.build.gradle.internal.api.ApplicationVariantImpl_Decorated@5921904c.

I rechecked everything and can not figure out why I cannot build. Any feedback would be appreciated. It happens as soons as I add the plugin, before that I can build and run normally. thanks in advance :)

Unable to connect to FCM. Error Domain=com.google.fcm Code=2001 "(null)"

After successfully using your plugin to set up cloud messaging notifications on android, I attempted to run the same project on ios. Since we use our server as a middleman between the app and firebase, I was able to send messages from IOS. However, I was not able to get the device to receive any notifications.

When launching the app I get this stream in the logs:

016-07-19 14:40:06.862 BubbleStudent[406:49197] Apache Cordova native platform version 4.1.1 is starting.
2016-07-19 14:40:06.864 BubbleStudent[406:49197] Multi-tasking -> Device: YES, App: YES
2016-07-19 14:40:06.990 BubbleStudent[406:49197] Using UIWebView
2016-07-19 14:40:06.992 BubbleStudent[406:49197] [CDVTimer][handleopenurl] 0.111997ms
2016-07-19 14:40:06.995 BubbleStudent[406:49197] [CDVTimer][intentandnavigationfilter] 2.980947ms
2016-07-19 14:40:06.996 BubbleStudent[406:49197] [CDVTimer][gesturehandler] 0.092983ms
2016-07-19 14:40:06.996 BubbleStudent[406:49197] Starting Facebook Connect plugin
2016-07-19 14:40:06.996 BubbleStudent[406:49197] [CDVTimer][facebookconnectplugin] 0.198007ms
2016-07-19 14:40:06.998 BubbleStudent[406:49197] [CDVTimer][keyboard] 2.220988ms
2016-07-19 14:40:06.998 BubbleStudent[406:49197] [CDVTimer][TotalPluginStartup] 6.520033ms
2016-07-19 14:40:07.012 BubbleStudent[406:49197] DidFinishLaunchingWithOptions
2016-07-19 14:40:07.020 BubbleStudent[406:49197] Configuring the default app.
2016-07-19 14:40:07.120 BubbleStudent[406:] <FIRAnalytics/INFO> Firebase Analytics v.3200000 started
2016-07-19 14:40:07.121 BubbleStudent[406:] <FIRAnalytics/INFO> To enable debug logging set the following application argument: -FIRAnalyticsDebugEnabled (see http://goo.gl/Y0Yjwu)
2016-07-19 14:40:07.135: <FIRInstanceID/WARNING> FIRInstanceID AppDelegate proxy enabled, will swizzle app delegate remote notification handlers. To disable add "FirebaseAppDelegateProxyEnabled" to your Info.plist and set it to NO
2016-07-19 14:40:07.136: <FIRInstanceID/WARNING> Failed to fetch APNS token Error Domain=com.firebase.iid Code=1001 "(null)"
2016-07-19 14:40:07.139 BubbleStudent[406:] <FIRAnalytics/INFO> Successfully created Firebase Analytics App Delegate Proxy automatically. To disable the proxy, set the flag FirebaseAppDelegateProxyEnabled to NO in the Info.plist
2016-07-19 14:40:07.145: <FIRMessaging/INFO> FIRMessaging library version 1.1.0
2016-07-19 14:40:07.162: <FIRMessaging/WARNING> FIRMessaging AppDelegate proxy enabled, will swizzle app delegate remote notification receiver handlers. Add "FirebaseAppDelegateProxyEnabled" to your Info.plist and set it to NO
2016-07-19 14:40:07.186 BubbleStudent[406:49197] app become active
2016-07-19 14:40:08.838 BubbleStudent[406:] <FIRAnalytics/INFO> Firebase Analytics enabled
2016-07-19 14:40:08.911: <FIRInstanceID/WARNING> APNS Environment in profile: (null)
2016-07-19 14:40:08.912: <FIRInstanceID/WARNING> No aps-environment set. If testing on a device APNS is not correctly configured. Please recheck your provisioning profiles. If testing on a simulator this is fine since APNS doesn't work on the simulator.
2016-07-19 14:40:09.153 BubbleStudent[406:49197] Resetting plugins due to page load.
2016-07-19 14:40:09.294 BubbleStudent[406:49197] Connected to FCM.
2016-07-19 14:40:09.431 BubbleStudent[406:49197] InstanceID token: (null)
2016-07-19 14:40:09.431 BubbleStudent[406:49197] Unable to connect to FCM. Error Domain=com.google.fcm Code=2001 "(null)"
2016-07-19 14:40:10.376 BubbleStudent[406:49197] ERROR Internal navigation rejected - not set for url='about:blank'
2016-07-19 14:40:10.378 BubbleStudent[406:49197] ERROR Internal navigation rejected - not set for url='about:blank'
2016-07-19 14:40:10.641 BubbleStudent[406:49197] ERROR Internal navigation rejected - not set for url=
2016-07-19 14:40:10.672 BubbleStudent[406:49197] Cordova view ready
2016-07-19 14:40:11.021 BubbleStudent[406:49197] Finished load of: file:///var/containers/Bundle/Application/
2016-07-19 14:40:15.465 BubbleStudent[406:49197] InstanceID token:
2016-07-19 14:40:15.466 BubbleStudent[406:49197] Unable to connect to FCM. Error Domain=com.google.fcm Code=2001 "(null)"
2016-07-19 14:40:37.404 BubbleStudent[406:49197] Starting login
2016-07-19 14:40:37.488 BubbleStudent[406:49197] THREAD WARNING: ['FacebookConnectPlugin'] took '84.738770' ms. Plugin should use a background thread.
2016-07-19 14:40:41.645 BubbleStudent[406:49197] FB handle url:
2016-07-19 14:40:41.808 BubbleStudent[406:49197] app become active
2016-07-19 14:40:41.808 BubbleStudent[406:49197] Set state foreground
2016-07-19 14:40:41.808 BubbleStudent[406:49197] Unable to connect to FCM. Error Domain=com.google.fcm Code=2001 "(null)"
2016-07-19 14:40:42.737 BubbleStudent[406:49197] view registered for notifications
2016-07-19 14:40:42.738 BubbleStudent[406:49197] Graph Path = me/?fields=name,age_range,gender,email,education
2016-07-19 14:40:42.847 BubbleStudent[406:49197] Finished GraphAPI request

2016-07-19 14:40:42.952 BubbleStudent[406:49197] Finished GraphAPI request
2016-07-19 14:40:42.969 BubbleStudent[406:49197] Graph Path = me/friends?fields=name,email,picture.type(large)&redirect=0
2016-07-19 14:40:43.076 BubbleStudent[406:49197] get Token
2016-07-19 14:40:43.106 BubbleStudent[406:49197] Finished GraphAPI request
2016-07-19 14:40:50.012 BubbleStudent[406:49197] view registered for notifications
2016-07-19 14:42:25.724 BubbleStudent[406:49197] app entered background
2016-07-19 14:42:25.726 BubbleStudent[406:49197] Set state background
2016-07-19 14:42:25.726 BubbleStudent[406:49197] Disconnected from FCM

I've followed a few tips and ensured that in my Info.plist I have set the Required background modes and the FirebaseAppDelegateProxy.

Here is my ionic info:

Cordova CLI: 6.2.0
Gulp version: CLI version 3.9.1
Gulp local: Local version 3.9.1
Ionic Framework Version: 1.3.1
Ionic CLI Version: 1.7.16
Ionic App Lib Version: 0.7.3
ios-deploy version: 1.8.6
ios-sim version: 5.0.8
OS: Mac OS X El Capitan
Node Version: v5.3.0
Xcode version: Xcode 7.3 Build version 7D175

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

Android notifications received successfully,
in IOS I get an error while trying to Build app in 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 build is successful and notifications are received in iOS

data.wasTapped retrun string

I think is better to return a bool for data.wasTapped instead of a string.
we can't check like this if (data.wasTapped) or if (!data.wasTapped).

btw thank you for the quick release :)

Get device token

hello,
There are no way to access on firebase token in javascript ?
I have to do implement a method like sendRegistrationToServer(refreshedToken); ?

Add the possibility to show notifications when app in foreground

I know the default behavior of firebase is not to show the notification when the app is in foreground, but it is like this because firebase is thought to be used in chat/realtime apps and this behavior is a pain in the ass to some other apps.
Just adding the possibility by configuration (saving it in the preferences) would be good enough, it does not need to be the default behavior.

Thanks and sorry for the outburst.

Phonegap Build

Is it possible to add the plugin trought Phonegap Build ?

How to control the Status Bar Notification?

I'm wondering how one can get control on the notification that appears on the Status Bar when the push arrives while the application is not on the foreground.

I would like to selectively display a status bar notification or modify an existing one, but I can't see where this is handled. At least on Android.

I see here that the actual call to sendNotification is commented out and upon debugging on Android, that function doesn't seem called at all.

Where is the status bar notification for the push built?

FCMPlugin.onNotification not fire in iOS

the code block inside this function doesnt trigger for iOS, where as it works fine in Android
the push notification is received but the data payload cant be read.

App Crashing on start

Whenever i launch the app in a device, it crashes. I followed the instructions, but cant seem to work. Hope you can help me with this.

Phonegap Build Error

"Oh geez. Your build failed. Sorry, but a problem occurred on the build server"

  • phonegap-version 6.1.0
  • config.xml

I suppose is a problem with google play services, but how can I do this with PGB? ->
"You will need to ensure that you have installed the following items through the Android SDK Manager:

Android Support Library version 23 or greater
Android Support Repository version 20 or greater
Google Play Services version 27 or greater
Google Repository version 22 or greater"

Cordova / Sencha Topic Subscriptions Error

I'm building a Sencha app with Cordova and have installed this plugin for notifications without an issue. I can receive all / ios notifications as expected however none of the custom functions are working for me specifically:

FCMPlugin.subscribeToTopic('topicExample');

I've verified the FCMPlugin is available and working however it isn't actually subscribing to the topic. Furthermore, FCMPlugins.onNotification() isn't firing when a 'all' event comes in either.

My Google plist is in place, and everything seems to be loading fine so I'm not sure what the deal is.

This is xcode's console output:

2016-07-15 14:08:10.236 OntrayPOS[2129:1713506] Configuring the default app.

2016-07-15 14:08:10.310: <FIRInstanceID/WARNING> FIRInstanceID AppDelegate proxy enabled, will swizzle app delegate remote notification handlers. To disable add "FirebaseAppDelegateProxyEnabled" to your Info.plist and set it to NO

2016-07-15 14:08:10.310: <FIRInstanceID/WARNING> Failed to fetch APNS token Error Domain=com.firebase.iid Code=1001 "(null)"

2016-07-15 14:08:10.317: <FIRMessaging/INFO> FIRMessaging library version 1.1.0

2016-07-15 14:08:10.333: <FIRMessaging/WARNING> FIRMessaging AppDelegate proxy enabled, will swizzle app delegate remote notification receiver handlers. Add "FirebaseAppDelegateProxyEnabled" to your Info.plist and set it to NO

2016-07-15 14:08:10.353 OntrayPOS[2129:1713506] app become active

2016-07-15 14:08:10.502 OntrayPOS[2129:] <FIRAnalytics/INFO> Firebase Analytics v.3200000 started

2016-07-15 14:08:10.504 OntrayPOS[2129:] <FIRAnalytics/INFO> To enable debug logging set the following application argument: -FIRAnalyticsDebugEnabled (see http://goo.gl/Y0Yjwu)

2016-07-15 14:08:11.174: <FIRInstanceID/WARNING> APNS Environment in profile: development

2016-07-15 14:08:11.290 OntrayPOS[2129:] <FIRAnalytics/INFO> Successfully created Firebase Analytics App Delegate Proxy automatically. To disable the proxy, set the flag FirebaseAppDelegateProxyEnabled to NO in the Info.plist

2016-07-15 14:08:11.306 OntrayPOS[2129:1713506] Resetting plugins due to page load.

2016-07-15 14:08:11.487 OntrayPOS[2129:1713506] Connected to FCM.

2016-07-15 14:08:11.786 OntrayPOS[2129:1713506] Finished load of: file:///var/mobile/Containers/Bundle/Application/9B065E68-1469-4B9F-88BA-1E4D4D4277BA/OntrayPOS.app/www/index.html

2016-07-15 14:08:11.968 OntrayPOS[2129:] <FIRAnalytics/INFO> Firebase Analytics enabled

How to retrieve the device token?

I'm new to web development.
Can anyone let me know, how & where do I need to use following code?

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

Distinguish between notification tray and foreground app

A common use case of FCM is to notify the user that a new email, ticket, etc. needs their attention. If they are outside of the app, tapping on the notification should take them directly to the item. But if they are in the app, it would be rather jarring to dump them directly from what they are doing to the new email, and would be better to show them a toast that they could click on if they want to go.

To do this, I need to know whether the message was received while the app was in the foreground, or if it was triggered from tapping the notification in the notification tray. Do you happen to know if there a way to get this information out of FCM?

Background Notification not working

Hii,

Step 1: Are you in the right place?

yes

Step 2: Describe your environment

Android device: Xiaomi MI5
Android OS version: 6.0
Google Play Services version: 9.2.56
Firebase/Play Services SDK version: 9.2.1
Step 3: Describe the problem:

Can't get push notification in background / when app is closed (swiped from recents apps)

Steps to reproduce:

followed these steps
and from POSTMAN
header
Authorization:key=xxxxxxxxxxxxx
Content-Type:application/json
below is payload
{
"notification":{
"title":"Notification title",
"body":"Notification body",
"sound":"default"
},
"to":"d5nwyla-QAY:APA91bEUlVdu8kahO2L7GZc0sdGnjAieBMY6zFSY2r-B-cvTveLpW0_lCNHSQ7R4q3DKzY1VOwVDhpDuOTPGW400SrYGxn3jTlPZU3sVi6zAd7wBYgyqIydVsKuOVWrtVe-CpEC7Sqvt",
"priority":"high",
"data":{
"param1":"value1",
"param2":"value2"
}
}

Observed Results:

getting notification in-app also when app is minimise (pressing home)

getting below warning from logcat
07-16 23:40:55.161 2941 2941 W GCM-DMM : broadcast intent callback: result=CANCELLED forIntent { act=com.google.android.c2dm.intent.RECEIVE flg=0x10000000 pkg=com.infogain.bioclinica (has extras) }

Expected Results:

Should get notification in background

(Android) Notification Sound Playing, No Notification

Steps

  1. Setup FCM in my Cordova/Android app, including moving the google_services.json file into the android build root
  2. Launch the app on device using cordova run android --device && adb logcat | egrep GCM|FCM
D/FCMPlugin(26358): ==> FCMPlugin execute: ready
D/GCM     ( 1150): GcmService start Intent { act=com.google.android.gms.gcm.PACKAGE_REPLACED cmp=com.google.android.gms/.gcm.GcmService (has extras) } com.google.android.gms.gcm.PACKAGE_REPLACED
D/FCMPlugin(26358): ==> FCMPlugin execute: registerNotification
D/FCMPlugin(26358): ==> FCMPlugin execute: getToken
D/FCMPlugin(26358):     Token: dxJpRst7q1A:APA91bE0IqohQFwh5n5e5jSpdsItiybHeaYJrNwbINvoOcYLJPZhpMAIXzr3FMOSgZ1RxKyAXc1dONSB0o4hGT6aTJbhWnN29C4z44JH05k1ubOfv7XxG1ZrAm8Y731euxaZQIV8-78C
D/FCMPlugin(26358): ==> FCMPlugin execute: subscribeToTopic
  1. Send a request via Postman
{
  "notification":{
    "title":"Super Notification",
    "body":"Notification is delivered!",
    "sound":"default",
    "click_action":"FCM_PLUGIN_ACTIVITY",
    "icon": "icon",
    "badge": "1"
  },
  "data":{
    "someData":"Great"
  },
  "to":"/topics/serverUp",
  "priority":"high"
}

Results:

  1. When in the foreground, the application behaves as expected.
  2. When in the background or stopped, the phone will make a sound, however no notifications appear. The following logs do appear:
D/PowerManagerService(  674): acquireWakeLockInternal: lock=1116552048, flags=0x1, tag="GCM_CONN", ws=WorkSource{10008 com.google.android.gms}, uid=10008, pid=1150
D/PowerManagerNotifier(  674): onWakeLockAcquired: flags=1, tag="GCM_CONN", packageName=com.google.android.gms, ownerUid=10008, ownerPid=1150, workSource=WorkSource{10008 com.google.android.gms}
I/GCM     ( 1150): GCM message com.pgmonitor.app 0:1468863544393079%a817cb89a817cb89
D/PowerManagerService(  674): releaseWakeLockInternal: lock=1116552048 [GCM_CONN], flags=0x0, total_time=125ms
D/PowerManagerNotifier(  674): onWakeLockReleased: flags=1, tag="GCM_CONN", packageName=com.google.android.gms, ownerUid=10008, ownerPid=1150, workSource=WorkSource{10008 com.google.android.gms}

Am I missing something?

Could not find method for RegisterResGeneratingTask()

A problem occurred configuring root project 'android'.

Could not find method registerResGeneratingTask() for arguments [task ':processDebugGoogleServices', C:\Users\Jonathan\Desktop\taxiApp\platforms\android\build\generated\res\google-services\debug] on com.android.build.gradle.internal.api.ApplicationVariantImpl_Decorated@6c5740e4.

Build failed

fcm plugin build failed both ios and android it shows,
> Could not find com.google.firebase:firebase-core:9.0.0.

Unable to build FCM plugin (it used to work 1 day ago)

capture

When I add the plugin, it gets added but throws an error in build.

These URLs are required as a dependency but they do not exist (404):

https://repo1.maven.org/maven2/com/google/firebase/firebase-messaging/9.2.0/firebase-messaging-9.2.0.pom
https://repo1.maven.org/maven2/com/google/firebase/firebase-messaging/9.2.0/firebase-messaging-9.2.0.jar
https://jcenter.bintray.com/com/google/firebase/firebase-messaging/9.2.0/firebase-messaging-9.2.0.pom
https://jcenter.bintray.com/com/google/firebase/firebase-messaging/9.2.0/firebase-messaging-9.2.0.jar

Please help me out on how to fix this. It was working well before 1 day but now when I did fresh install, the dependency problem arises.

Token is null

Hi guys

I work on an Ionic 2 hybrid app with cordova-plugin-fcm and Firebase. But the returned token is always null. I rechecked everything (google-services.json is added too).

Does have anyone an idea what could be wrong?

thanks in advance

IOS doesn't show notifications when in background or killed.

I have made a working chat that allows users to talk between android and ios. On android when the app is in the background or has been killed, the user receives a notification to alert them that a message has been sent. In ios no such notification seems to appear.

This is the format that I send messages in:

{ "notification": { "title": "Titlte", "body": "body", "tag": "tag", "click_action": "FCM_PLUGIN_ACTIVITY", "icon": "fcm_push_icon", "sound":"default", "badge": "2", }, "data": { "groupID": 77, "message": "message", "code": 0, "sender": "sender", "time": "2016-07-11 15:23", "signature": "" }, "to": "/topics/77", "content_available": true, "priority": "high" }

Are you able to shed any light on this?

Only show background notifications based on content of message?

I have the need to allow users to enable and disable background messages based on content of an fcm notification. The payload of the notifications has data that a user can choose to ignore notifications on. Is it possible to do this, or will I have to implement this using topics or some other method?

how to subscribe or get token

I have created a cordova project & installed the cordov-plugin-fcm with some other plugins (like network plugin).

I am new to web development.

Please let me know how/where to use the below code to get token/subscribe:

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

)

FCMPlugin.subscribeToTopic('topicExample');

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.