3

我遵循了许多有关交互式通知的教程,但我不知道我的代码中缺少什么。我可以收到一个简单的推送通知,并且我知道我必须滑动才能显示按钮。我在iOS 9.2.1上有一部iPhone 4S,我使用Mixpanel发送通知。我也尝试了本地通知,但它也不起作用。(模拟器 8.4、9.2、iPhone 4S)我收到了消息,但没有按钮。

有效载荷: { "aps" : { "category" : "RATING_CATEGORY", "alert" : "rate the app" }}

应用委托:

    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()
}
4

0 回答 0