FCM flutter enable notification vibration - firebase

I'm developing a Flutter application for Android and IOS. I have created notification channels for Android according to this article.
My node.js payload:
const payload = {
notification: {
title: "title",
},
android: {
priority: "high",
ttl: 60 * 60 * 1,
notification: {
channel_id: 'YO',
},
},
apns: {
payload: {
aps: {
sound: "sound_03.caf"
}
},
headers: {
"apns-collapse-id": "yo",
"apns-priority": "10"
}
},
priority: 10
}
My notifications are working just fine, for both Android and IOS using. The problem is that vibration is disabled by default.
How to enable notification vibration for Android and IOS for Firebase Cloud Messaging?

You can set the sound property to default so it makes uses the default sound if sound is enabled and it vibrates if the device is on vibrate.
You can update your payload to this:
const payload = {
notification: {
title: "title",
sound: "default"
},
android: {
priority: "high",
ttl: 60 * 60 * 1,
notification: {
channel_id: 'YO',
},
},
apns: {
payload: {
aps: {
sound: "default"
}
},
headers: {
"apns-collapse-id": "yo",
"apns-priority": "10"
}
},
priority: 10
}

For me, I only needed to add it to the notification portion of the message payload.
Below is how it looks in Typescript (but the message JSON is all that matters).
let tokens = ...
let message = {
message: {
notification: {
title: title,
body: body,
sound: 'default', // <----- All I needed
},
data: {
...
},
}
}
firebase.messaging().sendToDevice(tokens, message)

Related

How to update "Going? Yes/No/Maybe" in Google calendar via API?

I am using Google Calendar API to work with events. For example, someone create an event and invites me. So, at the bottom of the event's detail I have 3 options of "Going": YES/NO/MAYBE. My question is how can I answer this by API?
I tried to use an UPDATE request, but it will create a new version of the event in my own calendar instead.
calendar.events.update(
{
calendarId: "primary",
eventId: event.id,
resource: {
start: {
dateTime: event.start.dateTime,
},
end: {
dateTime: event.end.dateTime,
},
attendees: [
{
email: "myemail#gmail.com",
responseStatus: "accepted",
},
],
},
},
(err, response) => {
}
)
For example, how about using patch instead of update as follows?
Modified script:
calendar.events.patch(
{
calendarId: "primary",
eventId: event.id,
resource: {
attendees: [
{
email: "myemail#gmail.com",
responseStatus: "accepted",
},
],
},
},
(err, response) => {
}
)
Reference:
Events: patch

Getting a fetch error using redux toolkit and RTK-Query

I am using RTK-Query, and Redux-toolkit for this app, and I created an api-slice with createApi, as per the docs.
When I run a request to the backend, I get a "FETCH_ERROR"; however, when I run the same request using Axios, I get the data correctly from the backend, which leads me to believe I have an error in my code. I am just not sure where exactly it is.
Here is the error:
Object {
"api": Object {
"config": Object {
"focused": true,
"keepUnusedDataFor": 60,
"middlewareRegistered": true,
"online": true,
"reducerPath": "api",
"refetchOnFocus": false,
"refetchOnMountOrArgChange": false,
"refetchOnReconnect": false,
},
"mutations": Object {},
"provided": Object {},
"queries": Object {
"test(undefined)": Object {
"endpointName": "test",
"error": Object {
"error": "TypeError: Network request failed",
"status": "FETCH_ERROR",
},
"requestId": "BWOuLpOxoDKTzlUYFLW4x",
"startedTimeStamp": 1643667104869,
"status": "rejected",
},
},
"subscriptions": Object {
"test(undefined)": Object {
"QJSCV641RznGWyudGWuMb": Object {
"pollingInterval": 0,
"refetchOnFocus": undefined,
"refetchOnReconnect": undefined,
},
},
},
},
"test": Object {
"data": Array [],
},
}
Here is the test slice:
import { createSlice } from "#reduxjs/toolkit";
const testSlice = createSlice({
name: "test",
initialState: {
data: [],
},
reducers: {
getData: (state) => {
state;
},
},
});
export const { getData } = testSlice.actions;
export default testSlice.reducer;
Here is the apiSlice:
import { createApi, fetchBaseQuery } from "#reduxjs/toolkit/query/react";
export const apiSice = createApi({
reducerPath: "test",
baseQuery: fetchBaseQuery({ baseUrl: process.env.REACT_APP_backend_url }),
endpoints: (builder) => ({
test: builder.query({
query: () => "/test",
}),
}),
});
export const { useTestQuery } = apiSice;
I solved it by changing the backend URL to my current ipv4 (for expo development, otherwise just your whatever your backend URL is) address in my .env file, then deleting cache, and restarting my app. In my case I was using expo so, expo r -c, and it worked.

