设为首页 加入收藏

TOP

iOS10--消息通知的基本使用(三)
2019-08-26 07:00:27 】 浏览:79
Tags:iOS10-- 消息 通知 基本 使用
DismissAction]; NSSet
*setting = [NSSet setWithObjects:category, nil]; [center setNotificationCategories:setting];

 

  • 在创建 UNNotificationContent 时把 categoryIdentifier 设置为需要的 category id 即可:
    content.categoryIdentifier = @"my_category";

    远程推送也可以使用 category,只需要在 payload 中添加 category 字段,并指定预先定义的 category id 就可以了

  • 处理category的通知:
    - (void)userNotificationCenter:(UNUserNotificationCenter *)center didReceiveNotificationResponse:(UNNotificationResponse *)response withCompletionHandler:(void (^)())completionHandler{
     
    completionHandler();
     
    NSLog(@"userInfo--%@",response.notification.request.content.userInfo);
     
    // 获取通知中心的所有的Categories
     
    [center getNotificationCategoriesWithCompletionHandler:^(NSSet<UNNotificationCategory *> * _Nonnull categories) {
     
    for (UNNotificationCategory *category in categories) {
     
    if ([category.identifier isEqualToString:@"my_category"] && [response.notification.request.content.categoryIdentifier isEqualToString:@"my_category"]) {
     
    for (UNNotificationAction *textAction in category.actions) {
     
    if ([textAction.identifier isEqualToString:@"my_text"]) {
     
    UNTextInputNotificationAction *text = (UNTextInputNotificationAction *)textAction;
     
    UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"提示" message:text.textInputButtonTitle preferredStyle:UIAlertControllerStyleAlert];
     
    [alert addAction:[UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleCancel handler:nil]];
     
    [[UIApplication sharedApplication].keyWindow.rootViewController presentViewController:alert animated:YES completion:nil];
     
    }
     
    }
     
    }
     
    }
     
    }];
     
    }
  •           
    长按 3D touch 效果图

              
    进入应用
    iOS 10 中被标为弃用的 API
    UILocalNotification
    UIMutableUserNotificationAction
    UIMutableUserNotificationCategory
    UIUserNotificationAction
    UIUserNotificationCategory
    UIUserNotificationSettings
    handleActionWithIdentifier:forLocalNotification:
    handleActionWithIdentifier:forRemoteNotification:
    didReceiveLocalNotification:withCompletion:
    didReceiveRemoteNotification:withCompletion:

     

    来源

    首页 上一页 1 2 3 下一页 尾页 3/3/3
    】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
    上一篇.gitignore中添加的某个忽略文件.. 下一篇iOS:WKWebView(19-05-30更)

    最新文章

    热门文章

    Hot 文章

    Python

    C 语言

    C++基础

    大数据基础

    linux编程基础

    C/C++面试题目