最近在做一个项目,需要大量的本地推送,本地推送有一个坑,就是iOS系统限制了注册本地推送的数量,最大的注册量为64条,没有那么多的容量供我们挥霍。网上相关的文章比较少提到推送数量限制。
不说废话,请看代码
AppDelegate.m
#import "AppDelegate.h"
@interface AppDelegate ()
@end
@implementation AppDelegate
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
//注册本地通知
[self registerLocalNotification];
return YES;
}
- (void)registerLocalNotification{
/**
*iOS 8之后需要向系统注册通知,让用户开放权限
*/
if (CurrenVersiongreaterThan(@"8.0")) {
if ([[UIApplication sharedApplication] respondsToSelector:@selector(registerUserNotificationSettings:)]) {
UIUserNotificationSettings *settings = [UIUserNotificationSettings settingsForTypes:UIUserNotificationTypeBadge|UIUserNotificationTypeSound|UIUserNotificationTypeAlert categories:nil];
[[UIApplication sharedApplication] registerUserNotificationSettings:settings];
}
}
}
- (void)application:(UIApplication *)application didReceiveLocalNotification:(UILocalNotification *)notification{
UIApplicationState state = application.applicationState;
if (state == UIApplicationStateActive) {
if (CurrenVersiongreaterThan(@"9.0")) {
UIAlertController * alert = [UIAlertController alertControllerWithTitle:@"警告" message:notification.alertBody preferredStyle:UIAlertControllerStyleAlert];
UIAlertAction *okAction = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:nil];
[alert addAction:okAction];
[self.window.rootViewController presentViewController:alert animated: