question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

*CAREFUL* Your persisted values will be lost when running in the Background on iOS

See original GitHub issue

This is a great library for securily storing values, but it currently has a problem that might cause a lot of headaches to developers, specially if you already have an app running and add the Background Fetch capability into the app and start using it with libraries like react-native-background-fetch and react-native-background-timer both of which will execute operations in the background (e.g: when the phone is locked)

If your background processes interact with the Keychain, you’ll completely loose those values if you try to update them when the app is running in the background. The reason for that is because the default keychain item accessibility is that items are only accessibible when the phone is unlocked, and this library currently uses the default accessibility when you pass your key/value pair to setItem. So when you call setItem in the background, the library will first delete the existing value as can be seen here and then it’ll try to write the new value, but that’ll fail since it’s not using the proper accessibility level.

There’s a PR already opened here which increases the functionality of the library by allowing us as developers to customize the accessibility level to whatever we want. I think the maintainers should consider accepting the PR and releasing a new official version, specially considering the popularity of this library and also the impact that this behavior can silently cause in apps, which is very tricky to reproduce when you consider how background fetches are executed by iOS.

If the PR isn’t in the essense of how the maintainers believe the library should work, I think we should at least have a warning to this behavior added to the README section to prevent people from running into this issue in the future.

Issue Analytics

  • State:open
  • Created a year ago
  • Reactions:18
  • Comments:6

github_iconTop GitHub Comments

1reaction
wjeffersontpaduacommented, Dec 20, 2022

@jkelley79 I believe I’ve used react-native-background-timer to achieve that

0reactions
jkelley79commented, Dec 20, 2022

@wjeffersontpadua - I setup a timeout, locked the phone but the callback is not fired until I unlock the phone and/or relaunch the app. Seems like you would need a way to trigger the app to run in the background while the phone is locked to reproduce.

Read more comments on GitHub >

github_iconTop Results From Across the Web

iOS 16 - New Features - Apple
See all the latest features, enhancements, app updates, and more in iOS 16 for iPhone.
Read more >
iOS Interview Questions Part 5: Core Data | by Chetan Aggarwal
No, Core Data is a framework for managing an object graph. SQLite is a relational database. SQLite is a database while Core Data...
Read more >
Data collection, retention, and storage in Application Insights
For webpages, open your browser's debugging window. Select F12 and open the Network tab. Screenshot that shows the open Network tab. Can I...
Read more >
The activity lifecycle | Android Developers
An Activity is an application component that provides a screen with which users can interact in order to do something, such as dial...
Read more >
What the Heck is Sign In with Apple? - Okta Developer
Thankfully, Apple adopted the existing open standards OAuth 2.0 and ... Then you'll use your app's configured values to create a URL that ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found