gpt4 book ai didi

push-notification - ios8 自定义交互式推送通知

转载 作者:行者123 更新时间:2023-12-01 00:59:11 24 4
gpt4 key购买 nike

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

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

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

最佳答案

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

  • 创建 UIMutableUserNotificationAction纽扣。
  • 然后创建 UIMutableUserNotificationCategory并将上述操作分组。
  • 将所有类别添加到集合中。
  • 创建 UIUserNotificationSettings与此类别集。
  • 使用此设置注册通知
  • 添加 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了解更多信息。

    关于push-notification - ios8 自定义交互式推送通知,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25065073/

    24 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com