iOS10富文本推送--UIMutableUserNotificationAction
来源:互联网 发布:sha1 js 时间 编辑:程序博客网 时间:2024/06/06 16:31
AppDelagate文件
添加action
根据以下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 @"忽略" //视频取消按钮标题
添加相应类别的aciton,一个类别必须对应一个category,
在下面这个方法里面执行,
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
//添加相应类别的aciton,一个类别必须对应一个category- (void)addNotificationAction{ //Image_Category UIMutableUserNotificationAction *imageConfirmAction = [self creatNotificationActionIdentifier:Action_Identifier_Image_Confirm title:Action_Title_Image_Confirm activationMode:UIUserNotificationActivationModeForeground]; imageConfirmAction.authenticationRequired = YES; imageConfirmAction.destructive = YES; UIMutableUserNotificationAction *imageConcelAction = [self creatNotificationActionIdentifier:Action_Identifier_Image_Concel title:Action_Title_Image_Concel activationMode:UIUserNotificationActivationModeBackground]; UIMutableUserNotificationCategory *ImageCategory = [self creatNotificationCategoryIdentifier:Action_Category_Identifier_Image setActions:@[imageConfirmAction,imageConcelAction] forContext:UIUserNotificationActionContextDefault]; //Audio_Category UIMutableUserNotificationAction *audioConfirmAction = [self creatNotificationActionIdentifier:Action_Identifier_Audio_Confirm title:Action_Title_Audio_Confirm activationMode:UIUserNotificationActivationModeForeground]; audioConfirmAction.authenticationRequired = YES; audioConfirmAction.destructive = YES; UIMutableUserNotificationAction *audioConcelAction = [self creatNotificationActionIdentifier:Action_Identifier_Audio_Concel title:Action_Title_Audio_Concel activationMode:UIUserNotificationActivationModeBackground]; UIMutableUserNotificationCategory *audioCategory = [self creatNotificationCategoryIdentifier:Action_Category_Identifier_Audio setActions:@[audioConfirmAction,audioConcelAction] forContext:UIUserNotificationActionContextDefault]; //Movie_Category UIMutableUserNotificationAction *movieConfirmAction = [self creatNotificationActionIdentifier:Action_Identifier_Movie_Confirm title:Action_Title_Movie_Confirm activationMode:UIUserNotificationActivationModeForeground]; movieConfirmAction.authenticationRequired = YES; movieConfirmAction.destructive = YES; UIMutableUserNotificationAction *movieConcelAction = [self creatNotificationActionIdentifier:Action_Identifier_Movie_Concel title:Action_Title_Movie_Concel activationMode:UIUserNotificationActivationModeBackground]; UIMutableUserNotificationCategory *movieCategory = [self creatNotificationCategoryIdentifier:Action_Category_Identifier_Movie setActions:@[movieConfirmAction,movieConcelAction] forContext:UIUserNotificationActionContextDefault]; NSSet *categories = [NSSet setWithObjects:ImageCategory,audioCategory,movieCategory,nil]; UIUserNotificationType types = (UIUserNotificationTypeAlert| UIUserNotificationTypeSound| UIUserNotificationTypeBadge); UIUserNotificationSettings *settings; settings = [UIUserNotificationSettings settingsForTypes:types categories:categories]; [[UIApplication sharedApplication] registerUserNotificationSettings:settings]; }
创建一个category
//创建一个category- (UIMutableUserNotificationCategory*)creatNotificationCategoryIdentifier:(NSString *)identifier setActions:(nullable NSArray<UIUserNotificationAction *> *)actions forContext:(UIUserNotificationActionContext)context{ UIMutableUserNotificationCategory *category = [[UIMutableUserNotificationCategory alloc] init]; category.identifier = identifier;//这组动作的唯一标示 [category setActions:actions forContext:context]; return category;}
创建一个action
//创建一个action-(UIMutableUserNotificationAction *)creatNotificationActionIdentifier:(NSString *)identifier title:(NSString *)title activationMode:(UIUserNotificationActivationMode)activationMode{ UIMutableUserNotificationAction *action = [[UIMutableUserNotificationAction alloc] init]; action.identifier = identifier; action.title = title; action.activationMode = activationMode; return action;}
阅读全文
0 0
- iOS10富文本推送--UIMutableUserNotificationAction
- iOS10富文本推送--NotificationServiceExtension
- iOS10富文本推送--NotificationContentExtension
- iOS10富文本推送--UNNotificationExtension--基础篇
- iOS10 推送
- 富文本
- 富文本
- 富文本
- 富文本
- 富文本
- 富文本
- 富文本
- 富文本
- iOS10 关于推送
- iOS10注册极光推送
- iOS10 推送最新配置
- iOS10 推送证书问题
- iOS10 本地推送机制
- Shell系列—Shell 函数
- Windows字符集:string转为CString、char* 转为CString、CString转为char*
- 《MySQL必知必会》学习心得 7/18
- Ubuntu16下libfreenect2连接两个Kinect V2出现的错误记录
- Eclipse R语言插件 statET 安装
- iOS10富文本推送--UIMutableUserNotificationAction
- Android启动一个新的activity并携带数据,返回数据给上一个activity
- Android中checkbox控件的自定义样式设置
- 防止头文件的重复包含
- BZOJ 2049 Cave 洞穴勘测 [LCT]
- PHP与 RESTful风格的swagger结合生成API
- 当你完不成自己的程序时,就不要睡觉......
- mybatis进阶(5)--多对多查询
- centos7.2 安装hdp2.6.1.0