Ionic2 Push notification with background processing - ionic-framework

I am using ionic.io to send push to my app. I have following body
{"tokens":["DeviceToken"],
"profile":"Profile",
"notification":{ "payload": {
"type": "loadCategories"
},
"ios": {
"content_available": 1
},
"android": {
"content_available": "1"
}}}
Type script code.
var push = Push.init({
android: {
senderID: "ID"
},
ios: {
alert: "true",
badge: true,
sound: 'false'
},
windows: {}
});
if((<any>push).error) {
console.log((<any>push).error);
return;
};
push.on('registration', (data)=>{
console.log(data.registrationId);
this.pushToken = data.registrationId;
this.updateToken();
});
push.on("notification", (data)=>{
console.log(data);
// if(data.additionalData.payload && data.additionalData.payload.type == 'categoryEvent') {
// console.log("at date")
// }
});
push.on('error', function(e) {
console.log(e.message);
});
Idea is that I need to send push to user and load data from the server. But problem is that if app is in background then notification event is not fired. It works only if app is active. But as soon as i understand from documentation it should work.

Known issue that has been addressed with setting content_available = 1. See https://github.com/phonegap/phonegap-plugin-push/issues/93 for more.

Related

Update Live Activity using remote push notification in SwiftUI

I am trying to update live activities using remote push notifications.
I am creating a live activity like this:
do{
let activity = try Activity<LiveMatchesAttributes>.request(attributes: attributes, contentState: state, pushType: .token)
print("Activity Added Successfully. id: \(activity.id)")
Task {
for await data in activity.pushTokenUpdates {
let myToken = data.map {String(format: "%02x", $0)}.joined()
print("pushToken", myToken)
}
}
}catch{
print(error.localizedDescription)
}
The live activity shows up in the notifications center and the pushToken can also be received.
Now I am trying to update the live activity using remote notifications. The code for that looks like this:
exports.updateLiveActivities = functions.https.onRequest((req, res) => {
const fcmToken = "fcmToken"
const apns = {
headers: {
"apns_push_type" : "liveactivity",
"apns_topic" : "bundle_id.push-type.liveactivity",
},
"payload": {
"aps": {
"timestamp" : Date.now(),
"event": "update",
"content-state": {
"event": "start"
},
"alert": {
"title": "Race Update",
"body": "Tony Stark is now leading the race!"
}
},
}
}
const message = {
token: fcmToken,
apns: apns
}
admin.messaging().send(message).then((response) => {
// Response is a message ID string.
console.log('Successfully sent message:', response);
res.send("ok")
// return res.send("ok");
}).catch((error) => {
console.log(error)
return res.send(error.code);
});
});
Sending the remote notification works because the "alert" is appearing on my phone but the live activity is not getting updated. Any ideas where to insert the received "pushToken" for the live activity?

FCM push notification payload

