iOS10富文本推送--NotificationContentExtension
来源:互联网 发布:生物信息学数据分析 编辑:程序博客网 时间:2024/06/06 03:06
NotificationContentExtension文件
根据以下ContentExtension Info.plist文件中的配置决定category的设置,两者必须一致
宏定义采用下列代码:
//推送相关设置#define Action_Category_Identifier_Image @"Image_Category" //图片类别标识符#define Action_Category_Identifier_Audio @"Audio_Category" //音频类别标识符#define Action_Category_Identifier_Movie @"Movie_Category" //视频类别标识符#define Action_Identifier_Image_Confirm @"imageConfirmAction" //图片确认按钮#define Action_Identifier_Image_Concel @"imageConcelAction" //图片取消按钮#define Action_Identifier_Audio_Confirm @"audioConfirmAction" //音频确认按钮#define Action_Identifier_Audio_Concel @"audioConcelAction" //音频取消按钮#define Action_Identifier_Movie_Confirm @"movieConfirmAction" //视频确认按钮#define Action_Identifier_Movie_Concel @"movieConcelAction" //视频取消按钮#define Action_Title_Image_Confirm @"查看" //图片确认按钮标题#define Action_Title_Image_Concel @"忽略" //图片取消按钮标题#define Action_Title_Audio_Confirm @"查看" //音频确认按钮标题#define Action_Title_Audio_Concel @"忽略" //音频取消按钮标题#define Action_Title_Movie_Confirm @"查看" //视频确认按钮标题#define Action_Title_Movie_Concel @"忽略" //视频取消按钮标题
采用的是自定义布局,注意如果想使用这个布局的话,
你必须提前在service里面设置好categoryIdentifier,它的值是你plist文件里面的任何一个
@interface NotificationViewController () <UNNotificationContentExtension>@property (nonatomic, strong)UIImageView *imageView;@property (nonatomic,strong)UILabel *label;@end
LazyLoad
-(UIImageView *)imageView{ if (_imageView == nil) { _imageView = [[UIImageView alloc] init]; _imageView.contentMode = UIViewContentModeScaleAspectFit; } return _imageView;}
AddView
- (void)viewDidLoad { [super viewDidLoad]; [self.view addSubview:self.imageView]; // Do any required interface initialization here.}
取出多媒体资料并展示到视图上,下面为image
- (void)didReceiveNotification:(UNNotification *)notification { NSLog(@"notification.request.content.userInfo%@",notification.request.content.userInfo); UNNotificationContent * content = notification.request.content; CGFloat widthTime = 2; if ([UIScreen mainScreen].bounds.size.width>375) { widthTime = 3.0; } UIImage *image = nil; if (content.attachments.count) { UNNotificationAttachment * attachment_img = content.attachments[0]; if (attachment_img.URL.startAccessingSecurityScopedResource) { image = [UIImage imageWithContentsOfFile:attachment_img.URL.path]; self.imageView.image = image; } } self.imageView.frame = self.view.frame; self.label.text = notification.request.content.body;}
响应相关Action
-(void)didReceiveNotificationResponse:(UNNotificationResponse *)response completionHandler:(void (^)(UNNotificationContentExtensionResponseOption))completion{ UNNotificationContent *content = [response.notification.request.content mutableCopy]; NSString *category = content.categoryIdentifier; NSString *actionIdentifier = [response.actionIdentifier copy]; if ([category isEqualToString:Action_Category_Identifier_Image]) { if ([actionIdentifier isEqualToString:Action_Identifier_Image_Confirm]) { completion(UNNotificationContentExtensionResponseOptionDismissAndForwardAction); }else{ completion(UNNotificationContentExtensionResponseOptionDismiss); } }else if ([category isEqualToString:Action_Category_Identifier_Audio]){ if ([actionIdentifier isEqualToString:Action_Identifier_Audio_Confirm]) { completion(UNNotificationContentExtensionResponseOptionDismissAndForwardAction); }else{ completion(UNNotificationContentExtensionResponseOptionDismiss); } }else{ if ([actionIdentifier isEqualToString:Action_Identifier_Movie_Confirm]) { completion(UNNotificationContentExtensionResponseOptionDismissAndForwardAction); }else{ completion(UNNotificationContentExtensionResponseOptionDismiss); } }}
阅读全文
0 0
- iOS10富文本推送--NotificationContentExtension
- iOS10富文本推送--UIMutableUserNotificationAction
- iOS10富文本推送--NotificationServiceExtension
- iOS10富文本推送--UNNotificationExtension--基础篇
- iOS10 推送
- 富文本
- 富文本
- 富文本
- 富文本
- 富文本
- 富文本
- 富文本
- 富文本
- iOS10 关于推送
- iOS10注册极光推送
- iOS10 推送最新配置
- iOS10 推送证书问题
- iOS10 本地推送机制
- XZ_iOS之崩溃信息的查看,调用堆栈的调试技巧
- 四种途径将HTML5 web应用变成android应用
- UILabel删除线不显示
- markdown语法
- day05 面向对象 如若有错还望指教
- iOS10富文本推送--NotificationContentExtension
- 大小不固定的图片和多行文字的垂直水平居中
- Codeforces Round #385 (Div. 2) 745A Hongcow Learns the Cyclic Shift
- 数据库分库分表(sharding)系列——全局主键生成策略(3)
- cookies,sessionStroage和localStorage的区别
- 欢迎使用CSDN-markdown编辑器
- Android线程池解析
- Java中的基本类型和引用类型变量的区别
- linux 下PS1自定义提示符