It's possible to change push notification message before display on device from iOS side?
Asked Answered
W

3

14

Display my push notification message is "Message from: +919687335565"

attached screenshot :

enter image description here

I just want to fetch the name of this +919687335565 contact number from the Address book and display name of this contact instead of a phone number in push notification.

Before displaying notification i want to replace phone number +919687335565 with its contact name Chandresh in push notification.

like attached screenshot :

enter image description here

Welloiled answered 27/12, 2016 at 13:14 Comment(7)
Whatever is sent in the payload of the push notification is displayed in the banner shown to the user. If you want to customize this message, you'll have to change what you are sending to the APNs service.Dutcher
let me check !!! VoIPWelloiled
@ChandreshKachariya check my answer.Prowler
I think you need to sync your contacts with server on each app launch and set aps content with name instead number.Taiwan
@SatishVekariya Don't required to sync contacts with server and also already answer is given in belove by dirtydanee. Without sync it's possible using Silent Notifications.Welloiled
@ChandreshKachariya No, It not possible with silent push. Once your app is terminated from app switcher, I guarantee!!Taiwan
@SatishVekariya silent push is working in my application in every state. It's one type VOIP service so work after terminated appWelloiled
P
11

There are various possibilities for preprocessing and modify the payload of a notification on iOS.

Before iOS 10

You could be sending Silent Notifications, what will not be not shown to the user. Will wake our application when it is terminated or in background, and you will be able to do preprocessing on the notification content. See more info here, how to set it up. However, this notification type is not 100% reliable, and should not be abused, e.g. used for all notifications to be delivered, because Apple could stop the notifications to be sent after a number of messages.

The other option is, if your application supports VoIP. This way your app will pretty much always listen to push notifications, and you will be always available to preprocess the notifications, before you would be displaying them. However, if your app does not have real VoIP capabilities, e.g. phone calls, your app will be rejected by Apple on the review. Here is a great tutorial, how to set it up.

From iOS 10

With the introduction of iOS 10, we are finally able to do preprocessing on our notifications, even, when the app is in background or terminated. No VoIP capabilities or special type of notifications needed to be sent. Here is a great tutorial, how to set it up.

Prowler answered 27/12, 2016 at 13:58 Comment(1)
You can't wake a force-killed (terminated) app with a silent notification, can you ?Cabasset
D
-1

This is possible, except:

want to fetch name of this +91********* contact number from Address book

because Address Book is not accessible when app is in background!
You have to write separate logic in app itself to replace mobile no by appropriate name.

How other than this is possible:

Before iOS 10 and iOS 8+:
Use PushKit to send silent push notifications, app will be woken up by iOS, change the mobile no by name, show local notification.

iOS 10+:
Use Notification Service Extension to alter notification content before it'll shown to user.
Look at this official documentation

Using this service extension, iOS gives you a way to first receive notification directly to app, modify content and then deliver to user.
Here you can change mobile no by name.

Diazo answered 9/1, 2017 at 16:3 Comment(2)
It's possible to fetch contact number from address book while app is in background.!!! In my case.Welloiled
The AddressBook/Contacts API is also not accessible from a service extension. There is no way for the user to grant permission to access it.Boric
D
-3

No this is not possible. Because the push notification is handle by server. This message is only change by server not from app because that time app is in background or terminated. But you can change message when app is in foreground and background fetch is enable then you can customize your message and can show it.

Deas answered 27/12, 2016 at 13:19 Comment(6)
Thanks @vivek padaya for your valuable response but i required when apps is terminated also in background, because it's client requirement.Welloiled
But it is not possible in iOS but You can achieve it in android.Deas
#32761020Deas
here we are talking about normal push not VoIP pushDeas
i strongly believe this answer is highly inaccurate, and very miss-leading.Prowler
This is not true, there are ways to achieve this!Diazo

© 2022 - 2024 — McMap. All rights reserved.