Replies: 2 comments
-
I think this is not possible, since the Preferences API always writes to Standard UserDefaults. Even when specifying group, which is just a prefix for the key, not a group for sharing between app & widget. Is this possible for localStorage/sqlite maybe? Or would I need to write to an app group there too? I simply need to share one integer between web view and widget and I do not know how to. I only read this post: https://forum.ionicframework.com/t/will-app-clips-be-available-in-ionic/194768/10?u=folsze Which says: so can SQLite really be used to read from a widget? Or do I need an app group there too, which cannot be targeted from the web view capacitor community sqlite plugin? The comment from Ionic Max is from 2020... |
Beta Was this translation helpful? Give feedback.
-
Here is a minimum reproducible example repo where you can experiment fast. I did not manage to get any data sharing working in it though, currently it uses the preferences API failing to write into a specifc group from WebView to WidgetExtension: https://github.com/folsze/write-preferences-web-read-user-defaults-ios Just clickt he button "Click me to save "AAA" to preferences" when in mobile, this should save to preferences and the widget will try to read this |
Beta Was this translation helpful? Give feedback.
-
I am just wondering whether this is possible.
AFAIK Preferences writes to UserDefaults thus this might actually be possible?
BUT:
to share data between an iOS main app and its widget, you need to create a group and write into the UserDefaults of that group.
This is where I see a potential issue. Can the Preferences API in WebView-code write the values to a specific group that can then also be read by the specific widget extension group?
I am highly thankful for ANY insights for this. Currently I am not able to retrieve the value by key.
Beta Was this translation helpful? Give feedback.
All reactions