设置通知内容
因为iOS10远程通知与本地通知统一起来了,通知内容属性是一致的,不过远程推送就需要在payload进行具体设置了,下面以本地通知为例,介绍关于UNNotificationContent的内容
官网上明确说明了,我们是不能直接创建UNNotificationContent的实例的, 如果我们需要自己去配置内容的各个属性,我们需要用到UNMutableNotificationContent
看一下它的一些属性:
attachments //附件
badge //徽标
body //推送内容body
categoryIdentifier //category标识
launchImageName //点击通知进入应用的启动图
sound //声音
subtitle //推送内容子标题
title //推送内容标题
userInfo //远程通知内容
UNMutableNotificationContent *content = [[UNMutableNotificationContent alloc] init];
content.title = @"Test";
content.subtitle = @"1234567890";
content.body = @"Copyright © 2016年 jpush. All rights reserved.";
content.badge = @1;
NSError *error = nil;
NSString *path = [[NSBundle mainBundle] pathForResource:@"718835727" ofType:@"png"];
UNNotificationAttachment *att = [UNNotificationAttachment attachmentWithIdentifier:@"att1" URL:[NSURL fileURLWithPath:path] options:nil error:&error];
if (error) {
NSLog(@"attachment error %@", error);
}
content.attachments = @[att];
content.categoryIdentifier = @"category1”; //这里设置category1, 是与之前设置的category对应
content.launchImageName = @"1-Eb_0OvtcxJXHZ7-IOoBsaQ";
UNNotificationSound *sound = [UNNotificationSound defaultSound];
content.sound = sound;

通知触发器
UNNotificationTrigger
iOS 10触发器有4种
•UNPushNotificationTrigger 触发APNS服务,系统自动设置(这是区分本地通知和远程通知的标识)
•UNTimeIntervalNotificationTrigger 一段时间后触发
•UNCalendarNotificationTrigger 指定日期触发
•UNLocationNotificationTrigger 根据位置触发,支持进入某地或者离开某地或者都有
//十秒后
UNTimeIntervalNotificationTrigger *trigger1 = [UNTimeIntervalNotificationTrigger triggerWithTimeInterval:10 repeats:NO];
//每周日早上8:00
NSDateComponents *component = [[NSDateComponents alloc] init];
component.weekday = 1;
component.hour = 8;
UNCalendarNotificationTrigger *trigger2 = [UNCalendarNotificationTrigger triggerWithDateMatchingComponents:component repeats:YES];
//圆形区域,进入时候进行通知
CLLocationCoordinate2D cen = CLLocationCoordinate2DMake(80.335400, -90.009201);
CLCircularRegion *region = [[CLCircularRegion alloc] initWithCenter:cen
radius:500.0 identifier:@“center"];
region.notifyOnEntry = YES; //进入的时候
region.notifyOnExit = NO; //出去的时候
UNLocationNotificationTrigger *trigger3 = [UNLocationNotificationTrigger
triggerWithRegion:region repeats:NO];










