天道酬勤,学无止境

apple-watch-complication

如何使用来自complicationController的sendMessage唤醒iOS父应用程序(how to wake up iOS parent app with sendMessage from complicationController)

问题 我正在尝试通过从 watchkit 扩展发送消息来唤醒 iOS 父应用程序。 这只有在从 watchApp / ViewController 调用下面的 sendMessage 函数时才有效。 当从 ComplicationController 调用它时,会发送消息,但 iOS 父应用程序现在确实会唤醒。 任何建议表示赞赏。 (请在 Swift 中引用任何代码) 这里的简化代码: 在 AppDelegate 和 ExtensionDelegate 中: override init() { super.init() setupWatchConnectivity() } private func setupWatchConnectivity() { if WCSession.isSupported() { let session = WCSession.defaultSession() session.delegate = self session.activateSession() } } 在 ExtensionDelegate 中:(这里没问题,消息发送成功) func sendMessage(){ let session = WCSession.defaultSession() let applicationData:[String:AnyObject] = ["text"

2022-01-13 11:56:41    分类:技术分享    ios   iphone   swift2   apple-watch-complication   clockkit

how to wake up iOS parent app with sendMessage from complicationController

I am trying to wake up the iOS parent app by sending a message from watchkit extension. This though does only work when below sendMessage function is called from the watchApp / ViewController. When it is called from ComplicationController, the message is sent, but the iOS parent app does now wake up. Any advice appreciated. (please any code reference in Swift) Here the simplified code: In AppDelegate and ExtensionDelegate: override init() { super.init() setupWatchConnectivity() } private func setupWatchConnectivity() { if WCSession.isSupported() { let session = WCSession.defaultSession()

2022-01-11 11:50:18    分类:问答    ios   iphone   swift2   apple-watch-complication   clockkit

在不运行时保持我的 WatchKit 并发症最新(Keeping my WatchKit complications up to date when not running)

问题 我正在开发我的应用程序的 WatchKit 扩展,并且遇到了一些并发症问题。 我有一个显示给定总量的复杂功能,这取决于用户在 iOS 应用程序上的操作。 当 WatchKit 扩展运行时,iOS 应用程序使用-[WCSession updateApplicationContext:]方法更新手表应用程序上下文。 它工作正常,然后在我的 Watch 应用程序的 ExtensionDelegate 中,我用新数据手动更新了复杂功能。 但这仅在扩展程序运行时才可以(如果不是,则在下一次启动之前不会获取应用程序上下文)。 所以我编辑了我的代码,当用户在 iOS 应用程序中更改某些内容时,将复杂数据直接发送到 Watch,使用-[WCSession transferCurrentComplicationUserInfo:]方法(它写在文档中,应该唤醒 ExtensionDelegate 以接收用户信息在后台)。 我已经实现了 ExtensionDelegate 的-session:didReceiveUserInfo:方法来在它从 iOS 应用程序接收数据时更新复杂性,但是当扩展没有运行时它不起作用......(我不知道是否它曾经收到用户信息,因为我无法登录) 即使扩展没有运行,我应该如何做才能使我的并发症保持最新? 谢谢 PS:我正在使用手表模拟器,要“关闭”扩展程序

2021-12-21 11:45:15    分类:技术分享    ios   watch   apple-watch-complication

获取数据复杂化:未调用 ExtensionDelegate(Get Data to Complication: ExtensionDelegate not Called)

问题 (看起来这个问题在前几周已经被其他人遇到了,但我还没有找到任何解决方案。) 我正在尝试做一件非常基本的事情:从我的 iOS 应用程序或我的 Watch 应用程序获取数据到我的 Complication Controller。 事实证明,我完成这件事的能力比我想象的要差得多。 watchOS 2 Transition Guide 指出我应该使用以下代码“[获取]来自扩展委托的所需数据”: ExtensionDelegate* myDelegate = [[WKExtension sharedExtension] delegate]; NSDictionary* data = [myDelegate.myComplicationData objectForKey:ComplicationCurrentEntry]; 伟大的。 除了,我一直无法弄清楚如何让它在扩展端工作。 尽管更重要的是,我似乎甚至无法从复杂控制器启动中运行扩展委托代码。 当我运行复杂功能时,我收到以下消息:“扩展收到唤醒复杂功能支持的请求。” 但是,任何扩展委托的方法中的代码似乎都没有运行。 我还在每个方法中设置了断点,并且没有一个断点被命中。 它看起来也像“transferCurrentComplicationUserInfo:”也被建议用于复杂功能更新,尽管目前还不清楚它是如何使用的。 据我所知

2021-12-21 10:54:48    分类:技术分享    apple-watch   watchos-2   apple-watch-complication   clockkit

Keeping my WatchKit complications up to date when not running

I'm working on the WatchKit Extension of my app, and have some issues with complications. I have a complication that displays a given total amount, which depends of what the user is doing on the iOS app. When the WatchKit Extension is running, the iOS app updates the watch app context using the -[WCSession updateApplicationContext:] method. It works fine, and then in the ExtensionDelegate of my Watch app, I manually update the complication with the new data. But this is OK only when the extension is running (if it's not, it won't get the application context until the next launch). So I edited

2021-12-13 13:33:00    分类:问答    ios   watch   apple-watch-complication

Get Data to Complication: ExtensionDelegate not Called

(It looks like this issue has been encountered by others in previous weeks, but there haven't been any solutions that I've found.) I'm trying to do a really basic thing: Get data from either my iOS app or my Watch app to my Complication Controller. I am turning out to be way less capable of getting this done than I thought. watchOS 2 Transition Guide indicates that I should "[fetch] the needed data from the extension delegate" using the following code: ExtensionDelegate* myDelegate = [[WKExtension sharedExtension] delegate]; NSDictionary* data = [myDelegate.myComplicationData objectForKey

2021-12-12 12:20:45    分类:问答    apple-watch   watchos-2   apple-watch-complication   clockkit

使用三个数组填充复杂功能时间线(Using three arrays to populate complication timeline)

问题 我有三个数组,这些数组的数据可以用条目填充复杂性时间线。 当我滚动时间旅行时,并发症没有改变,所以我知道我一定做错了什么。 func getTimelineEntriesForComplication(complication: CLKComplication, afterDate date: NSDate, limit: Int, withHandler handler: (([CLKComplicationTimelineEntry]?) -> Void)) { for headerObject in headerArray! { for body1Object in body1Array! { for body2Object in body2Array! { let headerTextProvider = CLKSimpleTextProvider(text: headerObject as! String) let body1TextProvider = CLKSimpleTextProvider(text: body1Object as! String) let body2TextProvider = CLKRelativeDateTextProvider(date: body2Object as! NSDate, style: .Offset, units:

2021-11-10 15:54:47    分类:技术分享    swift   watchkit   watchos-2   apple-watch-complication

Using three arrays to populate complication timeline

I have three arrays that have the data to populate the complication timeline with entries. When I scroll through time travel, the complication does not change so I know I must be doing something wrong. func getTimelineEntriesForComplication(complication: CLKComplication, afterDate date: NSDate, limit: Int, withHandler handler: (([CLKComplicationTimelineEntry]?) -> Void)) { for headerObject in headerArray! { for body1Object in body1Array! { for body2Object in body2Array! { let headerTextProvider = CLKSimpleTextProvider(text: headerObject as! String) let body1TextProvider = CLKSimpleTextProvider

2021-11-09 06:30:07    分类:问答    swift   watchkit   watchos-2   apple-watch-complication

watchOS - 复杂功能显示以前的条目(watchOS - Complication shows previous entry)

问题 我正在创建一个 watchOS 3 复杂功能,用于显示公共交通服务的出发时间。 我用一个数组创建了一个数据模型,该数组包含带有stationName (String) 和departureTime (NSDate) 的Train对象。 我已经实现了 getCurrentTimelineEntry() 方法并且条目显示在手表上。 问题是手表只显示上一个条目。 例如,我有以下出发时间: Train(startStation: "Station name", endStation: "Station name", departureTime: stringToDate(dateString: "2016-06-20 14:00")), Train(startStation: "Station name", endStation: "Station name", departureTime: stringToDate(dateString: "2016-06-20 14:30")), Train(startStation: "Station name", endStation: "Station name", departureTime: stringToDate(dateString: "2016-06-20 14:45")), 如果当前时间为 14:10,则手表上仍显示第一个条目

2021-10-14 23:52:33    分类:技术分享    swift   watchkit   apple-watch-complication   clockkit   watchos-3

为 Apple Watch 复杂功能设置 tintColor(Setting tintColor for Apple Watch complication)

问题 我正在尝试为模块化大型复杂功能设置标题文本颜色。 我已经自定义了表盘以使用多色。 但是,当我构建并运行此代码时,标题文本颜色仍然是白色(这是默认值)。 为什么不更新颜色? private func templateForClassModularLarge(className: Schedule) -> CLKComplicationTemplateModularLargeStandardBody { let template = CLKComplicationTemplateModularLargeStandardBody() let headerTextProvider = CLKSimpleTextProvider(text: "My Schedule", shortText: "Schedule") headerTextProvider.tintColor = UIColor(red: 101, green: 153, blue: 255, alpha: 1) template.headerTextProvider = headerTextProvider template.body1TextProvider = CLKTimeIntervalTextProvider(startDate: className.start, endDate: className.end)

2021-10-14 21:33:16    分类:技术分享    swift   watchos   apple-watch-complication   clockkit