Push notification ios8自定义交互式推送通知
我正在尝试查找更新的文档,其中包含新交互式推送通知中的任何信息/代码示例。我在本地和远程推送通知上找到的指南仍然显示有效负载大小为256字节。我的理解是,在ios8中,该限制已提高到2k 我还试图找到有关如何添加自定义按钮以使我的通知具有交互性的文档。我在推送通知编程指南中没有看到太多内容Push notification ios8自定义交互式推送通知,push-notification,customization,ios8,Push Notification,Customization,Ios8,我正在尝试查找更新的文档,其中包含新交互式推送通知中的任何信息/代码示例。我在本地和远程推送通知上找到的指南仍然显示有效负载大小为256字节。我的理解是,在ios8中,该限制已提高到2k 我还试图找到有关如何添加自定义按钮以使我的通知具有交互性的文档。我在推送通知编程指南中没有看到太多内容 如何设置类别以添加带有颜色的自定义按钮?关于这方面的任何文档都会很有用。这是我在youtube上找到的自定义动作推送通知的教程。这是用swift完成的 您可以通过在iOS8中定义操作按钮来创建交互式通知 创建
如何设置类别以添加带有颜色的自定义按钮?关于这方面的任何文档都会很有用。这是我在youtube上找到的自定义动作推送通知的教程。这是用swift完成的
您可以通过在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"] ){
}
}
您可以查看此链接以了解更多信息。请参阅此链接