I followed many tutorials about interactive notifications and I don't know what is missing in my code. I can receive a simple push notification and I know that I have to swipe to make the buttons appear. I have an iPhone 4S on iOS 9.2.1 and I use Mixpanel to send a notification. I also tried local notification but it's not working either. (simulator 8.4, 9.2, iPhone 4S) I've got the message but no buttons.
Payload : { "aps" : { "category" : "RATING_CATEGORY", "alert" : "rate the app" }}
AppDelegate:
func registerForNotifications() {
if #available(iOS 8.0, *) {
let notificationActionRate :UIMutableUserNotificationAction = UIMutableUserNotificationAction()
notificationActionRate.identifier = "RATE_IDENTIFIER"
notificationActionRate.title = NSLocalizedString("Rate.Button.Title", comment: "Rate the app")
notificationActionRate.destructive = false
notificationActionRate.authenticationRequired = false
notificationActionRate.activationMode = UIUserNotificationActivationMode.Background
let notificationActionNotNow :UIMutableUserNotificationAction = UIMutableUserNotificationAction()
notificationActionNotNow.identifier = "NOT_NOW_IDENTIFIER"
notificationActionNotNow.title = NSLocalizedString("NotNow.Button.Title", comment: "Not now")
notificationActionNotNow.destructive = true
notificationActionNotNow.authenticationRequired = false
notificationActionNotNow.activationMode = UIUserNotificationActivationMode.Background
let notificationCategoryRating: UIMutableUserNotificationCategory = UIMutableUserNotificationCategory()
notificationCategoryRating.identifier = "RATING_CATEGORY"
notificationCategoryRating.setActions([notificationActionRate, notificationActionNotNow], forContext: UIUserNotificationActionContext.Default)
notificationCategoryRating.setActions([notificationActionRate, notificationActionNotNow], forContext: UIUserNotificationActionContext.Minimal)
let categories = Set([notificationCategoryRating])
UIApplication.sharedApplication().registerUserNotificationSettings(UIUserNotificationSettings(forTypes: [.Sound, .Alert, .Badge], categories: categories))
UIApplication.sharedApplication().registerForRemoteNotifications()
} else {
UIApplication.sharedApplication().registerForRemoteNotificationTypes([.NewsstandContentAvailability, .Badge,.Sound,.Alert])
}
}
func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
registerForNotifications()
return true
}
func application(application: UIApplication, handleActionWithIdentifier identifier: String?, forRemoteNotification userInfo: [NSObject : AnyObject], completionHandler: () -> Void) {
if identifier == "RATE_IDENTIFIER" {
let itunesLink = NSURL(string: "http://google.com")
UIApplication.sharedApplication().openURL(itunesLink!)
}
completionHandler()
}