iOS Notification Images React-Native

I have a problem to display image in my ios notification. It works on android but not in ios.
I have followed the react-native-firebase documentation and it doesn't work ....
The documentation : https://rnfirebase.io/messaging/ios-notification-images
My code to receive the notification :
buildIOSNotification = (id, title, message, data = {}, options.
= {}) => { return {
alertAction: options.alertAction || 'view',
category: options.category || '',
userInfo: {
id: id,
item: data,
},
}}
And this is the json object that i receive :
{"action": undefined, "badge": undefined, "data": {"fcm_options": {"image": "http://192.168.1.37:4000/notification/46f72f09cfc29c6a8878dd23c4cee7d2"}, "gcm.message_id": "1622999135203061", "google.c.a.e": "1", "google.c.sender.id": "556656275748", "notificationId": "A5490592-7AA1-4B6F-82BF-3BA9D6589B0A", "remote": true}, "finish": [Function finish], "foreground": true, "id": undefined, "message": "dsdsdsdsdsdsdsdsdsdsdsddsdsdsdsddsdsddsdsdsdsdsdsdsds", "reply_text": undefined, "soundName": "sound_one.mp3", "title": "ddssddsdsdsdssdsddsddsdssdsdsdssdsdsdsdsdsdsd", "userInteraction": true}

Firebase Cloud Functions silent push notification to iOS

I'm trying to send silent push notification to iOS from could functions, but cannot receive any message.
Here is my payload
const payload = {
apns: {
"headers":{
"apns-priority":"5",
"apns-push-type":"background"
},
payload: {
aps: {
"content-available": 1,
"priority": "high"
}
}
},
data: {
orderId: "123",
orderStatus: "done"
},
token: "fcm_Token_Value_Here"
}
await admin.messaging().send(payload)
Any suggestions what could be the issue?
After short investigation with firebase docs the answer is following:
const payload = {
apns: {
payload: {
aps: {
"contentAvailable": true
}
}
},
data: {
orderId: "123",
orderStatus: "done"
},
token: "fcm_Token_Value_Here"
}
Removed headers part, changed "content-available": 1 to "contentAvailable": true, and removed "priority": "high".

Implementing Push notification using Strongloop

