How to reset intent extension configurations in WidgetKit

后端 未结 2 1708
眼角桃花
眼角桃花 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条回答
  •  闹比i
    闹比i (楼主)
    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?, 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)
       }
    
    }
    

提交回复
热议问题