diff --git a/example/ios/AsyncStorageExample/Info.plist b/example/ios/AsyncStorageExample/Info.plist index 7ac62b4f..5135a604 100644 --- a/example/ios/AsyncStorageExample/Info.plist +++ b/example/ios/AsyncStorageExample/Info.plist @@ -2,6 +2,8 @@ + RCTAsyncStorageExcludeFromBackup + CFBundleDevelopmentRegion en CFBundleDisplayName diff --git a/ios/RNCAsyncStorage.m b/ios/RNCAsyncStorage.m index 8b20cc2f..6a268fb7 100644 --- a/ios/RNCAsyncStorage.m +++ b/ios/RNCAsyncStorage.m @@ -34,6 +34,26 @@ } } +static BOOL RCTAsyncStorageSetExcludedFromBackup(NSString* path, NSNumber* isExcluded) +{ + NSFileManager *fileManager = [[NSFileManager alloc] init]; + + BOOL isDir; + BOOL exists = [fileManager fileExistsAtPath:path isDirectory:&isDir]; + BOOL success = false; + + if (isDir && exists) { + NSURL* pathUrl = [NSURL fileURLWithPath:path]; + NSError *error = nil; + success = [pathUrl setResourceValue:isExcluded forKey:NSURLIsExcludedFromBackupKey error:&error]; + + if (!success) { + NSLog(@"Could not exclude AsyncStorage dir from backup %@", error); + } + } + return success; +} + static void RCTAppendError(NSDictionary *error, NSMutableArray **errors) { if (error && errors) { @@ -393,6 +413,14 @@ - (NSDictionary *)_ensureSetup } if (!_haveSetup) { + // iCloud backup exclusion + NSNumber* isExcludedFromBackup = [[NSBundle mainBundle] objectForInfoDictionaryKey:@"RCTAsyncStorageExcludeFromBackup"]; + if (isExcludedFromBackup == nil) { + // by default, we want to exclude AsyncStorage data from backup + isExcludedFromBackup = @YES; + } + RCTAsyncStorageSetExcludedFromBackup(RCTCreateStorageDirectoryPath(RCTStorageDirectory), isExcludedFromBackup); + NSDictionary *errorOut = nil; NSString *serialized = RCTReadFile(RCTCreateStorageDirectoryPath(RCTGetManifestFilePath()), RCTManifestFileName, &errorOut); if (!serialized) { diff --git a/website/docs/advanced/Backup.md b/website/docs/advanced/Backup.md new file mode 100644 index 00000000..a7dcc67f --- /dev/null +++ b/website/docs/advanced/Backup.md @@ -0,0 +1,24 @@ +--- +id: backup +title: Database backup exclusion +sidebar_label: iCloud backup +--- +import PlatformSupport from "../../src/components/Platform.js" + +**Supported platforms:** + + +--- + +Async Storage stores data in `Application Support` directory, which is backed up by iCloud by default. +This can lead to unintentional behavior where data is persisted even after an app re-installation. + +Async Storage disables that feature by default. + +In order to enable iCloud backup, open your app's `info.plist` in Xcode and add **boolean** entry called **RCTAsyncStorageExcludeFromBackup** and set its value to **NO** (NO as no for exclusion). + +Alternatively, you can open `info.plist` in editor and add new entry: +```diff ++ RCTAsyncStorageExcludeFromBackup ++ +``` diff --git a/website/docs/advanced/BrownfieldIntegration.md b/website/docs/advanced/BrownfieldIntegration.md index e4a6f692..ee40df01 100644 --- a/website/docs/advanced/BrownfieldIntegration.md +++ b/website/docs/advanced/BrownfieldIntegration.md @@ -3,6 +3,7 @@ id: brownfield title: Brownfield integration sidebar_label: Brownfield integration --- +import PlatformSupport from "../../src/components/Platform.js" **Supported platforms:** @@ -109,20 +110,3 @@ Called by `getItem` and `multiGet` in JS. **Optional:** Returns whether the delegate should be treated as a passthrough. This is useful for monitoring storage usage among other things. Returns `NO` by default. - - - - -export const PlatformSupport = ({platformIcon, title}) => ( -
- -

{title}

-
- ); diff --git a/website/docs/advanced/DedicatedExecutor.md b/website/docs/advanced/DedicatedExecutor.md index 197309f5..eed6cba6 100644 --- a/website/docs/advanced/DedicatedExecutor.md +++ b/website/docs/advanced/DedicatedExecutor.md @@ -3,6 +3,7 @@ id: executor title: Dedicator Thread Executor sidebar_label: Dedicated Executor --- +import PlatformSupport from "../../src/components/Platform.js" **Supported platforms:** @@ -27,19 +28,3 @@ Add a `AsyncStorage_dedicatedExecutor` property to your `android/gradle.properti ``` AsyncStorage_dedicatedExecutor=true ``` - - - -export const PlatformSupport = ({platformIcon, title}) => ( -
- -

{title}

-
- ); diff --git a/website/docs/advanced/IncreaseDbSize.md b/website/docs/advanced/IncreaseDbSize.md index 349ee30d..4ffadb05 100644 --- a/website/docs/advanced/IncreaseDbSize.md +++ b/website/docs/advanced/IncreaseDbSize.md @@ -3,7 +3,7 @@ id: db_size title: Increasing Storage size sidebar_label: Storage space increase --- - +import PlatformSupport from "../../src/components/Platform.js" **Supported platforms:** @@ -21,19 +21,3 @@ AsyncStorage_db_size_in_MB=10 ``` Now you can define the new size in MB. In this example, the new limit is 10 MB. - - - -export const PlatformSupport = ({platformIcon, title}) => ( -
- -

{title}

-
- ); diff --git a/website/sidebars.js b/website/sidebars.js index 5c16ecb0..3646e727 100644 --- a/website/sidebars.js +++ b/website/sidebars.js @@ -1,7 +1,7 @@ module.exports = { docs: { 'Getting started': ['install', 'usage', 'link', 'api'], - Advanced: ['advanced/jest', 'advanced/brownfield', 'advanced/executor', 'advanced/db_size'], - Help: ['help/troubleshooting'] + Advanced: ['advanced/jest', 'advanced/brownfield', 'advanced/backup', 'advanced/executor', 'advanced/db_size'], + Help: ['help/troubleshooting'], }, }; diff --git a/website/src/components/Platform.js b/website/src/components/Platform.js new file mode 100644 index 00000000..a69afff4 --- /dev/null +++ b/website/src/components/Platform.js @@ -0,0 +1,20 @@ +import React from "react"; + +const PlatformSupport = ({ platformIcon, title }) => ( +
+ +

{title}

+
+); + +export default PlatformSupport;