-
Notifications
You must be signed in to change notification settings - Fork 21
How can I be sure that message is delivered?
Because the delivery of remote notifications is not guaranteed by Apple Push Notification service (APNs) as described in the documentation, Mobile Messaging SDK has a fetching mechanism to get messages that weren't delivered by APNs.
All fetched messages will be displayed using local notifications by default, this behaviour is implemented by MMDefaultMessageHandling
class.
Every message that either was pushed by APNs or fetched from Mobile Messaging server is represented by MM_MTMessage
object.
Use MM_MTMessage.deliveryMethod
attribute to determine how the message was delivered to your application:
func handle(message: MM_MTMessage) {
switch message.deliveryMethod {
case .push:
//message pushed by APNs
case .pull:
//message fetched from Mobile Messaging server
default:
break
}
}
NOTE: As a compromise between APNs delivery restrictions and our pursuit of improved delivery rate, there is a chance that a message may appear twice. This may happen if a push message was delivered by APNs while application was killed by the user, because Apple doesn't allow the application to handle remote notifications until relaunched. Once the app launched, Mobile Messaging SDK will fetch messages that were sent, but not yet handled by the SDK. In such case Mobile Messaging SDK can't tell if a fetched message was previously delivered by APNs and will try to display them.
In order to prevent fetched messages to be displayed using local notifications, you implement your custom message handler as follows:
class CustomMessageHandler: MMMessageHandlingDelegate {
func didReceiveNewMessage(message: MM_MTMessage) {
switch message.deliveryMethod {
case .generatedLocally:
if !message.isSilent {
UIApplication.shared.presentLocalNotificationNow(localNotification(with: message))
}
case .pull, .push, .undefined:
break
}
}
func localNotification(with message: MM_MTMessage) -> UILocalNotification {
let localNotification = UILocalNotification()
localNotification.alertBody = message.text
localNotification.soundName = message.sound
return localNotification
}
}
//then set your handler to messageHandling property:
MobileMessaging.messageHandlingDelegate = CustomMessageHandler()
If you have any questions or suggestions, feel free to send an email to support@infobip.com or create an issue.
- Library events
- Server errors
- Users and installations
- Messages and notifications management
- Inbox
- Geofencing service
- Privacy settings
- In-app chat
- WebRTC Calls and UI