How to reset intent extension configurations in WidgetKit

后端 未结 2 1701
眼角桃花
眼角桃花 2021-02-07 21:26

I have an application where a user can login. If a user is logged in, then I display a placeholder for my widget and it\'s configurable through an intent extension.

The c

相关标签:
2条回答
  • 2021-02-07 21:44

    I found this solution, but for dynamic properties only: use different identifiers for every user in your IntentHandler. Example:

    class IntentHandler: XXExtension { ... }
    
    extension IntentHandler: XXDynamicXXXSelectionIntentHandling {
    
       func provideXXXOptionsCollection(for intent: XXDynamicXXXSelectionIntent, with completion: @escaping (XXObjectCollection<XXX>?, Error?) -> Void) {
          let userId = (UserDefaults.myGroup().object(forKey: "UserId" ) as? String) ?? ""
          let items: [XXX] = UserDefaults.myGroup().sharedXxx.map { (sharedXxx) -> XXX in
             return XXX(identifier: userId + "_" + sharedXxx.Id // <== add unique prefix ===
                           display: sharedXxx.visibleName())
          }        
          let collection = XXObjectCollection(items: items)
          completion(collection, nil)
       }
    
    }
    
    0 讨论(0)
  • 2021-02-07 22:02

    I had the same issue that the widget was showing stale configuration options. I solved this by forcefully refreshing all objects in my shared Core Data database which I was using. I did this in the „getTimeline“ method.

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