推送未在Swift中显示的通知操作?

时间:2016-06-13 22:42:02

标签: ios swift push-notification

我目前有一个iOS项目,但推送通知操作没有显示。以下是我负责测试的有效负载体:

$body['aps'] = array(
  'alert' => $message,
  'sound' => 'default',
  'link_url' => $url,
  'category' => 'NEWS_CATEGORY',
  );

以下是App Delegate中的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])
  }

非常感谢有关通知操作未显示原因的任何帮助!

1 个答案:

答案 0 :(得分:1)

似乎忘了向应用程序添加实际的注册设置。添加

application.registerUserNotificationSettings(notificationSettings)

let notificationSettings = UIUserNotificationSettings(forTypes: [.Badge, .Sound, .Alert], categories: [newsCategory])之后