gpt4 book ai didi

iOS - 向远程通知添加操作。我错过了什么?

转载 作者:行者123 更新时间:2023-11-29 11:50:08 24 4
gpt4 key购买 nike

我正在尝试向 iOS 远程通知添加一个操作。

这是我发送到休斯顿的命令 (https://github.com/nomad/houston)

apn push "APNS_TOKEN_HERE" -c /Users/johannwerner/Desktop/apple_push_notification.pem -P '{"aps":{"alert":{"action-loc-key":"OK","title":"hello","body":"Hello"},"category":"ACTIONABLE"}}' 

当应用程序从推送通知启动并且我从 didFinishWithOptions 方法记录 launchOptions 时,我得到以下内容

{
UIApplicationLaunchOptionsRemoteNotificationKey = {
aps = {
alert = {
"action-loc-key" = OK;
body = Hello;
title = hello;
};
category = ACTIONABLE;
};
};
}

当我在代码中注册通知时,我使用以下内容。

if (NSClassFromString(@"UNUserNotificationCenter")) {

UNNotificationAction* snoozeAction = [UNNotificationAction
actionWithIdentifier:@"SNOOZE_ACTION"
title:@"Snooze"
options:UNNotificationActionOptionNone];

UNNotificationCategory* generalCategory = [UNNotificationCategory
categoryWithIdentifier:@"GENERAL"
actions:@[snoozeAction]
intentIdentifiers:@[@"ACTIONABLE"]
options:UNNotificationCategoryOptionCustomDismissAction];



UNAuthorizationOptions options = (UNAuthorizationOptionBadge | UNAuthorizationOptionSound |UNAuthorizationOptionAlert);
UNUserNotificationCenter *center = [UNUserNotificationCenter currentNotificationCenter];

[center setNotificationCategories:[NSSet setWithObjects:generalCategory, nil]];

center.delegate = self;
[center requestAuthorizationWithOptions:options completionHandler:^(BOOL granted, NSError * _Nullable error)
{
if( !error ){
[Localytics didRequestUserNotificationAuthorizationWithOptions:options
granted:granted];
[[UIApplication sharedApplication] registerForRemoteNotifications];
}

[[NSNotificationCenter defaultCenter] postNotificationName:PUSH_DELEGATE_AFTER_REGISTERED object: nil];
}];
}

我收到一个标题和正文为“你好”的推送,但推送通知上没有按钮或操作。

我已经阅读了本指南 https://nrj.io/simple-interactive-notifications-in-ios-8/

以及苹果文档 https://developer.apple.com/library/content/documentation/NetworkingInternet/Conceptual/RemoteNotificationsPG/CreatingtheNotificationPayload.html#//apple_ref/doc/uid/TP40008194-CH10-SW1用于有效载荷

https://developer.apple.com/library/content/documentation/NetworkingInternet/Conceptual/RemoteNotificationsPG/SupportingNotificationsinYourApp.html用于向通知添加操作。

最佳答案

终于找到了。在我的有效载荷中,我将类别作为字符串“可操作”发送。它应该是“一般”

关于iOS - 向远程通知添加操作。我错过了什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41484891/

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