//进行本地推送
-(void)receiveLocalNotificaionWithDictionary:(NSDictionary *)dict {
dispatch_barrier_async(dispatch_get_global_queue(0, 0), ^{
CGFloat deviceFloat = [[[UIDevice currentDevice] systemVersion] floatValue];
if (deviceFloat >= 10.0) {
#ifdef __IPHONE_10_0
NSLog(@"LocalNotification");
//Local Notification
UNMutableNotificationContent *content = [[UNMutableNotificationContent alloc] init];
content.body = dict[@"description"];//内容
content.sound = [UNNotificationSound defaultSound];
content.userInfo = dict;
content.categoryIdentifier = dict[@"msgId"];
//content.badge = @1;
//10秒后提醒
UNTimeIntervalNotificationTrigger *trigger = [UNTimeIntervalNotificationTrigger triggerWithTimeInterval:3 repeats:NO];
NSString *requestIdentifier = dict[@"msgId"];//@"sampleRequest";
UNNotificationRequest *request = [UNNotificationRequest requestWithIdentifier:requestIdentifier content:content trigger:trigger];
[[UNUserNotificationCenter currentNotificationCenter] addNotificationRequest:request withCompletionHandler:^(NSError * _Nullable error) {
if (error == nil) {
NSLog(@"Time Interval Notification scheduled: %@",requestIdentifier);
}
else {
NSLog(@"error : %@",error);
}
}];
#endif
}
else {
UILocalNotification* notification=[[UILocalNotification alloc] init];
if (nil != notification) {
UIApplication *application = [UIApplication sharedApplication];
// application.applicationIconBadgeNumber ++;
notification.fireDate = [NSDate date];
notification.timeZone= [NSTimeZone defaultTimeZone];
notification.alertBody = [NSString stringWithFormat:@"%@",dict[@"description"]];
//如果app不在前台打开提示音
if(application.applicationState != UIApplicationStateActive){
//通知提示音 使用默认的
notification.soundName = UILocalNotificationDefaultSoundName;
}else{
notification.soundName = @"";
}
notification.userInfo = dict;
// AudioServicesPlaySystemSound(1004); //更换播放系统的声音 id值可以百度查询
// AudioServicesPlaySystemSound(kSystemSoundID_Vibrate);//震动
// 启动通知
NSLog(@"scheduleLocalNotification");
[[UIApplication sharedApplication]scheduleLocalNotification:notification];
}
}
});//全局
}
网友评论