【问题标题】:ios8 customizing interactive push notificationsios8自定义交互式推送通知
【发布时间】:2014-07-31 17:12:41
【问题描述】:

我正在尝试查找更新的文档,其中包含有关新交互式推送通知的任何信息/代码示例。我在本地和远程推送通知上找到的指南仍然显示有效负载大小为 256 字节。我的理解是,在 ios8 中,该限制已提高到 2k。

我还在尝试查找有关如何添加自定义按钮以使我的通知具有交互性的文档。我在推送通知编程指南中没有看到太多内容。

如何设置类别以添加带有颜色的自定义按钮?任何有关这方面的文档都会很有用。

【问题讨论】:

标签: push-notification customization ios8


【解决方案1】:

您可以通过在 iOS8 中定义操作按钮来创建交互式通知。

  1. 创建UIMutableUserNotificationAction 按钮。
  2. 然后创建UIMutableUserNotificationCategory 并将上述操作分组到类别中。
  3. 将所有类别添加到集合中。
  4. 使用此类别集创建UIUserNotificationSettings
  5. 使用此设置注册通知
  6. 在推送负载中添加category字段并发送通知

请在下面找到示例代码:

- (void) registerRemoteNotificationWithActions{

    //1. Create action buttons..:)

    UIMutableUserNotificationAction *shareAction = [[UIMutableUserNotificationAction alloc] init];
    shareAction.identifier = @"SHARE_IDENTIFIER";
    shareAction.title = @"Share";
    shareAction.activationMode = UIUserNotificationActivationModeForeground;
    shareAction.destructive = NO;
    shareAction.authenticationRequired = YES;

    //2. Then create the category to group actions.:)

    UIMutableUserNotificationCategory *shareCategory = [[UIMutableUserNotificationCategory alloc] init];
    shareCategory.identifier = @"SHARE_CATEGORY";
    [shareCategory setActions:@[shareAction] forContext:UIUserNotificationActionContextDefault];
    [shareCategory setActions:@[shareAction] forContext:UIUserNotificationActionContextMinimal];

    //3. Then add categories into one set..:)
    NSSet *categories = [NSSet setWithObjects:shareCategory, nil];

    //4. Finally register remote notification with this action categories..:)
    UIUserNotificationSettings* notificationSettings = [UIUserNotificationSettings settingsForTypes:UIUserNotificationTypeAlert | UIUserNotificationTypeBadge | UIUserNotificationTypeSound categories:categories];
    [[UIApplication sharedApplication] registerUserNotificationSettings:notificationSettings];

}

样本负载格式:

{
    "aps": {
         "badge": 1,
         "alert": "Hello world!",
         “category”: “SHARE_CATEGORY”
          }
}

并使用以下方法处理操作:

- (void)application:(UIApplication *)application handleActionWithIdentifier:(NSString *)identifier forRemoteNotification:(NSDictionary *)userInfo completionHandler:(void(^)())completionHandler
{
        if ([identifier isEqualToString:@"SHARE_IDENTIFIER"] ){

        }
}

您可以查看此link 了解更多信息。

【讨论】:

    【解决方案2】:

    这是我在 youtube 上找到的自定义操作推送通知教程。它是迅速完成的。

    https://www.youtube.com/watch?v=Yh3lLpV1k_Y

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-04-10
      • 1970-01-01
      • 1970-01-01
      • 2015-03-02
      • 1970-01-01
      • 2013-03-27
      • 1970-01-01
      • 2014-11-13
      相关资源
      最近更新 更多