title: What order dose a complications happen hand how do I change the data?
body: <p>I've asked a question before about how I refresh a complications and got some help there but I still don't know in what order everything happens and how to update the complications data. My complications is still showing the first loaded data even after a <code>WKRefreshBackgroundTask</code></p>
  <p><a href="https://stackoverflow.com/questions/68106565/how-do-i-refresh-watchapp-complications">How do I refresh WatchApp complications</a></p>
  <p>My <code>WKRefreshBackgroundTask</code> look like this and at calls scheduleBackgroundRefreshTasks():</p>
  <pre class="lang-swift prettyprint-override"><code>    func handle(_ backgroundTasks: Set&lt;WKRefreshBackgroundTask&gt;) {
          print(&quot;__________________________________________________&quot;)
          print(&quot;Handling a background task...&quot;)
          print(&quot;App State: \(WKExtension.shared().applicationState.rawValue)&quot;)
          print(GlobalVaribles.sharedInstance.currentTime)
          print(&quot;__________________________________________________&quot;)
  
          
          for task in backgroundTasks {
              print(&quot;backgroundTasks = \(backgroundTasks)&quot;)
  
              switch task {
              // Handle background refresh tasks.
              case let backgroundTask as WKApplicationRefreshBackgroundTask:
                  scheduleBackgroundRefreshTasks()
                  backgroundTask.setTaskCompletedWithSnapshot(true)
              case let snapshotTask as WKSnapshotRefreshBackgroundTask:
                  snapshotTask.setTaskCompleted(restoredDefaultState: true, estimatedSnapshotExpiration: Date.distantFuture, userInfo: nil)
              case let connectivityTask as WKWatchConnectivityRefreshBackgroundTask:
                  connectivityTask.setTaskCompletedWithSnapshot(false)
              case let urlSessionTask as WKURLSessionRefreshBackgroundTask:
                  urlSessionTask.setTaskCompletedWithSnapshot(false)
              case let relevantShortcutTask as WKRelevantShortcutRefreshBackgroundTask:
                  relevantShortcutTask.setTaskCompletedWithSnapshot(false)
              case let intentDidRunTask as WKIntentDidRunRefreshBackgroundTask:
                  intentDidRunTask.setTaskCompletedWithSnapshot(false)
              default:
                  task.setTaskCompletedWithSnapshot(false)
              }
          }
      }
  }
  
  </code></pre>
  <p>I can see that  <code>scheduleBackgroundRefreshTasks</code> prints <code>&quot;Task scheduled with targetDate = \(targetDate).&quot;)</code>but no data is changing.</p>
  <H1>ExtensionDelegate.swift</H1>
  <pre><code>import ClockKit
  import WatchKit
  import os
  
  // The app's extension delegate.
  class ExtensionDelegate: NSObject, WKExtensionDelegate {
      func applicationDidFinishLaunching(){
          print(&quot;&gt;&gt;&gt;&gt;&gt; applicationDidFinishLaunching&quot;)
      }
      func applicationDidBecomeActive(){
          print(&quot;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; applicationDidBecomeActive&quot;)
      }
      func applicationWillResignActive(){
          print(&quot;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; applicationWillResignActive&quot;)
      }
      func applicationWillEnterForeground(){
          print(&quot;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; applicationWillEnterForeground&quot;)
      }
      func applicationDidEnterBackground(){
          print(&quot;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; applicationDidEnterBackground&quot;)
          scheduleBackgroundRefreshTasks()
      }
      func updateActiveComplications(){
          
      }
  
  
      func handle(_ backgroundTasks: Set&lt;WKRefreshBackgroundTask&gt;) {
          print(&quot;__________________________________________________&quot;)
          print(&quot;Handling a background task...&quot;)
          print(&quot;App State: \(WKExtension.shared().applicationState.rawValue)&quot;)
          print(GlobalVaribles.sharedInstance.currentTime)
          print(&quot;__________________________________________________&quot;)
  
          
          for task in backgroundTasks {
              print(&quot;backgroundTasks = \(backgroundTasks)&quot;)
  
              switch task {
              // Handle background refresh tasks.
              case let backgroundTask as WKApplicationRefreshBackgroundTask:
                  scheduleBackgroundRefreshTasks()
                  backgroundTask.setTaskCompletedWithSnapshot(true)
              case let snapshotTask as WKSnapshotRefreshBackgroundTask:
                  snapshotTask.setTaskCompleted(restoredDefaultState: true, estimatedSnapshotExpiration: Date.distantFuture, userInfo: nil)
              case let connectivityTask as WKWatchConnectivityRefreshBackgroundTask:
                  connectivityTask.setTaskCompletedWithSnapshot(false)
              case let urlSessionTask as WKURLSessionRefreshBackgroundTask:
                  urlSessionTask.setTaskCompletedWithSnapshot(false)
              case let relevantShortcutTask as WKRelevantShortcutRefreshBackgroundTask:
                  relevantShortcutTask.setTaskCompletedWithSnapshot(false)
              case let intentDidRunTask as WKIntentDidRunRefreshBackgroundTask:
                  intentDidRunTask.setTaskCompletedWithSnapshot(false)
              default:
                  task.setTaskCompletedWithSnapshot(false)
              }
          }
      }
  }
  
  func scheduleBackgroundRefreshTasks() {
      print(&quot;--&gt;&gt;--&gt;&gt;--&gt;&gt;--&gt;&gt;--&gt;&gt;--&gt;&gt;--&gt;&gt;--&gt;&gt;--&gt;&gt;--&gt;&gt;--&gt;&gt;--&gt;&gt;--&gt;&gt;--&gt;&gt;--&gt;&gt;&quot;)
      print(GlobalVaribles.sharedInstance.title)
      print(GlobalVaribles.sharedInstance.currentTime)
      print(&quot;--&gt;&gt;--&gt;&gt;--&gt;&gt;--&gt;&gt;--&gt;&gt;--&gt;&gt;--&gt;&gt;--&gt;&gt;--&gt;&gt;--&gt;&gt;--&gt;&gt;--&gt;&gt;--&gt;&gt;--&gt;&gt;--&gt;&gt;&quot;)
      let watchExtension = WKExtension.shared()
      let targetDate = Date().addingTimeInterval(60)
      let title = GlobalVaribles.sharedInstance.title
      let time = GlobalVaribles.sharedInstance.time
      let info: NSDictionary = [
          &quot;title&quot; : title,
          &quot;time&quot;: time
      ]
      
      watchExtension.scheduleBackgroundRefresh(withPreferredDate: targetDate, userInfo: info) { (error) in
          if let error = error {
              print(&quot;An error occurred while scheduling a background refresh task: \(error.localizedDescription)&quot;)
              return
          }
          print(&quot;Task scheduled with targetDate = \(targetDate).&quot;)
      }
  }
  </code></pre>
  <H1>ComplicationController.swift</H1>
  <pre><code>/*
  See LICENSE folder for this sample’s licensing information.
  
  Abstract:
  A controller that configures and updates the complications.
  */
  
  import ClockKit
  
  class ComplicationController: NSObject, CLKComplicationDataSource {
      // MARK: - Timeline Configuration
      func getTimelineEndDate(for complication: CLKComplication, withHandler handler: @escaping (Date?) -&gt; Void) {
          // Indicate that the app can provide timeline entries for the next 24 hours.
          handler(Date().addingTimeInterval(24.0 * 60.0 * 60.0))
      }
      func getPrivacyBehavior(for complication: CLKComplication, withHandler handler: @escaping (CLKComplicationPrivacyBehavior) -&gt; Void) {
          // This is potentially sensitive data. Hide it on the lock screen.
          handler(.hideOnLockScreen)
      }
      func getComplicationDescriptors(handler: @escaping ([CLKComplicationDescriptor]) -&gt; Void) {
          let descriptor = CLKComplicationDescriptor(identifier: &quot;Scheduled_Countdown&quot;,
                                                     displayName: &quot;Scheduled Countdown&quot;,
                                                     supportedFamilies: CLKComplicationFamily.allCases)
          handler([descriptor])
      }
      
      // MARK: - Timeline Population
      func getCurrentTimelineEntry(for complication: CLKComplication, withHandler handler: @escaping (CLKComplicationTimelineEntry?) -&gt; Void) {
          print(&quot;////////////////////////////////////////////////////////////&quot;)
          print(&quot;getCurrentTimelineEntry&quot;)
          print(&quot;////////////////////////////////////////////////////////////&quot;)
              handler(createTimelineEntry(forComplication: complication, date: Date()))
      }
      
      // Return future timeline entries.
      func getTimelineEntries(for complication: CLKComplication,
                              after date: Date,
                              limit: Int,
                              withHandler handler: @escaping ([CLKComplicationTimelineEntry]?) -&gt; Void) {
          
          print(&quot;-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_&quot;)
          print(&quot;getTimelineEntries&quot;)
          print(&quot;-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_&quot;)
  
          let fiveMinutes = 1.0 * 60
          let twentyFourHours = 24.0 * 60.0 * 60.0
          
          var entries = [CLKComplicationTimelineEntry]()
          
          var current = date.addingTimeInterval(fiveMinutes)
          let endDate = date.addingTimeInterval(twentyFourHours)
          
          while (current.compare(endDate) == .orderedAscending) &amp;&amp; (entries.count &lt; limit) {
              for i in 0..&lt;3600 {
                  let line1 = CLKSimpleTextProvider(text:GlobalVaribles.sharedInstance.title)
                  let line2 = CLKSimpleTextProvider(text:&quot;\(GlobalVaribles.sharedInstance.currentTime) and \(i)&quot;)
                  let template = CLKComplicationTemplateModularLargeStandardBody(headerTextProvider: line1, body1TextProvider: line2)
                  let entry = CLKComplicationTimelineEntry(date: date.addingTimeInterval(Double(i)), complicationTemplate: template)
                      entries.append(entry)
              }
              //entries.append(createTimelineEntry(forComplication: complication, date: current))
              current = current.addingTimeInterval(fiveMinutes)
          }
          
          handler(entries)
      }
      
      // MARK: - Placeholder Templates
      func getLocalizableSampleTemplate(for complication: CLKComplication, withHandler handler: @escaping (CLKComplicationTemplate?) -&gt; Void) {
          let future = Date().addingTimeInterval(25.0 * 60.0 * 60.0)
          let template = createTemplate(forComplication: complication, date: future)
          handler(template)
      }
  
      // MARK: - Private Methods
      private func createTimelineEntry(forComplication complication: CLKComplication, date: Date) -&gt; CLKComplicationTimelineEntry {
          
          // Get the correct template based on the complication.
          let template = createTemplate(forComplication: complication, date: date)
          
          // Use the template and date to create a timeline entry.
          return CLKComplicationTimelineEntry(date: date, complicationTemplate: template)
      }
      private func createTemplate(forComplication complication: CLKComplication, date: Date) -&gt; CLKComplicationTemplate {
          switch complication.family {
          case .modularSmall:
              return createModularSmallTemplate(forDate: date)
          case .modularLarge:
              return createModularLargeTemplate(forDate: date)
          case .utilitarianSmall, .utilitarianSmallFlat:
              return createUtilitarianSmallFlatTemplate(forDate: date)
          case .utilitarianLarge:
              return createUtilitarianLargeTemplate(forDate: date)
          case .circularSmall:
              return createCircularSmallTemplate(forDate: date)
          case .extraLarge:
              return createExtraLargeTemplate(forDate: date)
          case .graphicCorner:
              return createGraphicCornerTemplate(forDate: date)
          case .graphicCircular:
              return createGraphicCircleTemplate(forDate: date)
          case .graphicRectangular:
              return createGraphicRectangularTemplate(forDate: date)
          case .graphicBezel:
              return createGraphicBezelTemplate(forDate: date)
          case .graphicExtraLarge:
              if #available(watchOSApplicationExtension 7.0, *) {
                  return createGraphicExtraLargeTemplate(forDate: date)
              } else {
                  fatalError(&quot;Graphic Extra Large template is only available on watchOS 7.&quot;)
              }
          @unknown default:
              fatalError(&quot;*** Unknown Complication Family ***&quot;)
          }
      }
      
      // Return a modular small template.
      private func createModularSmallTemplate(forDate date: Date) -&gt; CLKComplicationTemplate {
          
          print(&quot;&gt;&gt;&gt; createModularSmallTemplate &lt;&lt;&lt;&quot;)
          let title = CLKSimpleTextProvider(text: &quot;Loading&quot;)
          let time = CLKSimpleTextProvider(text: &quot;...&quot;)
  //        GlobalVaribles.sharedInstance.startSocket()
          
          // Create the template using the providers.
          return CLKComplicationTemplateModularSmallStackText(line1TextProvider: title,
                                                              line2TextProvider: time)
      }
      private func createModularLargeTemplate(forDate date: Date) -&gt; CLKComplicationTemplate {
          let titleTextProvider = CLKSimpleTextProvider(text: &quot;Scheduled Countdown&quot;)
          let title = CLKSimpleTextProvider(text: GlobalVaribles.sharedInstance.title)
          let time = CLKSimpleTextProvider(text: GlobalVaribles.sharedInstance.time)
          
          // Create the template using the providers.
          return CLKComplicationTemplateModularLargeStandardBody(headerTextProvider: titleTextProvider,
                                                                 body1TextProvider: title,
                                                                 body2TextProvider: time)
      }
      private func createUtilitarianSmallFlatTemplate(forDate date: Date) -&gt; CLKComplicationTemplate {
          // Create the data providers.
          let title = CLKSimpleTextProvider(text: GlobalVaribles.sharedInstance.title)
          let time = CLKSimpleTextProvider(text: GlobalVaribles.sharedInstance.time)
          let combinedMGProvider = CLKTextProvider(format: &quot;%@ %@&quot;, title, time)
          
          // Create the template using the providers.
          return CLKComplicationTemplateUtilitarianSmallFlat(textProvider: combinedMGProvider)
      }
      private func createUtilitarianLargeTemplate(forDate date: Date) -&gt; CLKComplicationTemplate {
          // Create the data providers.
          let title = CLKSimpleTextProvider(text: GlobalVaribles.sharedInstance.title)
          let time = CLKSimpleTextProvider(text: GlobalVaribles.sharedInstance.time)
          let combinedMGProvider = CLKTextProvider(format: &quot;%@ %@&quot;, title, time)
          
          // Create the template using the providers.
          return CLKComplicationTemplateUtilitarianLargeFlat(textProvider: combinedMGProvider)
      }
      private func createCircularSmallTemplate(forDate date: Date) -&gt; CLKComplicationTemplate {
          // Create the data providers.
          let title = CLKSimpleTextProvider(text: GlobalVaribles.sharedInstance.title)
          let time = CLKSimpleTextProvider(text: GlobalVaribles.sharedInstance.time)
          
          // Create the template using the providers.
          return CLKComplicationTemplateCircularSmallStackText(line1TextProvider: title,
                                                               line2TextProvider: time)
      }
      private func createExtraLargeTemplate(forDate date: Date) -&gt; CLKComplicationTemplate {
          // Create the data providers.
          let title = CLKSimpleTextProvider(text: GlobalVaribles.sharedInstance.title)
          let time = CLKSimpleTextProvider(text: GlobalVaribles.sharedInstance.time)
          
          // Create the template using the providers.
          return CLKComplicationTemplateExtraLargeStackText(line1TextProvider: title,
                                                            line2TextProvider: time)
      }
      private func createGraphicCornerTemplate(forDate date: Date) -&gt; CLKComplicationTemplate {
          // Create the data providers.
          let leadingValueProvider = CLKSimpleTextProvider(text: &quot;0&quot;)
          leadingValueProvider.tintColor = .green
          
          let trailingValueProvider = CLKSimpleTextProvider(text: &quot;500&quot;)
          trailingValueProvider.tintColor = .blue
          
          let title = CLKSimpleTextProvider(text: GlobalVaribles.sharedInstance.title)
          let time = CLKSimpleTextProvider(text: GlobalVaribles.sharedInstance.time)
          let combinedMGProvider = CLKTextProvider(format: &quot;%@ %@&quot;, title, time)
          
          let percentage = Float(0.5)
          let gaugeProvider = CLKSimpleGaugeProvider(style: .fill,
                                                     gaugeColors: [.green, .yellow, .red],
                                                     gaugeColorLocations: [0.0, 300.0 / 500.0, 450.0 / 500.0] as [NSNumber],
                                                     fillFraction: percentage)
          
          // Create the template using the providers.
          return CLKComplicationTemplateGraphicCornerGaugeText(gaugeProvider: gaugeProvider,
                                                               leadingTextProvider: leadingValueProvider,
                                                               trailingTextProvider: trailingValueProvider,
                                                               outerTextProvider: combinedMGProvider)
      }
      private func createGraphicCircleTemplate(forDate date: Date) -&gt; CLKComplicationTemplate {
          // Create the data providers.
          let percentage = Float(0.5)
          let gaugeProvider = CLKSimpleGaugeProvider(style: .fill,
                                                     gaugeColors: [.green, .yellow, .red],
                                                     gaugeColorLocations: [0.0, 300.0 / 500.0, 450.0 / 500.0] as [NSNumber],
                                                     fillFraction: percentage)
          
          let title = CLKSimpleTextProvider(text: GlobalVaribles.sharedInstance.title)
          let time = CLKSimpleTextProvider(text: GlobalVaribles.sharedInstance.time)
          
          // Create the template using the providers.
          return CLKComplicationTemplateGraphicCircularOpenGaugeSimpleText(gaugeProvider: gaugeProvider,
                                                                           bottomTextProvider: title,
                                                                           centerTextProvider: time)
      }
      private func createGraphicRectangularTemplate(forDate date: Date) -&gt; CLKComplicationTemplate {
          // Create the data providers.
          let titleTextProvider = CLKSimpleTextProvider(text: &quot;Coffee Tracker&quot;, shortText: &quot;Coffee&quot;)
          
          let title = CLKSimpleTextProvider(text: GlobalVaribles.sharedInstance.title)
          let time = CLKSimpleTextProvider(text: GlobalVaribles.sharedInstance.time)
          let combinedMGProvider = CLKTextProvider(format: &quot;%@ %@&quot;, title, time)
          
          let percentage = Float(0.5)
          let gaugeProvider = CLKSimpleGaugeProvider(style: .fill,
                                                     gaugeColors: [.green, .yellow, .red],
                                                     gaugeColorLocations: [0.0, 300.0 / 500.0, 450.0 / 500.0] as [NSNumber],
                                                     fillFraction: percentage)
          
          // Create the template using the providers.
          
          return CLKComplicationTemplateGraphicRectangularTextGauge(headerTextProvider: titleTextProvider,
                                                                    body1TextProvider: combinedMGProvider,
                                                                    gaugeProvider: gaugeProvider)
      }
      private func createGraphicBezelTemplate(forDate date: Date) -&gt; CLKComplicationTemplate {
          
          // Create a graphic circular template with an image provider.
          let circle = CLKComplicationTemplateGraphicCircularImage(imageProvider: CLKFullColorImageProvider(fullColorImage: #imageLiteral(resourceName: &quot;CoffeeGraphicCircular&quot;)))
          
          // Create the text provider.
          let title = CLKSimpleTextProvider(text: GlobalVaribles.sharedInstance.title)
          let time = CLKSimpleTextProvider(text: GlobalVaribles.sharedInstance.time)
          
          let separator = NSLocalizedString(&quot;,&quot;, comment: &quot;Separator for compound data strings.&quot;)
          let textProvider = CLKTextProvider(format: &quot;%@%@ %@&quot;,
                                             title,
                                             separator,
                                             time)
          
          // Create the bezel template using the circle template and the text provider.
          return CLKComplicationTemplateGraphicBezelCircularText(circularTemplate: circle,
                                                                 textProvider: textProvider)
      }
      private func createGraphicExtraLargeTemplate(forDate date: Date) -&gt; CLKComplicationTemplate {
          
          // Create the data providers.
          let percentage = Float(0.5)
          let gaugeProvider = CLKSimpleGaugeProvider(style: .fill,
                                                     gaugeColors: [.green, .yellow, .red],
                                                     gaugeColorLocations: [0.0, 300.0 / 500.0, 450.0 / 500.0] as [NSNumber],
                                                     fillFraction: percentage)
          
          let title = CLKSimpleTextProvider(text: GlobalVaribles.sharedInstance.title)
          let time = CLKSimpleTextProvider(text: GlobalVaribles.sharedInstance.time)
          
          return CLKComplicationTemplateGraphicExtraLargeCircularOpenGaugeSimpleText(
              gaugeProvider: gaugeProvider,
              bottomTextProvider: title,
              centerTextProvider: time)
      }
      
      
      
      
  }
  </code></pre>