iOS Firebase Cloud Messaging Conflicting With Android - android

I am writing a iOS and Android application that is supposed to notify users through the FCM API yet there seems to be a catch-22 within the firebase API that involves both platforms:
On Android, to handle new notifications using a custom implementation of FirebaseMessagingService.onMessageReceived(), one must create a DATA only message server-side. E.g: { "data": {"param": "foo" },"to" : "/topics/bar"}. The moment a "notification" field is included in the json, the custom implementation will not be called when the app is in the background. This would be ok but...
On iOS, if the "notification" field is not included in the message, the message just isn't received when the app is in the background which is unacceptable.
Thus, to receive background notification on iOS, you need to add the "notification" field, but adding this field makes the Android apps display bogus, non-customizable notifications when in the background!
I hope there is something that I am missing in the documentation. I would like to know how others have overcome this problem and whether it would be wise to stick with FCM for iOS or ditch it for something else.

Related

Send push Notification in Ionic

I am working on an ionic application and need to implement push notifications using the back end API's developed in .NET.
While going through few blogs I found fire base API's and was able to complete a POC using Firebase. However the notification did not show when the app was in foreground.
I am not sure how to consume .NET API's to get the push messages. Can we achieve this without using Firebase. Please suggest. Thanks !
It is normal so that notification not show on forground using firebase notifications.
this.firebase.onNotificationOpen().subscribe( (msg) => {
if (this.platform.is('ios')) {
this.presentToast(msg.aps.alert);
//here notfication in ios
} else {
this.presentToast(msg.body);
//here notfication in android
}
});
This will trigger a toast of notification in foreground. If you want it as notfication, use local notfication and set the msg.body details as it should be shown inside the local notfication.
And as an advice, use onesignal notfication since it contains better features plus easier and more flexible.

Firebase data message to specific android app versions

i have an android app and i want to send a firebase data message to inform the users of a new app version available in the play store. I am sending a data message in order to reach devices in which the app is in background.
I want send the message to specific versions, or if it's possible to all versions except the last version.
What is the best way to do it? Can I specify a version number in a fcm data message?
Below is the data message i am sending.
Thanks in advance.
{
"to": "/topics/all",
"data": {
"title": "new version",
"body": "a new version is available in play store"
}
}
I don't have answer for your question but I can suggest another way to achieve your case.
Take a look at Firebase Remote Config.
You can define variable for your client to get anytime it start.
So for your case, we have 3 variable:
destinationVersion for your specific version
title
message
In the app, just put the logic like if app's version equal to destinationVersion , create a notification with title and message to tell user update the app
. Hope it helpful to you.
You can force users to update with Google now: https://developer.android.com/guide/playcore/in-app-updates#immediate

Push notification from Mixpanel dashboard to Android Cordova app

