Watchos 2 Beta 5未显示动态通知,仅加载静态通知界面

时间:2015-09-02 07:14:59

标签: apple-push-notifications watchkit apple-watch

我已经创建了苹果手表应用程序以显示推送通知。所以我创建了不同类别的动态通知界面。但它没有显示动态界面但能够看到相应类别的动作按钮。请帮助我。请找到appdelegate推送通知注册方法

P.S:如果在带有效载荷的模拟器中运行,它工作正常。

 func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
        // Override point for customization after application launch.




        // Register for Push Notitications, if running iOS 8
        if application.respondsToSelector("registerUserNotificationSettings:") {

         self.registerSettingsAndCategories()

        } else {
            // Register for Push Notifications before iOS 8
            application.registerForRemoteNotifications()
        }


        return true
    }

  func registerSettingsAndCategories() {



            let alarmAction = UIMutableUserNotificationAction()
            alarmAction.title = NSLocalizedString("Activate Theft Alarm ", comment: "Activate Theft Alarm ")
            alarmAction.identifier = "theftAlarm"
            alarmAction.activationMode = UIUserNotificationActivationMode.Foreground
            alarmAction.authenticationRequired = false

            let callCopsAction = UIMutableUserNotificationAction()
            callCopsAction.title = NSLocalizedString("Call Near by cops", comment: "Call Near by cops")
            callCopsAction.identifier = "callCops"
            callCopsAction.activationMode = UIUserNotificationActivationMode.Foreground
            callCopsAction.authenticationRequired = false

            let callSecAction = UIMutableUserNotificationAction()
            callSecAction.title = NSLocalizedString("Call Parking Security ", comment: "Call Parking Security ")
            callSecAction.identifier = "callSecurity"
            callSecAction.activationMode = UIUserNotificationActivationMode.Foreground
            callSecAction.authenticationRequired = false

            let navigateToSpotAction = UIMutableUserNotificationAction()
            navigateToSpotAction.title = NSLocalizedString("Navigate to Spot", comment: "Navigate to Spot")
            navigateToSpotAction.identifier = "navigateToSpot"
            navigateToSpotAction.activationMode = UIUserNotificationActivationMode.Foreground
            navigateToSpotAction.authenticationRequired = false


            let bookappointmentAction = UIMutableUserNotificationAction()
            bookappointmentAction.title = NSLocalizedString("Book Appointment", comment: "Book Appointment")
            bookappointmentAction.identifier = "bookAppointment"
            bookappointmentAction.activationMode = UIUserNotificationActivationMode.Foreground
            bookappointmentAction.authenticationRequired = false






            let theftCategory = UIMutableUserNotificationCategory()
            theftCategory.setActions([alarmAction, callCopsAction,callSecAction],
                forContext: UIUserNotificationActionContext.Default)
            theftCategory.setActions([callCopsAction,callSecAction], forContext: UIUserNotificationActionContext.Minimal)
            theftCategory.identifier = "theftWarning"


            let accidentCategory = UIMutableUserNotificationCategory()
            accidentCategory.setActions([navigateToSpotAction], forContext: UIUserNotificationActionContext.Default)
            accidentCategory.setActions([navigateToSpotAction], forContext: UIUserNotificationActionContext.Minimal)
            accidentCategory.identifier = "accident"

            let lowOilCategory = UIMutableUserNotificationCategory()
            lowOilCategory.setActions([bookappointmentAction], forContext: UIUserNotificationActionContext.Default)
            lowOilCategory.setActions([bookappointmentAction], forContext: UIUserNotificationActionContext.Minimal)
            lowOilCategory.identifier = "lowOil"


            let categories : Set<UIUserNotificationCategory> = [theftCategory, accidentCategory, lowOilCategory]

            // Configure other actions and categories and add them to the set...


            let settings = UIUserNotificationSettings(forTypes: [.Alert, .Badge, .Sound], categories: categories)
            UIApplication.sharedApplication().registerUserNotificationSettings(settings)
            UIApplication.sharedApplication().registerForRemoteNotifications()


        }

1 个答案:

答案 0 :(得分:1)

您需要在WKUserNotificationInterfaceController的子类中实现didReceiveRemoteNotification:withCompletion:。

然后,执行completionHandler。

completionHandler(WKUserNotificationInterfaceType.Custom)

WatchOS 2.0文档:

  

用于告诉系统接口的完成处理程序   显示。在方法结束时执行此完成处理程序   实现。如果你没有及时执行这个块,   系统显示应用程序的静态通知界面。