//进行本地推送
-(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];
}
}
});//全局
}
注册通知推送
最后编辑于 :
©著作权归作者所有,转载或内容合作请联系作者
- 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
- 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
- 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
推荐阅读更多精彩内容
- //如果版本升级到了8.0以上需要先注册才能使用 if([UIApplicationinstancesRespon...
- title : 本地推送通知、远程推送通知、激光推送category : UI 本地推送通知、远程推送通知、激光...
- @(〓〓 iOS-实用技术)[远程/本地推送] 作者: Liwx 邮箱: 1032282633@qq.com 目...
- WWDC session - Notifications 学习总结,如有不妥之处,望请指正🙏🙏 pusher工具[...