UNUserNotificationCenter (iOS10.0)
if (NSClassFromString(@"UNUserNotificationCenter")) { // ios 10
// 设置触发时间
UNTimeIntervalNotificationTrigger *trigger = [UNTimeIntervalNotificationTrigger triggerWithTimeInterval:0.01 repeats:NO];
UNMutableNotificationContent *content = [[UNMutableNotificationContent alloc] init];
content.sound = [UNNotificationSound defaultSound];
content.body = body;//展示内容
content.categoryIdentifier = conversationId;//传递类型
content.userInfo = userInfo;//传递参数
UNNotificationRequest *request = [UNNotificationRequest requestWithIdentifier:messageId content:content trigger:trigger];
[[UNUserNotificationCenter currentNotificationCenter] addNotificationRequest:request withCompletionHandler:nil];//执行回调
[UNUserNotificationCenter currentNotificationCenter].delegate = self;
}
//点击跳转代理方法
- (void)userNotificationCenter:(UNUserNotificationCenter *)center didReceiveNotificationResponse:(UNNotificationResponse *)response withCompletionHandler:(void(^)(void))completionHandler __IOS_AVAILABLE(10.0) __WATCHOS_AVAILABLE(3.0) __TVOS_PROHIBITED{
[self receiveNotificationWithUserInfo:response.notification.request.content.userInfo];
}
UILocalNotification(iOS10.0 之前)
UILocalNotification *notification = [[UILocalNotification alloc] init];
notification.fireDate = [NSDate date]; //触发通知的时间
notification.alertBody = body;
notification.alertAction = @"Open";
notification.timeZone = [NSTimeZone defaultTimeZone];
notification.soundName = UILocalNotificationDefaultSoundName;
notification.userInfo = userInfo;
[[UIApplication sharedApplication] scheduleLocalNotification:notification];
//点击跳转方法
-(void)application:(UIApplication *)application didReceiveLocalNotification:(UILocalNotification *)notification