I need to send a notification from the device (not the back-end) is there a way to do that ?
Thanks for response I ll be grateful
as mentioned by the others, you can use some libraries for this purpose. Among them I believe 'react-native-push-notification' is more widely endorsed: https://www.npmjs.com/package/react-native-push-notification
Note that if you are using RN0.60.+ it will autolink for you and you don't have to go through steps like react-native link or adding packages in MainApplication.java. If not, the repo itself has detailed instruction on installation too.
Moreover, part of this library has dependencies on gms/firebase, so in a HMS context you cannot use some of its features, e.g. remote notification. If your purpose is solely local notification then you are good to go.
Also note that if you plan on handling the click of your local notification, you'll need to configure onNotificaiton to listen to the click. One important point to note is on HMS devices the requestPermission param must be set to false otherwise a firebase dependency will be called and cause errors.
Sample code snippets:
import PushNotification from 'react-native-push-notification'
export default class App extends Component {
...
componentDidMount() {
...
PushNotification.configure({
// (required) Called when a remote is received or opened, or local notification is opened
onNotification: function (notification) {
console.log("NOTIFICATION:", notification);
// process the notification
// (required) Called when a remote is received or opened, or local notification is opened
notification.finish(...);
},
// Should the initial notification be popped automatically
// default: true
popInitialNotification: true,
/**
* (optional) default: true
* - Specified if permissions (ios) and token (android and ios) will requested or not,
* - if not, you must call PushNotificationsHandler.requestPermissions() later
* - if you are not using remote notification or do not have Firebase installed, use this:
* requestPermissions: Platform.OS === 'ios'
*/
requestPermissions: false,
});
...
}
...
onSendLocalNotification = () => {
PushNotification.localNotification({
/* Android Only Properties */
id: 0, // (optional) Valid unique 32 bit integer specified as string. default: Autogenerated Unique ID
ticker: "My Notification Ticker", // (optional)
autoCancel: true, // (optional) default: true
largeIcon: "ic_launcher", // (optional) default: "ic_launcher"
smallIcon: "ic_notification", // (optional) default: "ic_notification" with fallback for "ic_launcher"
bigText: "My big text that will be shown when notification is expanded", // (optional) default: "message" prop
subText: "This is a subText", // (optional) default: none
color: "red", // (optional) default: system default
vibrate: true, // (optional) default: true
vibration: 300, // vibration length in milliseconds, ignored if vibrate=false, default: 1000
tag: "some_tag", // (optional) add tag to message
group: "group", // (optional) add group to message
ongoing: false, // (optional) set whether this is an "ongoing" notification
priority: "high", // (optional) set notification priority, default: high
visibility: "private", // (optional) set notification visibility, default: private
importance: "high", // (optional) set notification importance, default: high
allowWhileIdle: false, // (optional) set notification to work while on doze, default: false
ignoreInForeground: false, // (optional) if true, the notification will not be visible when the app is in the foreground (useful for parity with how iOS notifications appear)
/* iOS only properties */
alertAction: "view", // (optional) default: view
category: "", // (optional) default: empty string
userInfo: {}, // (optional) default: {} (using null throws a JSON value '<null>' error)
/* iOS and Android properties */
title: "My Notification Title", // (optional)
message: "My Notification Message", // (required)
playSound: false, // (optional) default: true
soundName: "default", // (optional) Sound to play when the notification is shown. Value of 'default' plays the default sound. It can be set to a custom sound such as 'android.resource://com.xyz/raw/my_sound'. It will look for the 'my_sound' audio file in 'res/raw' directory and play it. default: 'default' (default sound is played)
number: 10, // (optional) Valid 32 bit integer specified as string. default: none (Cannot be zero)
repeatType: "day", // (optional) Repeating interval. Check 'Repeating Notifications' section for more info.
actions: '["Yes", "No"]', // (Android only) See the doc for notification actions to know more
});
}
...
}
I hope you can use the code pattern.
Related
This is the exact step noted from this readme section.twilio queue callback flex plugin
There it is instructed to update accountSid variable. But there is no accountSid variable in appConfig.js (code 1). Assuming, I should add the extra variable I did as showed in code 1 (comment ) below.But, the react app didn't work properly,it didn't show any call baack option or voicemail in the task (image added)
Step 3: Open appConfig.js with your text editor and update the accountSid variable with your account SID:
var accountSid = 'ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX'
//code 1
//assuming here I have to add this line "var accountSid =
//'ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX'"
var appConfig = {pluginService: {
enabled: true,
url: '/plugins',} ,ytica: false, logLevel: 'info', showSupervisorDesktopView: true,};
Twilio developer evangelist here.
You are right that you need to add the accountSid to the appConfig.js file. It should look like this:
var accountSid = 'ACXXXXX';
var appConfig = {
pluginService: {
enabled: true,
url: '/plugins',
},
ytica: false,
logLevel: 'info',
showSupervisorDesktopView: true,
};
I wonder if you don't see a proper voicemail recording or way to callback because the number they called from, +266696687, is invalid. More than invalid, it is in fact an anonymous number. The numbers 266696687 type out "ANONYMOUS" on a phone keyboard.
On Android, I'm utilizing the LocalNotifications API in an Ionic project with Capacitor JS (https://capacitorjs.com/docs/apis/local-notifications). So the user can respond directly to a notification, I've added some action types to the payload like this:
LocalNotifications.registerActionTypes({
types: [
{
id: "workout-1",
actions: [
{
id: ":+1:",
title: "đź‘Ť",
destructive: true,
},
{
id: ":muscle:",
title: "đź’Ş",
destructive: true,
},
{
id: "free_text",
title: "Respond",
input: true,
},
],
},
This enables the message to render like this:
However, even when tapping one of emojis, it opens the app. All I'd like it to do is trigger action performed on the emoji that was tapped. It works this way on iOS. Any ideas?
You have to set up an event listener in your application setup phase:
LocalNotifications.addListener('localNotificationActionPerformed', (notification) => {
const tappedActionId = notification.actionId;
// TODO: do action depending on actionId
}
When user taps on notification or any action, app will open and this function will run. When user taps on notification (not action) actionId = 'tap'.
As related to this documentation :
https://capacitorjs.com/docs/apis/local-notifications
It seems possible to use Capacitor local notification plugin for the web as pwa also.
I try to push "test" a local notification every 10 seconds but nothing happen even with service worker enabled
import { Plugins } from '#capacitor/core';
const { LocalNotifications } = Plugins;
const notifs = await LocalNotifications.schedule({
notifications: [
{
title: "Title",
body: "Body",
id: 1,
schedule: {
repeats: true,
every: "second",
count: 10
},
sound: null,
attachments: null,
actionTypeId: "",
extra: null
}
]
});
console.log('scheduled notifications', notifs);
In the source code of the LocalNotification plugin for web it seems as though the notification is only scheduled if the schedule option has the "at" property.
Even then I can't get it to work on chrome for android.
Notification scheduling for PWAs is currently in trial using the TimestampTrigger so I think the lack of browser support is the issue. Possibly getting out of trial during 2021. Just have to wait and see I guess.
I am working on a project where I want to make Push notifications work, on Parse-Server (Heroku), with an iOS app.
This is the code I use on the server side to generate a PUSH:
const pushQuery = new Parse.Query(Parse.Installation);
pushQuery.equalTo('deviceType', 'ios');
Parse.Push.send({
where: pushQuery, // Set our Installation query
data: {alert: "ABCXYZ"}
}, {
useMasterKey: true,
success: function() {},
error: function(error) {
throw "Got an error " + error.code + " : " + error.message;
}
});
On the iOS app side, I receive the notification, but I would like to tweak it to my taste, if possible.
Here is the relevant swift code where I can see the notification coming:
func userNotificationCenter(_ center: UNUserNotificationCenter,
willPresent notification: UNNotification,
withCompletionHandler completionHandler: #escaping (UNNotificationPresentationOptions) -> Void) {
print(#function)
print("NN = \(notification.description)")
}
And finally, this is what I can see in the Xcode debugging console, when the notification arrives:
userNotificationCenter(_:willPresent:withCompletionHandler:)
NN = <UNNotification: 0x2....; date: 2020-03-02 06:51:39 +0000,
request: <UNNotificationRequest: 0x28....3e0; identifier: 0C....AF3,
content: <UNNotificationContent: 0x28....6c0; title: (null), subtitle: (null),
body: ABCXYZ, summaryArgument: , summaryArgumentCount: 0, categoryIdentifier: ,
launchImageName: , threadIdentifier: , attachments: (
), badge: (null), sound: (null),,
trigger: <UNPushNotificationTrigger: 0x28...0;
contentAvailable: NO, mutableContent: NO>>>
Obviously, it is working up to a point. But I can see fields in the incoming notification that I do not control. Namely: title, subtitle, summaryArgument, categoryIdentifier ...... In fact only "body" is what I have set on the server side.
Therefore my question is: how can I set all those fields the way I wish.
I have already tried something like this:
data: {
title: "MyOwnTitle",
alert: "ABCXYZ"
}
But without success.
Furthermore, by using something like:
data: {
alert: "ABCXYZ",
content_available: 1,
push_type: "background",
category: "S3x"
}
I can see the following in the Xcode debugging console, when the notification arrives:
userNotificationCenter(_:willPresent:withCompletionHandler:)
NN = <UNNotification: 0x28...; date: 2020-03-03 ...,
request: <UNNotificationRequest: 0x2..;
identifier: BF...EE, content: <UNNotificationContent: 0x28..;
title: (null), subtitle: (null), body: ABCXYZ,
summaryArgument: , summaryArgumentCount: 0,
categoryIdentifier: S3x, launchImageName: ,
threadIdentifier: , attachments: (
), badge: (null), sound: (null),,
trigger: <UNPushNotificationTrigger: 0x28..;
contentAvailable: NO, mutableContent: NO>>>
Where it appears that the "ABCXYZ" part is transferred as well as the category (S3x), but the rest (content_available,push_type) seems to be ignored.
According to Parse push notification docs, you can send the following options in your push notification payload:
alert: the notification’s message.
badge: (iOS only) the value indicated in the top right corner of the app icon. This can be set to a value or to Increment in order to increment the current value by 1.
sound: (iOS only) the name of a sound file in the application bundle.
content-available: (iOS only) If you are a writing an app using the Remote Notification Background Mode introduced in iOS7 (a.k.a. “Background Push”), set this value to 1 to trigger a background download. You also have to set push_type starting iOS 13 and watchOS 6.
push_type: (iOS only) The type of the notification. The value is alert or background. Specify alert when the delivery of your notification displays an alert, plays a sound, or badges your app’s icon. Specify background for silent notifications that do not interact with the user. Defaults to alert if no value is set. Required when delivering notifications to devices running iOS 13 and later, or watchOS 6 and later.
priority: (iOS only) The priority of the notification. Specify 10 to send the notification immediately. Specify 5 to send the notification based on power considerations on the user’s device. (More detailed documentation)
category: (iOS only) the identifier of the UNNotification​Category for this push notification.
uri: (Android only) an optional field that contains a URI. When the notification is opened, an Activity associated with opening the URI is launched.
title: (Android only) the value displayed in the Android system tray notification.
Besides these, you can also write a custom push notification handler in your iOS app by following this guide: http://docs.parseplatform.org/ios/guide/#responding-to-the-payload
I am trying to get this route to work
items/images/myimg.jpg
It responses 404 but work with
items/images/myimg
Also works with
items/images/myimg.jpg/
I tried the following router configuration
'get /items/images/:imageName': {
action: 'items/images/find',
skipAssets: true,
}
EDIT:
If I set skipAssets: false then the response will be unauthorized. I have the following ACL
'*': false,
'items/images/find': 'isLoggedIn',
In the isLoggedIn.js policy the req.session is undefined even when the user has a valid session.
if I set 'items/images/find': true it will work but I want access control for this route.
The route should be set like this:
'get /items/images/:imageName': {
action: 'items/images/find',
skipAssets: false,
}
This method should be added to config/session.js:
isSessionDisabled: function (req){
// Allow session for all item image requests.
if (req.path.match(/^\/items\/images\//) {
return false;
}
// Otherwise, disable session for all requests that look like assets.
return !!req.path.match(req._sails.LOOKS_LIKE_ASSET_RX);
}
More can be read about this here:
https://github.com/balderdashy/sails/issues/4216#issuecomment-337613995