我正在尝试向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];
}];
}
我正在推送标题和正文“hello”,但推送通知上没有按钮或动作。
我已阅读本指南https://nrj.io/simple-interactive-notifications-in-ios-8/
答案 0 :(得分:1)