【问题标题】:Watchos 2 Beta 5 Dynamic notification not showing,Only static notification interface loadedWatchos 2 Beta 5 动态通知不显示,仅加载静态通知界面
【发布时间】:2015-09-02 07:14:59
【问题描述】:

我创建了苹果手表应用程序来显示推送通知。所以我创建了不同类别的不同动态通知界面。但它没有显示动态界面但能够看到相应类别的操作按钮。请帮助我。请找到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()


        }

【问题讨论】:

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


    【解决方案1】:

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

    然后,执行completionHandler。

    completionHandler(WKUserNotificationInterfaceType.Custom)
    

    WatchOS 2.0 文档:

    完成处理程序,用于告诉系统要执行什么接口 展示。在方法结束时执行此完成处理程序 执行。如果不及时执行此块, 系统显示您应用的静态通知界面。

    【讨论】:

    • 你好 hiro_Kimu 谢谢你的回复 我已经在 WKUserNotificationInterfaceController 中添加了completionHandler
    • 我取消配对并修复了 Apple Watch,现在它可以正常工作了,谢谢
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-07-22
    • 1970-01-01
    • 1970-01-01
    • 2018-12-07
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多