-
Notifications
You must be signed in to change notification settings - Fork 19
How to implement custom message handler
Davor Komušanac edited this page Dec 5, 2022
·
3 revisions
- 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]];
}
- (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]];
If you have any questions or suggestions, feel free to send an email to [email protected] 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