我遵循了很多关于交互式通知的教程,我不知道我的代码中缺少什么。我可以收到一个简单的推送通知,我知道我必须滑动才能显示按钮。 我在 iOS 9.2.1 上有 iPhone 4S ,我使用 Mixpanel 发送通知。 我也尝试了本地通知,但它也没有用。 (模拟器8.4,9.2,iPhone 4S)我收到了消息但没有按钮。
有效负载: { "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()
}