IOS本地推送

环境:unity 2017.4.26

1、unity 提供ios本地推送功能:支持后台/结束进程,不支持在前台接收推送

参考地址:

https://blog.csdn.net/shuangkui5355/article/details/79064241

2、用oc写:支持前台/后台/结束进程接收推送

ios10以上调用,后台模式或者应用关闭状态。

( >= IOS 10 )userNotificationCenter:willPresentNotification:withCompletionHandler:

参考地址:

https://www.jianshu.com/p/332802291e93

GitHub地址:支持本地推送/远程推送

https://github.com/QiShare/QiNotification

遇到问题:

1、icon图标右上角红点数量:

 1     NSInteger badgeInt = 1//红点数字。<0不显示
 2     //请求标识符,同一个标识符新推送会覆盖老的
 3     NSString *requestIdentifer=@"标识";
 4     BOOL repeatBool = NO;//YES
 5     if (@available(iOS 10.0, *)) {
 6         UNMutableNotificationContent *content = [[UNMutableNotificationContent alloc] init];
 7         //[content setValue:@(YES) forKeyPath:@"shouldAlwaysAlertWhileAppIsForeground"];        
 8         content.title = title;
 9         content.subtitle = subTitle;
10         content.body = body;
11         content.badge = @(badgeInt);
12         content.sound = [UNNotificationSound defaultSound];
13         //触发
14         UNCalendarNotificationTrigger *trigger = [UNCalendarNotificationTrigger triggerWithDateMatchingComponents:components repeats:repeatBool];
15         UNNotificationRequest *request = [UNNotificationRequest requestWithIdentifier:requestIdentifer content:content trigger:trigger];
16         [[UNUserNotificationCenter currentNotificationCenter] addNotificationRequest:request withCompletionHandler:^(NSError * _Nullable error) {
17         }];
18 
19     } else {    
20         NSCalendar * calendar = [NSCalendar currentCalendar];
21         NSDate * date = [calendar dateFromComponents:components];    
22         UILocalNotification *localNotification = [[UILocalNotification alloc] init];        
23         // 1.设置触发时间(如果要立即触发,无需设置)
24         localNotification.timeZone = [NSTimeZone defaultTimeZone];
25         localNotification.fireDate = date;        
26         // 2.设置通知标题
27         localNotification.alertBody = title;        
28         // 3.设置通知动作按钮的标题
29         localNotification.alertAction = @"查看";        
30         // 4.设置提醒的声音
31         localNotification.soundName = UILocalNotificationDefaultSoundName;        
32         // 5.设置通知的 传递的userInfo
33         //localNotification.userInfo = userInfo;        
34         //6.设置每天重复
35         localNotification.repeatInterval = NSCalendarUnitDay;        
36         localNotification.applicationIconBadgeNumber = badgeInt;        
37         // 6.在规定的日期触发通知
38         [[UIApplication sharedApplication] scheduleLocalNotification:localNotification];
39         // 6.立即触发一个通知
40         //[[UIApplication sharedApplication] presentLocalNotificationNow:localNotification];
41     }

2、ios本地推送的红点数字在badge设置固定值,不会根据实际显示推送数量+1。推送设定后会传给系统的推送机制,推送执行时候只有游戏在前台游戏会获得回调。

3、有一个有意思的问题。如果你app上现在有红点数字这个时候卸载再安装会发现红点数字还会显示,即使这个时候你app并没有登陆。不过如果卸载超过一天再安装红点数量不会显示

原文地址:https://www.cnblogs.com/wangle/p/13050172.html