效果如下面图示:

四、通知音效类UNNotificationSound
通知可以进行自定义的音效设置,其中方法如下:
//系统默认的音效
+ (instancetype)defaultSound;
//自定义的音频音效
/*
注意,音频文件必须在bundle中或者在Library/Sounds目录下
*/
+ (instancetype)soundNamed:(NSString *)name __WATCHOS_PROHIBITED;
五、通知触发器UNNotificationTrigger
通知触发器可以理解为定义通知的发送时间,UNNotificationTrigger是触发器的基类,具体的触发器由它的四个子类实现,实际上,开发者在代码中可能会用到的触发器只有三种,UNPushNotificationTrigger远程推送触发器开发者不需要创建使用,远程通知有远程服务器触发,开发者只需要创建与本地通知有关的触发器进行使用。
1.UNTimeIntervalNotificationTrigger
UNTimeIntervalNotificationTrigger是计时触发器,开发者可以设置其在添加通知请求后一定时间发送。
//创建触发器 在timeInterval秒后触发 可以设置是否循环触发
+ (instancetype)triggerWithTimeInterval:(NSTimeInterval)timeInterval repeats:(BOOL)repeats;
//获取下次触发的时间点
- (nullable NSDate *)nextTriggerDate;
2.UNCalendarNotificationTrigger
UNCalendarNotificationTrigger是日历触发器,开发者可以设置其在某个时间点触发。
//创建触发器 设置触发时间 可以设置是否循环触发
+ (instancetype)triggerWithDateMatchingComponents:(NSDateComponents *)dateComponents repeats:(BOOL)repeats;
//下一次触发的时间点
- (nullable NSDate *)nextTriggerDate;
3.UNLocationNotificationTrigger
UNLocationNotificationTrigger是地域触发器,开发者可以设置当用户进入某一区域时触发。
//地域信息
@property (NS_NONATOMIC_IOSONLY, readonly, copy) CLRegion *region;
//创建触发器
+ (instancetype)triggerWithRegion:(CLRegion *)region repeats:(BOOL)repeats __WATCHOS_PROHIBITED;
六、为通知内容添加附件
附件主要指的是媒体附件,例如图片,音频和视频,为通知内容添加附件需要使用UNNotificationAttachment类。示例代码如下:










