iOS Notification Images React-Native - firebase

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}

Related

unable to access session using next-auth

The session is stored in cookies. When I use this {session ? `${session.user.email}` : ''} it keeps saying undefined.
This is my JSON object:
{
"user": {
"token": {
"responseCode": 0,
"responseMessage": "success",
"data": {
"id": 6,
"userId": "SYS-9d502c43-9ef3-432d-ab93-be0b8236cdff",
"fullName": "yeshewas string",
"username": "yes#yes.com",
"userRole": "Super User",
"permissions": []
}
}
},
"expires": "2022-06-24T06:14:39.011Z"
}
Try to change your jwt callback like this:
callbacks: {
jwt: async ({ token, user }) => {
user && (token.user = user.user)
return token;
},
},

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.

FCM flutter enable notification vibration

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)

Calendar API Event Attendees Response Status always changes to "Needs Action"

I am doing callout from salesforce to google calendar api to upsert a google event. when i make the request, it always changes the attendee status to "NeedsAction", so when I sent request to google, attendee status was "Accepted" but in response i got "NeedsAction". Why google always changes the attendee response. Please help if anyone knows. Thanks
Request Body :
{
"kind" : "calendar#event",
"summary" : "nice 13 val",
"description" : "this is new",
"location" : "3 value friday",
"start" : {
"dateTime" : "2020-08-13T12:30:00+05:00"
},
"end" : {
"dateTime" : "2020-08-13T13:30:00+05:00"
},
"attendees" : [ {
"email" : "mohit.kumar#test.in",
"organizer" : true,
"responseStatus" : "accepted"
}, {
"email" : "test#gmail.com",
"responseStatus" : "accepted"
} ]
}
Callout :
Http http = new Http();
HttpRequest httpReq = new HttpRequest();
httpReq.setEndpoint('https://www.googleapis.com/calendar/v3/calendars/mohit.kumar#test.in/events/'+objEvent.Google_Event_Id__c);
httpReq.setTimeout(30000);
httpReq.setHeader('Content-Type', 'application/json');
httpReq.setMethod('POST');
httpReq.setHeader('X-HTTP-Method-Override','PATCH');
httpReq.setHeader('Authorization', 'Bearer ' + accessToken);
String reqBody = createEventBody(objEvent, googleSettingInfo);
if (String.isNotBlank(reqBody)) {
httpReq.setBody(reqBody);
}
if (httpReq.getBody() != null && httpReq.getBody() != '') {
HttpResponse httpRes = http.send(httpReq);
System.debug('code: ' + httpRes.getStatusCode());
if (httpRes.getStatusCode() == 200) {
System.debug('response: ' + httpRes);
System.debug('create event response body: ' + httpRes.getBody());
}
}
getting attendees response always as "needs Action" while this should be "accepted" for "test#gmail.com"
{
"created": "2020-08-11T18:51:41.000Z",
"updated": "2020-08-28T06:48:49.972Z",
"summary": "nice 13 val",
"description": "this is new",
"location": "3 value friday",
"creator": {
"email": "mohit.kumar#test.in",
"self": true
},
"organizer": {
"email": "mohit.kumar#test.in",
"self": true
},
"start": {
"dateTime": "2020-08-13T14:00:00+05:30"
},
"end": {
"dateTime": "2020-08-13T15:00:00+05:30"
},
"sequence": 16,
"attendees": [
{
"email": "test#gmail.com",
"responseStatus": "needsAction"
},
{
"email": "mohit.kumar#test.in",
"organizer": true,
"self": true,
"responseStatus": "accepted"
}
],
Proposed modification:
What about modifying the createEventBody function in order to create a simple JSON object that will only contain the attendees information with the updated statuses.
This will leverage correctly the PATCH semantics and helps a lot on improving readability.
I tested it myself and your generated JSON object returns an error on the start property. Removing that will help you solve that error too. Finally I tested that passing the attendees property to the PATCH method will work as intended.
You can try using the "Try this API" functionality before actually update your code.
Reference:
Events patch

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