How do I send GCM that when clicked opens URL? - push-notification

I have set up service workers that subscribe to notifications. When Chrome is in the foreground the javascript controls the notification content and its notificationclick event handler will open a web page when the notification is clicked. (code not shown)
But when Chrome is in the background, the "Notification" payload is used for the notification content instead (js not activated), and when I click the notification it just opens Chrome without opening any web page at all.
I can live with having to handle two cases (Chrome was foreground or it wasn't), but clicking on them need to open a web page in both cases.
I'm thinking either my notification is missing some parameter, or I need my js to listen to a service-worker event that is triggered when Chrome opens. But I can't find a list of events that would be relevant.
Code that sends notifications:
import (
gcm "github.com/google/go-gcm"
)
[...]
res, err := gcm.SendHttp(apiKey, gcm.HttpMessage{
// `destination` is the subscription endpoint provided by
// serviceWorkerRegistration.pushManager.subscribe callback.
RegistrationIds: []string{destination},
ContentAvailable: true,
TimeToLive: &ttl,
// This shows up when chrome is not open only. wut?
Notification: &gcm.Notification{
Title: `Title here`,
Body: "Blah blah lorem ipsum",
Sound: "default",
Color: "#ff0000",
//ClickAction: "something here?",
},
})

Related

My notification badge icon is not showing after the PWA is installed to homescreen

I have a mobile website which has the ability to receive push notifications. Some codes on the firebase-messaging-sw.js are as below,
messaging.setBackgroundMessageHandler(function(payload) {
console.log('[firebase-messaging-sw.js] Received background message ', payload);
// Customize notification here
var notificationTitle = payload.data.title;
var notificationOptions = {
body: payload.data.body,
icon: payload.data.icon,
data: payload.data.click_action,
badge: "{icon url}",
image: payload.data.image,
tag: payload.data.unique_id
};
return self.registration.showNotification(notificationTitle,
notificationOptions);
});
When I allow notifications on the mobile Chrome, the notifications are showing perfectly, which my custom made badge logo showing on the notification bar. But after I click on "Add to Homescreen", the notification badge icon becomes the default bell-shaped icon. Why is it like that and is there any ways to change it?
Thank you.
This is a known bug in Chrome. They have already fixed it in this commit.
The bugfix is rolling out with Chrome 69 on the 4th of September (tomorrow). You can check the rollout state here: https://www.chromestatus.com/features/schedule

Open differents pages ionic 3 with push notifications

I need help,
I am trying to open different pages of my application in ionic3, I can do it for a specific page, but I want to differentiate the type of notification, example if the notification is of the message type, my message page is opened and if it is another type of notification will open a different page.
pushObject.on('notification').subscribe((notification: any) => {
this.nav.push(PushNotification); //here open specific page, but I need to open not only a specific page but several pages.
if (notification.additionalData.foreground) {
let youralert = this.alertCtrl.create({
title: 'New Push notification',
message: notification.message,
});
youralert.present();
}
});

react native share dynamic link

1.Everything work fine before share, I shared to Facebook Messenger and click the social content, the redirect link is not the link that firebase generated. The link has become the dynamic domain mixed with the title and description.
2.I tried to copy only the generated firebase link and paste to Facebook Messenger, social content loaded, then by clicking the content it call the dynamic link correctly and launch the app.
const link = new firebase.links.DynamicLink('https://example.com/parameter' , 'abc123.app.goo.gl')
.android.setPackageName('com.example.android')
.ios.setBundleId('com.example.android')
.social.setTitle("Social Title")
.social.setImageUrl("http://exmaple.com/super.png")
.social.setDescriptionText("Description");
firebase.links().createShortDynamicLink(link, 'SHORT')
.then((url) => {
Share.share({
message: "Message Title",
url: url,
title: "Title"
}, {
// Android only:
dialogTitle: 'Super Share'
})
// ...
});
How to share with correct dynamic link not just copy and paste, consider the user behavior.

How to customize styles for browser push notification

I am creating an app using Angular 4, that should receive push notifications from time to time. I have managed to make the notification appear, but I wasn't able to customize its styles and its content.
What I am looking for is a way to change the background color of my notifications so that I can make them blink to call the user's attention.
Here is my code:
public showNotification(title: string, text: string): Notification {
// Check if notifications are supported
const notificationOptions = {
body: `<div style="color:red"><p>${text}</p></div>`,
icon: 'assets/img/logo_onyo-simples.png',
badge: 'assets/img/logo_onyo-simples.png',
vibrate: [200, 100, 200]
};
try {
// Throws an exception if the browser doesn't support a notification.
const notification = new Notification(title, notificationOptions);
notification.onclick = (e: any) => {
window.focus();
notification.close();
};
return notification;
}
catch (e) {
if (e.name === 'TypeError') {
this.raven.captureBreadcrum({
message: 'This browser does not support notifications',
level: 'warning',
category: 'notification'
});
}
else {
this.raven.captureException(e);
throw e;
}
}
}
I've tried to add a test HTML tag to the notification body, but that didn't work. Is there a way to do this?
Note: the reason because I am not using Toastr notifications is because I want the user to receive my notifications even if the browser is minimized or behind another application.
Note 2: here is an example of the type of notification that I am using: https://tests.peter.sh/notification-generator/.
I believe that what you're trying to do is not possible, at least according to the spec. There are no properties nor methods for passing / setting of visual presentation.
I'm speculating here, but it could be because browser vendors want to prevent exactly the type of behavior you're trying to create. Maybe you can style a notification with good taste and design. However, this would also open the door to people creating bad, annoying and straight up predatory notifications. It would open the door to dark patterns.
Although, it's possible that this kind of stylistic flexibility will be added in the future. I just don't think so.

How to launch different screen of apple watch app from different notification?

Problem:
How to launch different screen of apple watch app from different notification?
This is my setup:
I have 2 static WKUserNotificationInterfaceController:
1) awardsCategory
2) otherCategories
This is my PushNotificationPayload.apns file for "awardsCategory" notification:
{
"aps": {
"alert": {
"body": "Hello world!",
"title": "Optional title"
},
"category": "salaryCategory"
},
"WatchKit Simulator Actions": [
{
"title": "Details",
"identifier": "detailsButtonAction"
}
],
"customKey": "Use this file to define a testing payload for your notifications. The aps dictionary specifies the category, alert text and title. The WatchKit Simulator Actions array can provide info for one or more action buttons in addition to the standard Dismiss button. Any other top level keys are custom payload. If you have multiple such JSON files in your project, you'll be able to select them when choosing to debug the notification interface of your Watch App."
}
Once I received a notification, pressing the notification sash or "Details" Button will launch the watch app:
How is it possible for the watch app to determined whether the notification is from awardsCategory or from otherCategories? And From there we can set our initial controller?
When the user taps a button on the notification, the main interface controller is always displayed. handleActionWithIdentifier:forRemoteNotification: is called on your main controller and you can update the UI there. For example, you could hide certain elements, or push a different controller.
(If the user taps on the sash, the identifier will be an empty string.)

Resources