This has obviously been asked multiple times but I can't seem to get any of the proposed solutions working.
Push notifs work when tethered to xcode. Untethered, I get the push notification itself but none of the delegate methods are called which results in not being able to increment badge count.
I also can't get silent notifications working on untethered as well. I use silent notifications to clear a notification with a given condition.
I've tried allowing background mode in plist, changing priorities, having an empty body. I've made sure that the device background refresh is on and that notifs are fully on. I've tried a ton more things that I can't remember off the top of my head. Nothing seems to work. I added a badge increment in every one of the push notif delegate methods and it seems none of them get called.
Here is the .js code snippet for regular notif
message1 = {
notification: {
title: "stackOverFlowTitle",
body: "stackOverFlowBody"
},
apns: {
payload: {
aps : {
"content-available": 1,
"sound": "default",
"priority" : 10
},
data: {
// collection: 'TestCollection',
// document: change.after.ref.id,
timePushed: timePushed,
alertOn: alertOn,
readNotification: readNotification,
eventKey: eventKey
}
},
headers: {
"apns-expiration": "4"
}
},
topic: topic
};
Here is the .js code snippet for silent notif
var message2 = {
notification: {
body: ""
},
apns: {
payload: {
aps: {
"content-available": 1,
"priority" : 10
},
data: {
alertOn: alertOn,
eventKey: eventKey
}
},
headers: {
"apns-expiration": "4"
}
},
topic: topic
};
Anyone have any potential solutions I haven't mentioned?
I changed silent notif priority to 5 and that helped (for this post) :D
According to the docs, when non-zero the apns-expiration represents a unix timestamp. By setting it to 4, you're telling APNs to expire the notification at 1970-01-01 00:00:04.
Related
I have been looking all over the threads of a way to make the app recieve the silent push notification while the app is terminated.
I have tried:
{
"data" : {
"foo" : boo
},
"apns" : {
"header" :{
'apns-priority' : '10' && i also tried 5
}
"aps" : {
"content-available" : 1
},
}
}
I know it´s possible since ton of apps use it to update app content while app is killed or after mobile restart. When I open the console I can see that the message is arrived but my app doesnt wake up.
I have made a print('xx') right at the beginning of my app.
I have no issue receiving data notifications on background/foreground,
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.
The Problem
I have a Google Actions SDK project and I am using the nodejs client library for building fulfillment. I am facing some problem trying to use the Confirmation Helper intent. It is overriding previous responses given before it. Let me give you a simplified example of the problem:
First, Action says, "Hi, hope you are having a great day"
Then, Action asks for a Confirmation, "Do you want today's weather report?"
But in the simulator, all I hear is the second question. I am targeting a Voice Only situation, so I really need all the responses. Interestingly, I can see all the responses in the AUDIO tab of simulator. How can I hear both of these phrases?
I am copy/pasting the response JSON as shown in the RESPONSE tab.
{
"expectUserResponse": true,
"expectedInputs": [
{
"possibleIntents": [
{
"intent": "actions.intent.CONFIRMATION",
"inputValueData": {
"#type": "type.googleapis.com/google.actions.v2.ConfirmationValueSpec",
"dialogSpec": {
"requestConfirmationText": "Do you want today's weather report?"
}
}
}
],
"inputPrompt": {
"richInitialPrompt": {
"items": [
{
"simpleResponse": {
"textToSpeech": "Hope you are doing well!"
}
}
]
}
}
}
],
"conversationToken": ""
}
How can I fix this situation. Thanks!
This is intentional behavior as using one of the intents like Confirmation will be the only response, and other responses will be ignored.
There are two potential ways to get around this.
Combine all of your responses to be in the Confirmation
Create your own Yes/No intent and use simple responses for everything.
I have iOS app written in Swift. I use Parse SDK for push notifications.
I want to add badge to app icon when push is received. There is problem - I can't add badge from push directly because there are a lot of users that use previous version of my app. And if I add badge from push - this badge will not disappear because previous app versions don't hide badge after it opened. So badge will be always on icon.
So what I want is to handle push by my app. No matter is it running or not. If push arrives - my app adds badge. So I can I handle push by my app if it is not running?
I know how to add badge with Swift
application.applicationIconBadgeNumber = 5
But how can i do it without opening the app - just when push is received?
When you push the app, you need to send the badge count with it:
{
"aps": {
"alert": "message goes here",
"sound": "sound.aiff",
"badge": 5
}
}
This will change the badge number on the app before it has been opened.
Please note that you cannot change the badge number of an app when it is closed without using notifications to do so.
Like said in the Parse docs, you can set badge number setting the badge field in the payload with an integer
ex:
"data": {
"alert": "The Mets scored! The game is now tied 1-1.",
"badge": 5,
"sound": "default",
"title": "Mets Score!"
}
or with Increment to automatically increment current value in badge count
ex:
"data": {
"alert": "The Mets scored! The game is now tied 1-1.",
"badge": "Increment",
"sound": "default",
"title": "Mets Score!"
}
To send push notifications with Parse just use the following code, making sure you change the channel to the correct one:
let push = PFPush()
push.setChannel("MyChannel")
push.sendPushInBackground()
Then to hide the badges once the user opens the app back up, add the following function to your AppDelegate.swift:
func applicationDidBecomeActive(application: UIApplication) {
//Reset badge counter to zero
var currentInstallation = PFInstallation.currentInstallation()
if(currentInstallation.badge != 0){
currentInstallation.badge = 0
}
}
since Parse SDK keeps it's own badge count separate from iOS app badge count, you need to follow it like this to rest the badge count to zero.
- (void)applicationDidBecomeActive:(UIApplication *)application {
PFInstallation *currentInstallation = [PFInstallation currentInstallation];
if (currentInstallation.badge != 0) {
currentInstallation.badge = 0;
[currentInstallation saveEventually];
}
// ...
}
In Swift 2.0,
let parseinst: PFInstallation = PFInstallation.currentInstallation();
if (parseinst.badge != 0)
{
parseinst.badge = 0;
parseinst.saveEventually()
}
I am facing one unusual issue that my notification is not coming in notification tray. Though I am getting sound and begde count too. So there should not be any problem with provisioning profile. I am not able to find anything with googling.
I have tested this case when app is in background and killed.
I have checked in settings also for my application its banner is selected.I also try with alerts but alerts are not appearing.
Any idea about this issue?
NSDictionary *userInfo = [launchOptions objectForKey: UIApplicationLaunchOptionsRemoteNotificationKey];
I am getting this userInfo = nil
Is this the issue notification not appearing in notification bar?
Finally I got the issue and that was from server side.
Might be one of the same case for others too..
aps = {
alert = {
dictioanry = {
key = value;
key = value;
};
};
badge = 1;
sound = default;
};
Here I asked the php person to add body tag and I was able to get notifications in tray..
So for the people with same issue just check out if you are missing any key from the server side.
For those who are using FCM Push Notif, might need to check wheter the payload has "notification" field there.
Here is the example of full payload working with FCM:
{
"registration_ids" : ["xx5MSpbpuUe6lgYhXTX-gs:APA91bFxKmDCTlE2WA_hl29XjiNK7A-qpdRBJaz-JddCsx5CAxxxxxxxxxxGcoO0-moOMqT2T59cExxxxxt-uMgLUQgg4t8jL3uuccka6psdBXVl26bx2HfnSbvKAxxxxxx-x_xxxxx_"],
"priority": "high",
"data" : {
"app_link": "xyz://abc/def/123/456",
"title": "Testing",
"icon": "htt://abc/image.png",
},
"notification": {
"body": "Notification body",
"title": "Here is the title",
"subtitle": "and this is subtitle",
"sound" : true,
"content_available": true,
"mutable_content": true,
"priority": "high",
"badge": "1"
}
}