-
Notifications
You must be signed in to change notification settings - Fork 472
Added the ability to set the storage location on iOS #18
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
Conversation
Hey @adamivancza, thank you for your input! I'm going to hold off merging this PR till I finish #15 - I'd love to have some tests on new functionality, hope you don't mind waiting. |
@adamivancza Hey, Also, we don't have generated docs from comments yet, so could you please add this method to Thanks a lot |
thx @krizzu - will do those over the weekend. |
ios/RNCAsyncStorage.m
Outdated
@@ -16,9 +16,25 @@ | |||
#import "RCTLog.h" | |||
#import "RCTUtils.h" | |||
|
|||
typedef NS_ENUM(NSInteger, RCTStorageLocation) { | |||
Documents, | |||
ApplicationSupport |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@krizzu Is this what we want? only support Documents
and ApplicationSupport
directories?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's been discussed in #13, where ApplicationSupport
is more safe to store app-specific data.
Do you have any suggestion if there should be more/less options to choose from?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@krizzu Oh, I scan those things, so now I think we may need to handle two things:
- Provide options for user to save data. (I suppose support three options,
Documents
,Library
,tmp
, https://developer.apple.com/library/archive/documentation/FileManagement/Conceptual/FileSystemProgrammingGuide/FileSystemOverview/FileSystemOverview.html#//apple_ref/doc/uid/TP40010672-CH2-SW1,tmp
is also meaningful IMO, provide temp storage). - Not backed up by iTunes. (For the
Application Support
directory, it would backed up by iTunes and iCloud, so if we use that, we need useNSURLIsExcludedFromBackupKey
for files we stored includes manifest file.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- not sure about tmp - do you have any use cases where it might be helpful? I think that would just cause confusion as tmp dir can be deleted deleted by OS at any time.
- maybe we can add a flag to control that? it could be useful to have this file backed up.
ios/RNCAsyncStorage.m
Outdated
@@ -455,4 +489,10 @@ - (NSDictionary *)_writeEntry:(NSArray<NSString *> *)entry changedManifest:(BOOL | |||
} | |||
} | |||
|
|||
RCT_EXPORT_METHOD(setStorageLocation:(RCTStorageLocation)location) | |||
{ | |||
storageLocation = location; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can have equal check in here.
ios/RNCAsyncStorage.m
Outdated
@@ -16,9 +16,25 @@ | |||
#import "RCTLog.h" | |||
#import "RCTUtils.h" | |||
|
|||
typedef NS_ENUM(NSInteger, RCTStorageLocation) { | |||
Documents, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
# Conflicts: # ios/RNCAsyncStorage.m
Sorry about this but I still haven't got time to finish up the tests - will try to find some time to do them. |
…act-native-async-storage # Conflicts: # ios/RNCAsyncStorage.m
…act-native-async-storage # Conflicts: # example/e2e/asyncstorage.e2e.js
hey @krizzu - finally finished with the PR! :) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks great 👏 I left two comments regarding some functionality. Please let me know what you think.
Also, I believe it'd be nice to document this feature and explain reasons why we added it.
thanks.
* Call this set the storage location. | ||
* @param storageLocation The storage location. Can be 'documents' or 'applicationSupport'. | ||
* | ||
* **Note**: changing this only sets the location for future actions and does not migrate |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This bit is bit worrying. We had similar issue #55, where storage location was changed and devs were losing data. Maybe we could come up with migration plan for data?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The default locations is still the same, imo devs can only loose data once updated to a new version which contains this change AND change the storage location specifically without copying their data.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see, thanks. We should provide a note in docs that this can happen, so they know upfront.
}, | ||
|
||
StorageLocationIOS: { | ||
documents: 'documents', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we could export constants to be used in JS, what do you think?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
oh yeah that's a great shout! will do that
Hey @adamivancza, thank you for your work so far 👏 We merged another PR which contains some native iOS code, I hope this won't give you much trouble. |
@krizzu There are some conflicting changes with my fix, mainly with |
Hey @adamivancza, Thank you so much for work you put into this PR, but I'm sorry to say that I'm going to close it. We're moving into Async Storage v2, where we do a lot of breaking changes. There's a plan to still support the current implementation of AS as another Backend Storage in v2 - maybe you'd like to take part in it? We plan to create it from the ground up, so I believe it'd best time to add additional functionality (not preset in AS before) thanks. |
#13
Moved my changes from this PR: https://github.com/facebook/react-native/pull/20904/files
I didn't find any tests in the repo atm so I wasn't able to add those. I can see a PR with detox tests though - if that's merged I can add some tests.