Skip to content

feat(iOS): Toggle backup feature #455

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

Merged
merged 6 commits into from
Oct 21, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions example/ios/AsyncStorageExample/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>RCTAsyncStorageExcludeFromBackup</key>
<true/>
<key>CFBundleDevelopmentRegion</key>
<string>en</string>
<key>CFBundleDisplayName</key>
Expand Down
28 changes: 28 additions & 0 deletions ios/RNCAsyncStorage.m
Original file line number Diff line number Diff line change
Expand Up @@ -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<NSDictionary *> **errors)
{
if (error && errors) {
Expand Down Expand Up @@ -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) {
Expand Down
24 changes: 24 additions & 0 deletions website/docs/advanced/Backup.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
---
id: backup
title: Database backup exclusion
sidebar_label: iCloud backup
---
import PlatformSupport from "../../src/components/Platform.js"

**Supported platforms:**
<PlatformSupport title="iOS/MacOS" platformIcon="icon_ios.svg" />

---

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
+ <key>RCTAsyncStorageExcludeFromBackup</key>
+ <false/>
```
18 changes: 1 addition & 17 deletions website/docs/advanced/BrownfieldIntegration.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ id: brownfield
title: Brownfield integration
sidebar_label: Brownfield integration
---
import PlatformSupport from "../../src/components/Platform.js"

**Supported platforms:**
<PlatformSupport title="iOS/MacOS" platformIcon="icon_ios.svg"></PlatformSupport>
Expand Down Expand Up @@ -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.


<!-- ------------------------ COMPONENTS ------------------------ -->

export const PlatformSupport = ({platformIcon, title}) => (
<div style={{
display: 'flex',
margin: '10px 20px',
alignItems: 'center',
flexDirection: 'row'
}}>
<img
style={{width: 34, height: 34}}
src={`/async-storage/img/${platformIcon}`} />
<p style={{margin: '0 0 0 10px', padding: 0}}>{title}</p>
</div>
);
17 changes: 1 addition & 16 deletions website/docs/advanced/DedicatedExecutor.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ id: executor
title: Dedicator Thread Executor
sidebar_label: Dedicated Executor
---
import PlatformSupport from "../../src/components/Platform.js"

**Supported platforms:**
<PlatformSupport title="Android" platformIcon="icon_android.svg"></PlatformSupport>
Expand All @@ -27,19 +28,3 @@ Add a `AsyncStorage_dedicatedExecutor` property to your `android/gradle.properti
```
AsyncStorage_dedicatedExecutor=true
```

<!-- ------------------------ COMPONENTS ------------------------ -->

export const PlatformSupport = ({platformIcon, title}) => (
<div style={{
display: 'flex',
margin: '10px 20px',
alignItems: 'center',
flexDirection: 'row'
}}>
<img
style={{width: 34, height: 34}}
src={`/async-storage/img/${platformIcon}`} />
<p style={{margin: '0 0 0 10px', padding: 0}}>{title}</p>
</div>
);
18 changes: 1 addition & 17 deletions website/docs/advanced/IncreaseDbSize.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:**
<PlatformSupport title="Android" platformIcon="icon_android.svg"></PlatformSupport>
Expand All @@ -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.

<!-- ------------------------ COMPONENTS ------------------------ -->

export const PlatformSupport = ({platformIcon, title}) => (
<div style={{
display: 'flex',
margin: '10px 20px',
alignItems: 'center',
flexDirection: 'row'
}}>
<img
style={{width: 34, height: 34}}
src={`/async-storage/img/${platformIcon}`} />
<p style={{margin: '0 0 0 10px', padding: 0}}>{title}</p>
</div>
);
4 changes: 2 additions & 2 deletions website/sidebars.js
Original file line number Diff line number Diff line change
@@ -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'],
},
};
20 changes: 20 additions & 0 deletions website/src/components/Platform.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import React from "react";

const PlatformSupport = ({ platformIcon, title }) => (
<div
style={{
display: "flex",
margin: "10px 20px",
alignItems: "center",
flexDirection: "row"
}}
>
<img
style={{ width: 34, height: 34 }}
src={`/async-storage/img/${platformIcon}`}
/>
<p style={{ margin: "0 0 0 10px", padding: 0 }}>{title}</p>
</div>
);

export default PlatformSupport;