-
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 MTMessage
object.
Use MTMessage.deliveryMethod
attribute to determine how the message was delivered to your application:
func handle(message: 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 happens 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 notification while killed by the user, until he launch it again. In such case Mobile Messaging SDK can't tell if a fetched message was previously delivered by APNs.
In order to prevent fetched messages to be displayed using local notifications, you implement your custom message handler as follows:
class CustomMessageHandler: MessageHandling {
func didReceiveNewMessage(message: MTMessage) {
switch message.deliveryMethod {
case .generatedLocally:
if !message.isSilent {
UIApplication.shared.presentLocalNotificationNow(localNotification(with: message))
}
case .pull, .push, .undefined:
break
}
}
func localNotification(with message: MTMessage) -> UILocalNotification {
let localNotification = UILocalNotification()
localNotification.alertBody = message.text
localNotification.soundName = message.sound
return localNotification
}
}
//then set your handler to messageHandling property:
MobileMessaging.messageHandling = 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 serviceDEPRECATED- Privacy settings
- In-app chat
- WebRTC Calls and UI