Is it possible to send a "silent" push notification on iPhone (without any alert to the user)? - iphone

I need to do it on a chat app to notice the client that there is new data to fetch from the server.
I know that technically it is possible with an empty payload (at least on ios 5 device it worked), but can Apple see it as abuse of service or is it OK to do it?
And is it technically possible on ios 4 device?

Yes, increment only badge number, dont send sound and alert, So, there will be one badge on the App icon.
So, here unknowingly the badge number will be incremented to show that something has been recieved when user watches the app icon.
But your device won't recive alert or empty payload and won't recieve sound also because you asked for “silent” push notification on iPhone
and while configuring in AppDelegate, configure only badges
[[UIApplication sharedApplication] registerForRemoteNotificationTypes:UIRemoteNotificationTypeBadge];
Hope this will be helpful for you

You need to build the payload like this:
String payload =
'{
"aps":{
"content-available": 1
},
"data_id": 5,
"additional_data": ["some", "data"]
}'
In aps put the apple variales needed to make the push notification display a text, sound, badge... or just content-available to make it silent. Then, out of 'aps{...}' and separated with ',' put your custom fields to send the needed information for the download.

If you don't want the badge number to increase you could also try sending a sound notification which plays a silent sound file. (Unfortunately, I don't know if this is ok for Apple).

Related

Background notifications using Ionic like a mortal

I have been trying for several months to implement an app that receives notifications whose content I want to be stored in the database of my application. I am using the Firebase Messagging plugin and I am receiving the notifications correctly, both in Foreground and in Background.
However, in the background I am unable to execute my callback without the need to press the notification explicitly by the user. Likewise, there is no way to increase the badge of the application when it is not open.
Now, I do not understand how applications like WhatsApp, Telegram and any other application that is not made by mere mortals work. How is it possible that they can get the data in backgroud, manage the badges, synchronize messages, etc? Being that, supposedly the services like Firebase are limited in background. Even with plugins like Background Mode my application is suspended by Android when the user closes it.
The code that I am currently using to handle notifications is the following:
// In foreground (WORKS)
this.firebaseMessaging.onMessage().subscribe((notificacion) => {
// Insert in DB
...
});
// In background (DOESN'T WORK)
this.firebaseMessaging.onBackgroundMessage().subscribe((notificacion) => {
// Insert in DB
...
});
What alternative is left? The only thing that occurs to me is to use notifications in Foreground and background only as a warning. So every time I open the application I'll have to call a message synchronization callback with the server (with badge management included).
If someone has some better way, I would greatly appreciate it if you throw a little light on the subject.
From already thank you very much
Ok, after more than a year I think it's time to close this question. I solved the problem this way:
Suppose I need to get a list of messages. This action is made by a function called getMessages()
When a new message is created in the backend, I send a push notification through Firebase service.
If the push notification is received in foreground I refresh call the method directly:
this.firebaseMessaging.onMessage().subscribe((notificacion) => {
getMessages();
});
If the push notification is received in background and the user taps on it there isn't a problem as it's supported by the plugin:
this.firebaseMessaging.onBackgroundMessage().subscribe((notificacion) => {
getMessages();
});
If the push notification is received in background but the user DOES NOT tap on it and opens the app in another way than the notification, we need to excecute the corresponing function when the app is opened in app.component.ts file:
this.platform.ready().then(() => {
getMessages();
// Extra stuff like this.statusBar.styleDefault(); or this.splashScreen.hide();
});
That way all the cases are considered! You should keep in mind that apps like Whatsapp or Telegram are developed in official technologies like Java or Kotlin which not only have official native plugins, also its code are excecuted natively and not in a limited browser as Cordova or Capacitor frameworks do

Rich push notifications in Smartface App Studio

I am trying to integrate push notification in smartface. But, this push notifications are only simple text.
Is there any way i can configure rich push notifications like,
Notification which is combination of images and text.
Please help to resolve this. Thanks in advance.
I think you have to use :
LocalNotification(
id,fireDate, alertTitle, alertBody, alertAction,
userInfo, launchImage, applicationIconBadgeNumber,
hasAction, repeatInterval, sound, smallIcon, autoCancel,
number, when, usesChronometer, vibrate, ticker, subText,
priority, actions, progress, bigText, bigPicture
);
Notifications API

iPhone push notifications information

Is it possible to transfer any information in the push notification beside "badge" "sound" and "text"?
For example, in the app "whatsapp" when a push notification appears and pressed, the app is opened but not going to the conversation. My guess is that it can't know what conversation to go to. But then I saw that in facebook messenger app it actually goes in the conversation. how does the messenger app know that what conversation to go to?
Also, if it is possible to transfer information, why is it that apps like whatsapp don't use it and also ask you for your name so it will be displayed in the push?
Yes, indeed. But your message size (in bytes) must not pass a certain threshold Apple has imposed. You can then pull that info in the - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions using something like this:
NSDictionary* dictionary = [launchOptions objectForKey: UIApplicationLaunchOptionsRemoteNotificationKey];
Where dictionary contains your push notification info.
There are apps that have permission to run in the background and other apps that have not. May be facebook messenger app have this permission and can receive push notifications and do whatever is needed to go to the correct conversation or user. I don't know if this is true but it could be a possible reason.
in this method we can display pushnotifications alerts and their action according to our app
-(void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo
{
NSLog(#"did receive remore notification %#",userInfo);
if(isForground)
{
}
}
You should take a look at this documentation section Examples of JSON Payloads
At the bottom you can see custom payload examples like:
{
"aps" : {
"alert" : "You got your emails.",
"badge" : 9,
"sound" : "bingbong.aiff"
},
"acme1" : "bar",
"acme2" : 42
}
Where acme1 and acme2 are custom data that you can pass to the push notification and get it inside you app after launched.
The data is available through UIApplicationDelegate callbacks as described here Handling Local and Remote Notifications
You can add more arguments in your payload. In our app we add something like
groupID, or type.
See this stack overflow for adding more payload arguments
APNS JSON PAYLOAD - more arguments
Make sure the message size doesnt exceed 256 bytes.It is the threshold limit for the payload

APNS notification does not work when app is not running or background

I'm using pyapns to send notification to iPhone.
receiving notification when the app is running was success.
but, when app is not running or app is on background, it can't receive notification.
is it related with URL identifier or scheme? if not, what is the problem..?
Did you get called in
- (void)application:didReceiveRemoteNotification:
while you were in the app?
the problem from notification msg.
among the notify function args, there is notifications list arg.
note that, when you make this parameter, a dictionary of this list should contain below. so that the application can do alert reaction.
thePayLoad = {
'aps': {
'alert':'this option should be contained if you want to see the alert msg',
'sound':'k1DiveAlarm.caf',
'badge':42
},
'test_data': { 'foo': 'bar' }
}
In my case, I just sent msg not containing above. and in didReceiveRemoteNotification function, I made alert msg. but msg not containing alert information. so the device couldn't react.

APNS without Badge/Alert/Sound

Can I send a notification to APNS without Badge / Alert / Sound, which should notify only to my app which is installed in the iPhone ?
It's like custom notification sending via APNS to the App in the device which should not alert the user.
Is it possible,if yes how ?
Thanks in advance !
Heh. It could be done (but I don't understand the purpose of that):
1) Ask user if he wants to receive Push-notifications that contains only sound alert
2) Send Push-notification without text and set sound-file that doesn't exists in app bundle or that is silent, for example:
{
"aps" : {
"sound" : "0.aiff"
}
}
Do you understand my hack? =)