本地消息推送(基于iOS10 UserNotifications框架):2-UNNotificationContent类
UNNotificationContent类定义了消息推送所携带的消息体内容,即每一类的推送消息所携带的信息都被封装在UNNotificationContent类中,包括我们经常使用的title、body以及一些附加信息等。
UNNotificationContent类常用属性和方法
UNNotificationContent类中封装了消息推送的信息,常用的有如下一些属性。
- body:推送消息消息体内容,如下图所示
@property (NS_NONATOMIC_IOSONLY, readonly, copy) NSString *body;
- title:推送消息的主标题,如下图所示
@property (NS_NONATOMIC_IOSONLY, readonly, copy) NSString *title;
- subtitle:推送消息的子标题内容,如下图所示
@property (NS_NONATOMIC_IOSONLY, readonly, copy) NSString *subtitle;
- userInfo: 一个字典,可以用于在推送消息中携带信息,信息在该字典中以键值对的形式进行存储
@property (NS_NONATOMIC_IOSONLY, readonly, copy) NSDictionary *userInfo;
- sound: 推送消息的提醒声音类型
@property (NS_NONATOMIC_IOSONLY, readonly, copy, nullable) UNNotificationSound *sound;
- launchImageName:当用户通过推送消息打开App时,显示该启动图片
@property (NS_NONATOMIC_IOSONLY, readonly, copy) NSString *launchImageName;
- categoryIdentifier:已注册的UNNotificationCategory类的标示符,UNNotificationCategory类的对象可以用于在推送消息中添加一些操作
@property (NS_NONATOMIC_IOSONLY, readonly, copy) NSString *categoryIdentifier;
- badge:badge数量
@property (NS_NONATOMIC_IOSONLY, readonly, copy, nullable) NSNumber *badge;
- attachments:推送消息中可以携带的可选附件
@property (NS_NONATOMIC_IOSONLY, readonly, copy) NSArray <UNNotificationAttachment *> *attachments;
UNMutableNotificationContent类
UNMutableNotificationContent类是UNNotificationContent类的子类。UNNotificationContent是一个不可变类,我们不能够对其属性进行修改。而UNMutableNotificationContent类是可变类,当我们需要设置消息体的内容时,需要创建UNMutableNotificationContent类的对象。
@interface UNMutableNotificationContent : UNNotificationContent
UNNotificationContent类的属性都是readonly的,而UNMutableNotificationContent类中也包含同样的属性,但都是可写的。
@property (NS_NONATOMIC_IOSONLY, copy) NSArray <UNNotificationAttachment *> *attachments;
@property (NS_NONATOMIC_IOSONLY, copy, nullable) NSNumber *badge;
@property (NS_NONATOMIC_IOSONLY, copy) NSString *body;
@property (NS_NONATOMIC_IOSONLY, copy) NSString *categoryIdentifier;
@property (NS_NONATOMIC_IOSONLY, copy) NSString *launchImageName;
@property (NS_NONATOMIC_IOSONLY, copy, nullable) UNNotificationSound *sound;
@property (NS_NONATOMIC_IOSONLY, copy) NSString *subtitle;
@property (NS_NONATOMIC_IOSONLY, copy) NSString *threadIdentifier;
@property (NS_NONATOMIC_IOSONLY, copy) NSString *title;
@property (NS_NONATOMIC_IOSONLY, copy) NSDictionary *userInfo;
文章发布时间为: November 21st , 2016 at 04:07 pm
最后编辑时间为: September 22nd , 2017 at 01:18 am
本文由 99ios 创作,转载请注明出处
最后编辑时间为: September 22nd , 2017 at 01:18 am
本文由 99ios 创作,转载请注明出处