Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Not shared data between react native and widget #24

Open
Youthleap423 opened this issue Aug 27, 2021 · 19 comments
Open

Not shared data between react native and widget #24

Youthleap423 opened this issue Aug 27, 2021 · 19 comments

Comments

@Youthleap423
Copy link

I have made widget extension with app and tried to share data between them. but It is not working. I can't get data on widget.
Can you tell me about issues?

@Youthleap423
Copy link
Author

my log is: [User Defaults] Couldn't read values in CFPrefsPlistSource

@csumrell
Copy link

same thing for me, following the instruction on the readme this, I can not get darta on widget. It shows it saves in the app but it does not show up in the widget or userdefault storage

@duyhodev
Copy link

+1

1 similar comment
@dominickmalzone
Copy link

+1

@panutat
Copy link

panutat commented Apr 29, 2022

+1 extension also

@duyhodev
Copy link

duyhodev commented May 25, 2022

Finally I managed to get it work

  • The identifier for app group should have some postfix, for example, your main app identifier is com.domain.myapp, then you app group identifier should be group.com.domain.myapp.store

  • In widget side, we can get the data like so in the timeline
    `

    func getTimeline(for configuration: ConfigurationIntent, in context: Context, completion: @escaping (Timeline<Entry>) -> ()) {
      let userDefaults = UserDefaults(suiteName:"group.com.domain.myapp.store)
    
      var user: User?
      do {
          let shared = userDefaults?.string(forKey: "user")
          print("data", shared)
    
          if(shared != nil){
              user = try JSONDecoder().decode(User.self, from: shared!.data(using: .utf8)!)
          }
       } catch{
        print(error)
       }
    
      let entry = UserEntry(date: Date(), configuration: ConfigurationIntent(), user: user)
      let timeline = Timeline(entries: [entry], policy: .atEnd)
      completion(timeline)
    }
    

`
then in the entry view, you can get this user data by entry.user

  • Can also use react-native-widget-bridge, call WidgetBridge.reloadWidget('MyApp_Widget') every time you do some changes

I'm not sure this is the best way to deal with it or not, but it works for me

@quant-daddy
Copy link

I think the group identifier can be anything. Make sure to add same App Group and check the check box in both the app and the widget configuration.

Screenshot 2023-07-07 at 9 45 40 PM

@naveedashfaq272
Copy link

naveedashfaq272 commented Mar 14, 2024

Finally I managed to get it work

  • The identifier for app group should have some postfix, for example, your main app identifier is com.domain.myapp, then you app group identifier should be group.com.domain.myapp.store
  • In widget side, we can get the data like so in the timeline
    `
    func getTimeline(for configuration: ConfigurationIntent, in context: Context, completion: @escaping (Timeline<Entry>) -> ()) {
      let userDefaults = UserDefaults(suiteName:"group.com.domain.myapp.store)
    
      var user: User?
      do {
          let shared = userDefaults?.string(forKey: "user")
          print("data", shared)
    
          if(shared != nil){
              user = try JSONDecoder().decode(User.self, from: shared!.data(using: .utf8)!)
          }
       } catch{
        print(error)
       }
    
      let entry = UserEntry(date: Date(), configuration: ConfigurationIntent(), user: user)
      let timeline = Timeline(entries: [entry], policy: .atEnd)
      completion(timeline)
    }
    

` Then in the entry view, you can get this user data by entry. user

  • Can also use react-native-widget-bridge, call WidgetBridge.reloadWidget('MyApp_Widget') every time you do some changes

I'm not sure if this is the best way to deal with it or not, but it works for me

@duyhodev Hello,

I hope you're doing well.

I've integrated this library to store data in the app group and successfully used SharedGroupPreferences.setItem and SharedGroupPreferences.getItem.

However, when attempting to fetch the stored data on the iOS native side, it returns nil values.

Could you please provide guidance on whether there are any extra configurations needed?

I've created a widget extension, but I'm unsure if additional code needs to be written inside the extension file.

Thank you in advance for your assistance.

I did integrations with the help of this document:
https://www.cristiangutu.pro/share-data-between-react-native-and-ios-widgets/

@naveedashfaq272
Copy link

@duyhodev Can you please help me??????

@Youthleap423
Copy link
Author

Youthleap423 commented Mar 18, 2024 via email

@naveedashfaq272
Copy link

naveedashfaq272 commented Mar 18, 2024

Do you have any other account to chat with me?

On Mon, Mar 18, 2024 at 2:27 AM naveedashfaq272 @.***> wrote: @duyhodev https://github.com/duyhodev Can you please help me?????? — Reply to this email directly, view it on GitHub <#24 (comment)>, or unsubscribe https://github.com/notifications/unsubscribe-auth/AIHFWCSRNGTUH7ZMVJXNFUTYY2CODAVCNFSM5C5OLMP2U5DIOJSWCZC7NNSXTN2JONZXKZKDN5WW2ZLOOQ5TEMBQGMYDCOBZGY2A . You are receiving this because you authored the thread.Message ID: </issues/24/2003018964@ github.com>

@sekoucox7913 Yes, I do have multiple accounts. let me know which one is suitable for you??

@naveedashfaq272
Copy link

Do you have any other account to chat with me?

On Mon, Mar 18, 2024 at 2:27 AM naveedashfaq272 @.***> wrote: @duyhodev https://github.com/duyhodev Can you please help me?????? — Reply to this email directly, view it on GitHub <#24 (comment)>, or unsubscribe https://github.com/notifications/unsubscribe-auth/AIHFWCSRNGTUH7ZMVJXNFUTYY2CODAVCNFSM5C5OLMP2U5DIOJSWCZC7NNSXTN2JONZXKZKDN5WW2ZLOOQ5TEMBQGMYDCOBZGY2A . You are receiving this because you authored the thread.Message ID: </issues/24/2003018964@ github.com>

"Hey @sekoucox7913 and @duyhodev, can you please help me out? I'm facing an issue and I was wondering if any of you have dealt with something similar and could offer some advice. Thanks in advance!"

@Youthleap423
Copy link
Author

@naveedashfaq272 Can you share your code snippet? shared data setting part on the react native side and getting part on the ios native side.

@naveedashfaq272
Copy link

naveedashfaq272 commented Mar 19, 2024

@naveedashfaq272 Can you share your code snippet? shared data setting part on the react native side and getting part on the ios native side.

Hey @sekoucox7913, I have attached screenshots that show the code snippets you asked for. They cover the shared data setting part on the React Native side and the getting part on the iOS Native side. If you have any further queries, feel free to let me know.
Screenshot 2024-03-19 at 11 38 30 AM
Screenshot 2024-03-19 at 11 39 34 AM
Screenshot 2024-03-19 at 11 46 19 AM

@Youthleap423
Copy link
Author

image
Can you check this?

@naveedashfaq272
Copy link

image Can you check this?

I checked but the issue is still same.

@naveedashfaq272
Copy link

image Can you check this?

Do I need to add additional code in the widget extension too?

@Youthleap423
Copy link
Author

No need, it seems group default is null. It means it is trying to get value before setting value.

@naveedashfaq272
Copy link

No need, it seems group default is null. It means it is trying to get value before setting value.

thanks for your help let me try to debug the settings.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants