i am trying to read application UserDefaults
from AppleWatch extension , after 2 days of R&D failure i am posting this thread .
for example what i am trying to do is to figure out if the user logged in or not form appleWatch side using the following code ( even if app terminated ):
struct ContentView: View {
let auth_token:String = UserDefaults(suiteName: "group.mybundle.app.com")!.string(forKey: "token") ?? ""
@ViewBuilder
var body: some View {
if self.auth_token == "" {
Text("You need to be Logged in").frame(minWidth: 0, maxWidth: .infinity, minHeight: 0, maxHeight: .infinity, alignment: .center)
}else{
WebImage(imageURL: URL(string: token)).frame(minWidth: 0, maxWidth: .infinity, minHeight: 0, maxHeight: .infinity, alignment: .center)
}
}
}
and from the application side once the user successfully logged in :
UserDefaults(suiteName: "group.mybundle.app.com")!.set(rr, forKey: "token")
UserDefaults(suiteName: "group.mybundle.app.com")!.synchronize()
i am still unable to read the token
what is the simplest way to read parent application data UserDefaults
from appleWatch extension ?