1

I'm following this tutorial for generating notifications. As it showed, the custom buttons are visible for local notifications. But when I tried same for remote, it didn't work.

Here's my code to set category to the notification:

func registerActions() {
    var notificationActionOk :UIMutableUserNotificationAction = UIMutableUserNotificationAction()
    notificationActionOk.identifier = "ACCEPT_IDENTIFIER"
    notificationActionOk.title = "Ok"
    notificationActionOk.isDestructive = false
    notificationActionOk.isAuthenticationRequired = false
    notificationActionOk.activationMode = UIUserNotificationActivationMode.background

    var notificationActionCancel :UIMutableUserNotificationAction = UIMutableUserNotificationAction()
    notificationActionCancel.identifier = "NOT_NOW_IDENTIFIER"
    notificationActionCancel.title = "Not Now"
    notificationActionCancel.isDestructive = true
    notificationActionCancel.isAuthenticationRequired = false
    notificationActionCancel.activationMode = UIUserNotificationActivationMode.background

    var notificationCategory:UIMutableUserNotificationCategory = UIMutableUserNotificationCategory()
    notificationCategory.identifier = "INVITE_CATEGORY"
    notificationCategory .setActions([notificationActionOk,notificationActionCancel], for: UIUserNotificationActionContext.default)
    notificationCategory .setActions([notificationActionOk,notificationActionCancel], for: UIUserNotificationActionContext.minimal)

    UIApplication.shared.registerUserNotificationSettings(UIUserNotificationSettings(types: UIUserNotificationType(rawValue: UIUserNotificationType.sound.rawValue | UIUserNotificationType.alert.rawValue |
        UIUserNotificationType.badge.rawValue), categories: NSSet(array:[notificationCategory]) as! Set<UIUserNotificationCategory>
    ))

//        fireLocalNotification()
}

Here's my payload added with the same category.

{"to": "cMGOnedo5M4:APA91bEQgj1Dt5IWsqgdq2QQmGBv-zAxH4qsWRApkeAA5fvxCZPKQACkok_sWC3v2mwT3SnFrK_08qgmy9bcac0PxSJkSWhJMKbWPnBzHWBnv2yKPY-FjSynLgGYTiK7bl5LejcaVQbr", 
"notification" : 
    {"body" : "   ","title": "You have received a message from jia ron","badge": "1" },
"data" : 
    {"OriginalFileName":null,"FilePath":"https:Chat//3458/","ChatID":3826,"From":3458,"To":3440,"Message":null,"SendDate":"2019-07-03T00:00:00","ServerDate":"","ModifyDate":"","SendType":"TEXT","IsDelete":false,"IsRead":false,"SendByMe":0,"Type":"OfflineChat","message":null,"UserID":"3458","DisplayName":"jia ron","MessageType":"TEXT","IsGroup":0,"GroupID":0,"FileName":null,"UnreadMessage":3},
"aps" :
  {"category" : "INVITE_CATEGORY"}
}

Here's the code to fire local notification.

func fireLocalNotification() {
    var localNotification:UILocalNotification = UILocalNotification()
    localNotification.alertAction = "Testing notifications on iOS8"
    localNotification.alertBody = "Woww it works!!"
    localNotification.fireDate = NSDate(timeIntervalSinceNow: 30) as Date
    localNotification.category = "INVITE_CATEGORY";
    UIApplication.shared.scheduleLocalNotification(localNotification)
}

From local notification, I got two buttons on pull.

enter image description here

But didn't showed up on remote push.

enter image description here

Krutika Sonawala
  • 1,065
  • 1
  • 12
  • 30

1 Answers1

0

Please change your notification payload JSON as per below

{"to": "d8xNDuQIua8:APA91bF15SABFUBNDEYb2JJ4_LGlDZ94G3TMryWIo0SFKE1xyr9VThS6Ce-NofxXtIAw_yMr5jFwUcEzk-JxqpqkJ5OiOYzftcukyef1VcX4a7I25BagAytp48GVt1VJueY49K2cAKcA",
     "notification": {
         "text": "YOUR_PUSH_TEXT",
         "click_action":"INVITE_CATEGORY"
     }
}
Parth Patel
  • 915
  • 11
  • 33