【问题标题】:Apple Watch Show Short or Long Look Notification for UILocalNotificationApple Watch 显示 UILocalNotification 的短视图或长视图通知
【发布时间】:2015-05-29 18:10:41
【问题描述】:

我想展示我为 Apple Watch 应用创建的 Short-Look 或 Long-Look 界面。

已经生效的如下:

应用程序执行一些后台工作,然后通知用户。这发生在 UILocalNotification 中。

当 iPhone 被锁定并且手表在我的手臂上时,手表会振动并只显示一个简单的通知,而不是 Long 或 Short-Look 通知。

我看到有人使用推送通知来处理它 -> Apple Watch: dynamic Long Look not shown, when push opened from Notification Center 目前我的应用不支持推送。

有没有人知道在没有执行推送的服务器的情况下呈现长或短通知的方法?

我使用以下代码发送通知:

    var localNotification =  UILocalNotification()
    //---the message to display for the alert---
    localNotification.alertBody =
    "You have entered the region you are monitoring"

    //---uses the default sound---
    localNotification.soundName = UILocalNotificationDefaultSoundName

    //---title for the button to display---
    localNotification.alertAction = "Details"
    //---display the notification---

    UIApplication.sharedApplication().presentLocalNotificationNow(localNotification)

最好的问候,

西蒙

【问题讨论】:

    标签: ios swift notifications watchkit


    【解决方案1】:

    您必须将“类别”属性设置为与手表应用故事板中的值匹配的值。

    【讨论】:

    • 谢谢,我不能再测试了,因为我没有手表了
    【解决方案2】:

    在您的 NotificationController.swift 文件(或您可能为自定义 WKUserNotificationInterfaceController 类命名的任何名称)中,您是否取消了函数“didReceiveLocalNotification”的注释(默认情况下已注释掉)?我不认为手表会显示 Short-或 Long-Look 通知。

    编辑:我错了;该功能仅与动态(Long-Look)界面有关,与静态界面无关。我不知道为什么静态界面不会出现。

    【讨论】:

    • 是的,我取消了这个函数的注释。在模拟器中显示带有按钮的 longlook,该按钮将打开我的应用程序。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多