I am successfully sending Push Notifications from the Mixpanel Dashboard to a Cordova app on both iOS and Android devices, using phonegap-plugin-push.
However, the title and body values entered in the default fields only appear on iOS devices.
For the notification to appear on Android devices, I currently need to include a custom payload in Mixpanels "Custom Data":
{
"title":"Title for Android only",
"body":"Content for Android only"
}
This is an error prone step for any non-technical using Mixpanel to send notifications.
Does someone know an easier way to do this?
The short answer here is that Cordova/Phonegap and similar third party frameworks are not 100% optimized for Mixpanel functionality (although they work pretty great), and as such you'll need to generate separate push notifications for both iOS and Android in your Mixpanel project.
Providing context, all iOS pushes regardless of app deliver a JSON payload to APN using the same keys to deliver their messages (alert, badge, sound). However, the keys that Android apps process for incoming GCM pushes are entirely dependent on how the GCM receiver is established, and therein lies the problem here.
Mixpanel's Android SDK initializes pushes and uses a GCM receiver that is specific to Mixpanel messages, and fully expects its custom keys (mp_message, mp_title) in order to render the notification. The webapp reformats the message input to meet these key requirements (http://bit.ly/1OGgU1y)
However, the Phonegap GCM receiver expects different keys as you've noticed. I'd recommend referring to the phonegap github page in order to get more context into the expected push format and behavior (looks like they expect "title" and "message" as the keys): http://bit.ly/1KDScye
Unfortunately, what this means is that the Android app is not optimized to receive the default, web-app generated Mixpanel pushes, although your iOS one is. Mixpanel's SDKs are intended to maximize capabilities for that platform, and it isn't guaranteed that Cordova or similar JS frameworks will translate 100%.
So to conclude - Creating a message in the Mixpanel push editor will send to iOS, but for Android you'll need to use the custom JSON payload in a separate notification, including keys that the phonegap GCM receiver is compatible with.
If its help to anyone this is how I solved the problem
in phonegap-plugin-push
you need to modify two files
GCMIntentService.java
private String normalizeKey(String key) {
if (key.equals(BODY) || key.equals(ALERT) || key.equals(MP_MESSAGE) || key.equals(GCM_NOTIFICATION_BODY)) { // added MP_MESSAGE
PushConstants.java
public static final String MP_MESSAGE = "mp_message";

Rich push in Urbanairship in android

I am implementing Push Notification for Android in my project. I am implementing urbanairship GCM push Notification.While i gone through the urbanairship site, i camr to notice that under the messages tab, there is an option for "TEST RICH PUSH". I have already done tested simple push by sending push messages from "TEST PUSH" under the tab messsages. Now my question is in "TEST RICH PUSH", there are two new fields "USER" and "ALIAS". Is Rich push is used for sending push notification only to a particualar user currently using an App. or it has got any other purpose. Also please let me know how to enable "RICH PUSH" in their new website.(Earlier it is staright forward. Now i looked in their whole website, But i couldn't find a clue). Any help in this is highly appreciated.`
Thanks InAdvance
Rich Push is automatically apart of the Urban Airship library (at least since 3.0.0 version, probably before then as well but I'm not sure which version number). There are just a few things in code you have to do to get it up and started.
In your airshipconfig.properties file add the line "richPushEnabled = true" (without quotes).
In your manifest file add a service with the name "com.urbanairship.richpush.RichPushUpdateService" along with the PushService/PushWorkerService, etc.
And you should be good to go! If not let me know I may have forgotten something.
To send a push you have to use the curl command found here (Under Rich Push -> Rich Push broadcast): https://support.urbanairship.com/customer/portal/articles/1069013-helpful-curl-examples under audience instead of doing "all", spit out this value to the logs somewhere once UA is initialized: RichPushManager.shared().getRichPushUser().getId() (import com.urbanairship.richpush.*;) and make sure the MasterSecret parameter is NOT your api secret but the master secret found in your API keys on your UA developer dashboard.
I wrote everything out because Urban Airship's documentation DNE for android Rich Pushes, it's absolutely horrible. They have a sample project but that's it.

Push Messages for PhoneGap

I created an app for iPhone and Android using Phonegap.
Now I wanted to add push functionality which already works pretty good.
When a push message arrives on my iPhone I get a message on the homescreen. If I swipe it, iOS will open my application. - So far so good.
Now, within my PhoneGap app I need to check what that message actually says in order to open the correct view within my app via JavaScript.
I know there are quite some posts about this but I couldn't find some clear answers to these questions:
Does PhoneGap support push messages?
If yes, where is the documentation for that?
If not, which plugins/frameworks can be recommended? So far I found pushwoosh and Urbanair. Are they any good?
Regarding Pushwoosh, I noticed that I need some kind of pushwoosh ID - Why that?
By Pushwoosh ID you most probably mean Pushwoosh App Id or Application Code. It's an ID of your application in Pushwoosh Control Panel (current format is XXXXX-XXXXX). You will see it as soon as you add a new app in Pushwoosh.
There was quite an extensive blog post made by Holly Schinsky on easy PhoneGap integration with Pushwoosh
http://devgirl.org/2012/12/04/easy-phonegap-push-notifications-with-pushwoosh/
It should be very helpful for all PhoneGap developers aiming to integrate push notifications into their apps.
I found a really easy solution without using a framework.
I simply added the following code to the very end of the method didFinishLaunchingWithOptions (Right before the return statement):
if (launchOptions != nil)
{
NSDictionary* dictionary = [launchOptions objectForKey:UIApplicationLaunchOptionsRemoteNotificationKey];
if (dictionary != nil)
{
NSLog(#"Launched from push notification: %#", dictionary);
[self addMessageFromRemoteNotification:dictionary updateUI:NO];
}
}
Also, I added this new method to my AppDelegate.m which gets the payload from the push message:
- (void)application:(UIApplication*)application didReceiveRemoteNotification:(NSDictionary*)userInfo
{
NSLog(#"Received notification: %#", userInfo);
[self addMessageFromRemoteNotification:userInfo updateUI:YES];
}
(The NSLog calls above will show you what's inside the push message)
As a last step, I added this listener to do what ever I want with the payload:
- (void)addMessageFromRemoteNotification:(NSDictionary*)userInfo updateUI:(BOOL)updateUI
{
// do what ever you want with userInfo
}
If you want to do an additional JavaScript call with this info, I recommend using:
[self.viewController.webView stringByEvaluatingJavaScriptFromString:#"callSomeJSFunction()"];
Of course you can also pass arguments as strings into that JS function if you want.

Categories

Resources