How to correctly implement transfer of settings from iOS app to watchOS2 complication

后端 未结 1 1887
一整个雨季
一整个雨季 2021-01-27 02:28

What I want to achieve is the following:

  1. Complication(s) get updated in the background at intervals of 30 minutes
  2. Complication(s) get updated whenever th
相关标签:
1条回答
  • 2021-01-27 03:09

    The purpose of transferCurrentComplicationUserInfo is to immediately pass current complication data to the extension. In your code, you are passing settings, however you are not including any weather data.

    The issue you're seeing stems from trying to asynchronously fetch new data within the extension (which is returning before the data is available).

    To handle this, you should fetch the current weather data on the phone based on the new settings, then pass (the new settings along with) the weather data in the current complication user info.

    - (void)session:(WCSession *)session didReceiveUserInfo:(NSDictionary<NSString *,id> *)userInfo {
        // Code here to apply the new settings for future updates
        // ....
        // Code here to update cache/backing store with current weather data just passed to us
        // ....
    
        CLKComplicationServer *server = [CLKComplicationServer sharedInstance];
        for (CLKComplication *complication in server.activeComplications) {
            [server reloadTimelineForComplication:complication];
        }
    }
    

    This way, the complication server can immediately update the timeline using the current complication data you just transferred to the watch.

    No stale data, no unnecessary second update.

    0 讨论(0)
提交回复
热议问题