How to implement custom message handler - infobip/mobile-messaging-sdk-ios GitHub Wiki
- Create custom message handler class, it should implement
MessageHandling
protocol.
Handler in example below will show local notification when it received message.
//Swift
class CustomMessageHandler: MMMessageHandlingDelegate {
func didReceiveNewMessage(message: MM_MTMessage) {
UIApplication.shared.presentLocalNotificationNow(localNotification(with: message))
}
func localNotification(with message: MM_MTMessage) -> UILocalNotification {
let localNotification = UILocalNotification()
localNotification.alertBody = message.text
localNotification.soundName = message.sound
return localNotification
}
}
//Objective-C
@interface CustomMessageHandler : NSObject<MMMessageHandlingDelegate>
@end
@implementation CustomMessageHandler
- (void)didReceiveNewMessageWithMessage:(MM_MTMessage *)message {
[UIApplication sharedApplication] presentLocalNotificationNow:[self localNotificationWithMesage:message](/infobip/mobile-messaging-sdk-ios/wiki/UIApplication-sharedApplication]-presentLocalNotificationNow:[self-localNotificationWithMesage:message);
}
- (UILocalNotification*)localNotificationWithMesage:(MM_MTMessage *)message {
UILocalNotification* notification = [UILocalNotification new];
notification.alertBody = message.text;
notification.soundName = message.sound;
return notification;
}
@end
- Set your message handler to MobileMessaging property
//Swift
MobileMessaging.messageHandlingDelegate = CustomMessageHandler()
//Objective-C
[MobileMessaging setMessageHandlingDelegate:[CustomMessageHandler new]];