#import <MobPush/MobPush.h>
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(didReceiveMessage:)
name:MobPushDidReceiveMessageNotification object:nil];
// 收到通知回调
-
(void)didReceiveMessage:(NSNotification *)notification
{
MPushMessage *message = notification.object;switch (message.messageType)
{
case MPushMessageTypeCustom:
{// 自定义消息} break; case MPushMessageTypeAPNs: {// APNs 回调 if ([UIApplication sharedApplication].applicationState == UIApplicationStateActive) { // 前台 } else { // 后台 } } break; case MPushMessageTypeLocal: { // 本地通知回调 NSString *body = message.notification.body; NSString *title = message.notification.title; NSString *subtitle = message.notification.subTitle; NSInteger badge = message.notification.badge; NSString *sound = message.notification.sound; NSLog(@"收到本地通知:{\nbody:%@,\ntitle:%@,\nsubtitle:%@,\nbadge:%ld,\nsound:%@,\n}",body, title, subtitle, badge, sound); } break; default: break;
}
}
//AppDelegate
#import <MobPush/MobPush.h>
// 设置推送环境
#ifdef DEBUG
[MobPush setAPNsForProduction:NO];
#else
[MobPush setAPNsForProduction:YES];
#endif
//MobPush推送设置(获得角标、声音、弹框提醒权限)
MPushNotificationConfiguration *configuration = [[MPushNotificationConfiguration alloc] init];
configuration.types = MPushAuthorizationOptionsBadge | MPushAuthorizationOptionsSound | MPushAuthorizationOptionsAlert;
[MobPush setupNotification:configuration];