天道酬勤,学无止境

apple-watch-complication

how to wake up iOS parent app with sendMessage from complicationController

Question 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

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

Keeping my WatchKit complications up to date when not running

Question 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

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

Get Data to Complication: ExtensionDelegate not Called

Question (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

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

Using three arrays to populate complication timeline

Question 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 =

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

watchOS - Complication shows previous entry

Question I'm creating a watchOS 3 complication that shows departure times from a public transit service. I've created a data model with an array that contains Train objects with a stationName (String) and departureTime (NSDate). I've implemented the getCurrentTimelineEntry() method and the entries are showing on the watch. The problem is that the watch shows only the previous entry. For example, I've the following departure times: Train(startStation: "Station name", endStation: "Station name", departureTime: stringToDate(dateString: "2016-06-20 14:00")), Train(startStation: "Station name"

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

Setting tintColor for Apple Watch complication

Question I am trying to set the header text color for a Modular Large complication. I have already customized the watch face to use Multicolor. However, when I build and run this code, the header text color is still white (which is the default). Why isn't the color updating? private func templateForClassModularLarge(className: Schedule) -> CLKComplicationTemplateModularLargeStandardBody { let template = CLKComplicationTemplateModularLargeStandardBody() let headerTextProvider = CLKSimpleTextProvider(text: "My Schedule", shortText: "Schedule") headerTextProvider.tintColor = UIColor(red: 101

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

ClockKit CLKComplicationDataSource missing backward events

Question I write a test app with complications support For some reason clock faces presenting only 1-2 backward events, but I can see in logs 10-15 events before current date. And when I return an empty array for forward events all my backward events start showing in clock face. Here is my function func getTimelineEntriesForComplication(complication: CLKComplication, beforeDate date: NSDate, limit: Int, withHandler handler: (([CLKComplicationTimelineEntry]?) -> Void)) { var entries: [CLKComplicationTimelineEntry] = [] let events = self.events.filter { (event: CEEvent) -> Bool in return date

2021-10-10 15:44:33    分类:技术分享    ios   apple-watch   apple-watch-complication   time-travel   clockkit

Updating complication with Swift 3 and background task

Question For watchOS 3, Apple suggests updating the complication with WKRefreshBackgroundTask instead of using getNextRequestedUpdateDate. How can I determine the time between two updates using the new approach? I would only hack my data requesting (from an url) into getCurrentTimelineEntry and would update the complication, but I think that's not really what Apple would recommend. A short code example would be a big help. Answer1 I generally covered this in a different answer, but I'll address your specific question here. You're right that you shouldn't hack the complication controller to do

2021-10-07 16:18:46    分类:技术分享    swift   swift3   apple-watch-complication   watchos-3   wkrefreshbackgroundtask

Combining WatchConnectivity and Complications

Question I want my complication to get data from the iPhone via Watch Connectivity. I am using sendMessage Instant Messaging technology. I don't want my iPhone app to be open when I try to get data, so this needs to work in the background. In my ViewController on my iPhone: import UIKit import WatchConnectivity class ViewController: UIViewController, WCSessionDelegate { var session: WCSession! override func viewDidLoad() { super.viewDidLoad() if WCSession.isSupported() { self.session = WCSession.defaultSession() self.session.delegate = self self.session.activateSession() } } func session

2021-10-07 03:55:35    分类:技术分享    swift   watchos-2   watchconnectivity   apple-watch-complication   wcsession

Watchkit Complication and location updates?

Question I'm trying to write a complication that uses location data. I can get the location data in the complication controller but it never seems to work properly due to the results coming back asynchronously. What is the best way to update a complication with location specific data? I'm thinking that it's not a good idea to get the location in the complication (even though you can). Answer1 You should retrieve and cache the location data before the complication data source needs it. The job of your data source class is to provide ClockKit with any requested data as quickly as possible. The

2021-10-07 00:19:20    分类:技术分享    watchkit   watchos-2   apple-watch-complication