i have this payload below that send push from firebase function. the payload send notification successful to Android. now i am confused about the iOS.
my Question is that:
will this also send to iOs because i can see that there is no alert in the payload in apsn.
i fellow the documentation in this site which they did not give ios payload.
when i make a research on iOs payload i can see something like this
{
"aps" : {
"alert" : "You got your emails.",
"badge" : 9,
"sound" : "bingbong.aiff"
},
"acme1" : "bar",
"acme2" : 42
}
but in the documentation i cant found where they give alert
exports.chatFunctions = functions.firestore.document("chat/{chatId}/Messages/{messagesId}").onCreate(async (snapshot, context) => {
if (!snapshot.exists) {
console.log('No Device');
}
const chatDatas = snapshot.data();
const messageTo = chatDatas['idTo'];
const deviceTokenuUser1 = await admin.firestore().collection('users').doc(messageTo).get();
const user1name = deviceTokenuUser1.data()['name'];
const user1Url = deviceTokenuUser1.data()['profilePictureUrl'];
let payload = {
notification: {
title: `${user1name}`,
body: `${chatDatas['content']}`,
},
data: {
key: 'chat',
id: `${messageTo}`,
click_action: "FLUTTER_NOTIFICATION_CLICK"
},
android: {
priority: "high",
},
apns: {
payload: {
aps: {
contentAvailable: true,
},
},
headers: {
"apns-push-type": "background",
"apns-priority": "5", // Must be `5` when `contentAvailable` is set to true.
"apns-topic": "io.flutter.plugins.firebase.messaging", // bundle identifier
},
},
token: deviceTokenuUser1.data()['tokens'],
};
try {
await admin.messaging().send(payload);
console.log("Firebase chat Messaging Successfully");
} catch (err) {
console.log("error from chat messaging " + err);
}

how to add channel id to push Notification payload

i am using push notification with local notification.. i have to set channel id in my payload..
here is my payload
i am not sure if this is payload for both andriod and ios. please help me out with correct payload.
thanks
exports.chatFunctions = functions.firestore.document("chat/{chatId}/Messages/{messagesId}").onCreate(async (snapshot, context) => {
if (!snapshot.exists) {
console.log('No Device');
}
const chatDatas = snapshot.data();
const messageTo = chatDatas['idTo'];
const deviceTokenuUser1 = await admin.firestore().collection('users').doc(messageTo).get();
const user1name = deviceTokenuUser1.data()['name'];
const user1Url = deviceTokenuUser1.data()['profilePictureUrl'];
let payload = {
notification: {
title: `${user1name}`,
body: `${chatDatas['content']}`,
},
data: {
key: 'chat',
id: `${messageTo}`,
click_action: "FLUTTER_NOTIFICATION_CLICK"
},
android: {
priority: "high",
},
apns: {
payload: {
aps: {
contentAvailable: true,
},
},
headers: {
"apns-push-type": "background",
"apns-priority": "5", // Must be `5` when `contentAvailable` is set to true.
"apns-topic": "io.flutter.plugins.firebase.messaging", // bundle identifier
},
},
token: deviceTokenuUser1.data()['tokens'],
};
try {
await admin.messaging().send(payload);
console.log("Firebase chat Messaging Successfully");
} catch (err) {
console.log("error from chat messaging " + err);
}
You can add channel id like this:
let payload = {
// ...
android: {
priority: "high",
notification: {
channelId: "yourchannelid"
}
}
// ...
}

Messenger webview working in mobile not on desktop

I am making messenger webview example but it is only working in mobile while form desktop it is redirecting me to a new tab,
Here is the Button payload,
var buttons = [{
type: "web_url",
url: constant.SERVER_URL + "/checkout",
title: "Yes",
webview_height_ratio: "tall",
messenger_extensions: false
}]
Here is request method,
app.get("/checkout", function (req, res) {
let referer = req.get('Referer');
console.log(referer)
if (referer) {
if (referer.indexOf('messenger') >= 0) {
res.setHeader('X-Frame-Options', 'ALLOW-FROM https://www.messenger.com/');
} else if (referer.indexOf('facebook') >= 0) {
res.setHeader('X-Frame-Options', 'ALLOW-FROM https://www.facebook.com/');
}
res.render('checkout')
}
});
var buttons = [{
type: "web_url",
url: constant.SERVER_URL + "/checkout",
title: "Yes",
webview_height_ratio: "tall",
messenger_extensions: True
}]
The Problem was about messenger_extensions i made it true and it worked.

Soundmanager 2 events won't fire/trigger

The soundmanager 2 events won't fire. Here is a snippet where the console.logs don't fire at all, therefore any of the different events aren't being triggered when they should.
soundManager.setup({
url: "js/swf/",
preferFlash: false,
useFlashBlock: false,
onready: function() {
soundManager.play(url, id, {
id: id,
url: url,
onplay: function() {
console.log("test");
},
onresume: function() {
console.log("test");
},
onpause: function() {
console.log("test");
},
onfinish: function() {
console.log("test");
next();
},
whileplaying: function() {
console.log("test");
},
});
},
defaultOptions: {
multiShotEvents: true, // allow events (onfinish()) to fire for each shot, if supported.
}
});
Is this because I have flash disabled? There is a bug currently where flash doesan't work in chrome.
Thanks.
You should use the
var sound = soundManager.createSound({id: 'soundId', url: '1.mp3'});
sound.play({
onplay: function() {
...
}
})
you missed "createSound"