I am trying to use strongloop loopback sdk 2.0. I tried to use the following code https://github.com/strongloop/loopback-component-push/tree/master/example/server which is loopback version 1.7.0. But when i try compile with version 2.0, it throws me error
Error: The data in model-config.json is in the unsupported 1.x format.
I had also tried as per the strong loop tutorial, but still it does not work. Anyone has suggestion or sample code on how to implement PUSH notification using loopback 2.0?
Create 4 models application, installation, notification, push
In common/models/application.json
{
"name": "push",
"plural": "Push",
"base": "Model",
"properties": {},
"validations": [],
"relations": {},
"acls": [],
"methods": []
}
In common/models/installation.json
{
"name": "installation",
"base": "Installation",
"properties": {},
"validations": [],
"relations": {},
"acls": [],
"methods": []
}
In common/models/notification.js
{
"name": "notification",
"base": "Notification",
"properties": {},
"validations": [],
"relations": {},
"acls": [
{
"principalType": "ROLE",
"principalId": "$everyone",
"permission": "ALLOW",
"property": "sendMessage"
}
],
"methods": []
}
In common/models/push.json
{
"name": "push",
"plural": "Push",
"base": "Model",
"properties": {},
"validations": [],
"relations": {},
"acls": [],
"methods": []
}
server/datasource.json
...
...
"push": {
"name": "push",
"connector": "loopback-component-push",
"installation": "installation",
"notification": "notification",
"application": "application"
}
In common/models/notification.js
module.exports = function(Notification) {
var badge = 1;
//DEFINING A PROPERTY IN NOTIFICATION FOR SENDING PUSH MESSAGE
Notification.sendMessage = function(message, registrationId, from, callback) {
var app = this.app;
from = from? from:'COMPANY_NAME';
sendMessage(app, message, registrationId, from, callback);
}//sendMessage Notification method..
//FUNCTION FOR SENDING PUSH MESSAGE..
var sendMessage = function(app, message, registrationId, from, callback){
var Application = app.models.application;
var PushModel = app.models.push;
var note = new Notification({
expirationInterval: 3600, // Expires 1 hour from now.
badge: badge++,
// sound: 'ping.aiff',
message: message,
messageFrom: from
});
PushModel.notifyById(registrationId, note, function (err) {
if (err) {
console.error('Cannot notify %j: %s', registrationId, err.stack);
return callback(err);
}
console.log('Pushing notification to %j', registrationId);
callback(null, []);
});
}//sendMessage function
//Now registering the method
Notification.remoteMethod(
'sendMessage',
{
accepts: [{arg: 'message', type: 'string', required:true},
{arg: 'registrationId', type: 'string', required:true},
{arg: 'from', type: 'string', required:true}],
description: "Sending message from notification.."
}
)
}//module.exports
Now inside server/ folder create a file push-service.js
module.exports = function(app) {
var Notification = app.models.notification;
var Application = app.models.application;
var PushModel = app.models.push;
function startPushServer() {
PushModel.on('error', function(err) {
console.error('Push Notification error: ', err.stack);
});
// Pre-register an application that is ready to be used for testing.
// You should tweak config options in ./config.js
var loopbackApp = {
id: 'loopback-push-application',
userId: 'strongloop',
name: config.appName,
description: 'loopback Push Notification Service',
pushSettings: {
apns: {
certData: "APPLE CERT. DATA",
keyData: "APPLE KEY DATA",
pushOptions: {
// Extra options can go here for APN
},
feedbackOptions: {
batchFeedback: true,
interval: 300
}
},
gcm: {
serverApiKey: "PASTE YOUR GOOGLE GCM KEY HERE"
}
}
};
updateOrCreateApp(function(err, appModel) {
if (err) {
throw err;
}
console.log('Application id: %j', appModel.id);
});
function updateOrCreateApp(cb) {
Application.findOne({
where: {
id: loopbackApp.id
}
},
function(err, result) {
if (err) cb(err);
if (result) {
delete loopbackApp.id;
result.updateAttributes(loopbackApp, cb);
} else {
return registerApp(cb);
}
});
} //updateOrCreate function
Application.beforeSave = function(next) {
if (this.name === loopbackApp.name) {
this.id = 'loopback-push-application';
}
next();
};
Application.register(
loopbackApp.userId,
loopbackApp.name, {
description: loopbackApp.description,
pushSettings: loopbackApp.pushSettings
},
function(err, app) {
if (err) {
return cb(err);
}
return cb(null, app);
}
);
} //register App
} //startPushServer
startPushServer();
};
Now finally in server.js
....
....
//Adding push service to the backend..
require('./push-service')(app);
....
Now run the loopback server open api explorer and go to NOTIFICATION->SendMessage method and type any message and it will send push notification on connected devices.
NOTE: You also need to configure push services from android/iphone to enable sending push application. For detail check loopback documentation.
Please check out this example - https://github.com/strongloop/loopback-component-push/tree/master/example/server-2.0

Resources