在iOS之前,我们这样使用本地通知
- (void)viewDidLoad {
[super viewDidLoad];
UIUserNotificationSettings *setting = [UIUserNotificationSettings settingsForTypes:UIUserNotificationTypeBadge | UIUserNotificationTypeAlert | UIUserNotificationTypeSound categories:nil];
[[UIApplication sharedApplication]registerUserNotificationSettings:setting];
}
- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event
{
UILocalNotification *notification = [UILocalNotification new];
notification.alertTitle = @"测试";
notification.timeZone = [NSTimeZone defaultTimeZone];
notification.fireDate = [NSDate dateWithTimeIntervalSinceNow:3];
notification.soundName = UILocalNotificationDefaultSoundName;
notification.alertBody = @"推送内容";
notification.applicationIconBadgeNumber = 1;
[[UIApplication sharedApplication] scheduleLocalNotification:notification];
}
在iOS10开始,这些方法都给出了警告,出现了新的方法替代了这些方法

使用通知时候我们需要加入新的框架
#import <UserNotifications/UserNotifications.h>
- (void)viewDidLoad {
[super viewDidLoad];
UIUserNotificationSettings *setting = [UIUserNotificationSettings settingsForTypes:UIUserNotificationTypeBadge | UIUserNotificationTypeAlert | UIUserNotificationTypeSound categories:nil];
[[UIApplication sharedApplication]registerUserNotificationSettings:setting];
}
- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event
{
UNMutableNotificationContent *content = [UNMutableNotificationContent new];
content.badge = @10;
content.sound = [UNNotificationSound defaultSound];
content.title = @"测试";
content.subtitle = @"小标题";
content.body = @"推送内容";
UNTimeIntervalNotificationTrigger *trigger = [UNTimeIntervalNotificationTrigger triggerWithTimeInterval:3 repeats:NO];
UNNotificationRequest *request = [UNNotificationRequest requestWithIdentifier:@"identifer" content:content trigger:trigger];
[[UNUserNotificationCenter currentNotificationCenter] addNotificationRequest:request withCompletionHandler:^(NSError * _Nullable error) {
}];
}