我目前有一个iOS项目,但未显示推送通知操作。这是我正在测试的有效载荷主体:
$body['aps'] = array(
'alert' => $message,
'sound' => 'default',
'link_url' => $url,
'category' => 'NEWS_CATEGORY',
);
这是App委托中的registerForPushNotifications:
func registerForPushNotifications(application: UIApplication) {
//allows notification actions by setting catagories
let viewAction = UIMutableUserNotificationAction()
viewAction.identifier = "VIEW_IDENTIFIER"
viewAction.title = "View"
viewAction.activationMode = .Foreground
let newsCategory = UIMutableUserNotificationCategory()
newsCategory.identifier = "NEWS_CATEGORY"
newsCategory.setActions([viewAction], forContext: .Default)
let notificationSettings = UIUserNotificationSettings(forTypes: [.Badge, .Sound, .Alert], categories: [newsCategory])
}
我们非常感谢您对为何未显示通知操作的任何帮助!
最佳答案
似乎忘记了向应用程序实际添加注册设置。加
application.registerUserNotificationSettings(notificationSettings)
let notificationSettings = UIUserNotificationSettings(forTypes: [.Badge, .Sound, .Alert], categories: [newsCategory])
之后关于ios - 推送通知操作未在Swift中显示?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/37800281/