KjellConnelly / react-native-shared-group-preferences

127 stars 57 forks source link

Not shared data between react native and widget #24

Open Youthleap423 opened 3 years ago

Youthleap423 commented 3 years ago

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 commented 3 years ago

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

csumrell commented 2 years ago

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 commented 2 years ago

+1

dominickmalzone commented 2 years ago

+1

panutat commented 2 years ago

+1 extension also

duyhodev commented 2 years ago

Finally I managed to get it work

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

quant-daddy commented 1 year ago

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 commented 8 months ago

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 commented 8 months ago

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

Youthleap423 commented 8 months ago

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 https://github.com/KjellConnelly/react-native-shared-group-preferences/issues/24#issuecomment-2003018964, or unsubscribe https://github.com/notifications/unsubscribe-auth/AIHFWCSRNGTUH7ZMVJXNFUTYY2CODAVCNFSM5C5OLMP2U5DIOJSWCZC7NNSXTN2JONZXKZKDN5WW2ZLOOQ5TEMBQGMYDCOBZGY2A . You are receiving this because you authored the thread.Message ID: <KjellConnelly/react-native-shared-group-preferences/issues/24/2003018964@ github.com>

naveedashfaq272 commented 8 months ago

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: <KjellConnelly/react-native-shared-group-preferences/issues/24/2003018964@ github.com>

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

naveedashfaq272 commented 8 months ago

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: <KjellConnelly/react-native-shared-group-preferences/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 commented 8 months ago

@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 commented 8 months ago

@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 commented 8 months ago

image Can you check this?

naveedashfaq272 commented 8 months ago

image Can you check this?

I checked but the issue is still same.

naveedashfaq272 commented 8 months ago

image Can you check this?

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

Youthleap423 commented 8 months ago

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

naveedashfaq272 commented 8 months ago

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.