Skip to content

Commit 810e32a

Browse files
author
Krzysztof
authored
feat(iOS): Toggle backup feature (#455)
1 parent 2f504f3 commit 810e32a

File tree

8 files changed

+79
-52
lines changed

8 files changed

+79
-52
lines changed

example/ios/AsyncStorageExample/Info.plist

+2
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
33
<plist version="1.0">
44
<dict>
5+
<key>RCTAsyncStorageExcludeFromBackup</key>
6+
<true/>
57
<key>CFBundleDevelopmentRegion</key>
68
<string>en</string>
79
<key>CFBundleDisplayName</key>

ios/RNCAsyncStorage.m

+28
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,26 @@
3434
}
3535
}
3636

37+
static BOOL RCTAsyncStorageSetExcludedFromBackup(NSString* path, NSNumber* isExcluded)
38+
{
39+
NSFileManager *fileManager = [[NSFileManager alloc] init];
40+
41+
BOOL isDir;
42+
BOOL exists = [fileManager fileExistsAtPath:path isDirectory:&isDir];
43+
BOOL success = false;
44+
45+
if (isDir && exists) {
46+
NSURL* pathUrl = [NSURL fileURLWithPath:path];
47+
NSError *error = nil;
48+
success = [pathUrl setResourceValue:isExcluded forKey:NSURLIsExcludedFromBackupKey error:&error];
49+
50+
if (!success) {
51+
NSLog(@"Could not exclude AsyncStorage dir from backup %@", error);
52+
}
53+
}
54+
return success;
55+
}
56+
3757
static void RCTAppendError(NSDictionary *error, NSMutableArray<NSDictionary *> **errors)
3858
{
3959
if (error && errors) {
@@ -393,6 +413,14 @@ - (NSDictionary *)_ensureSetup
393413
}
394414

395415
if (!_haveSetup) {
416+
// iCloud backup exclusion
417+
NSNumber* isExcludedFromBackup = [[NSBundle mainBundle] objectForInfoDictionaryKey:@"RCTAsyncStorageExcludeFromBackup"];
418+
if (isExcludedFromBackup == nil) {
419+
// by default, we want to exclude AsyncStorage data from backup
420+
isExcludedFromBackup = @YES;
421+
}
422+
RCTAsyncStorageSetExcludedFromBackup(RCTCreateStorageDirectoryPath(RCTStorageDirectory), isExcludedFromBackup);
423+
396424
NSDictionary *errorOut = nil;
397425
NSString *serialized = RCTReadFile(RCTCreateStorageDirectoryPath(RCTGetManifestFilePath()), RCTManifestFileName, &errorOut);
398426
if (!serialized) {

website/docs/advanced/Backup.md

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
---
2+
id: backup
3+
title: Database backup exclusion
4+
sidebar_label: iCloud backup
5+
---
6+
import PlatformSupport from "../../src/components/Platform.js"
7+
8+
**Supported platforms:**
9+
<PlatformSupport title="iOS/MacOS" platformIcon="icon_ios.svg" />
10+
11+
---
12+
13+
Async Storage stores data in `Application Support` directory, which is backed up by iCloud by default.
14+
This can lead to unintentional behavior where data is persisted even after an app re-installation.
15+
16+
Async Storage disables that feature by default.
17+
18+
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).
19+
20+
Alternatively, you can open `info.plist` in editor and add new entry:
21+
```diff
22+
+ <key>RCTAsyncStorageExcludeFromBackup</key>
23+
+ <false/>
24+
```

website/docs/advanced/BrownfieldIntegration.md

+1-17
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ id: brownfield
33
title: Brownfield integration
44
sidebar_label: Brownfield integration
55
---
6+
import PlatformSupport from "../../src/components/Platform.js"
67

78
**Supported platforms:**
89
<PlatformSupport title="iOS/MacOS" platformIcon="icon_ios.svg"></PlatformSupport>
@@ -109,20 +110,3 @@ Called by `getItem` and `multiGet` in JS.
109110
**Optional:** Returns whether the delegate should be treated as a passthrough.
110111
This is useful for monitoring storage usage among other things. Returns `NO` by
111112
default.
112-
113-
114-
<!-- ------------------------ COMPONENTS ------------------------ -->
115-
116-
export const PlatformSupport = ({platformIcon, title}) => (
117-
<div style={{
118-
display: 'flex',
119-
margin: '10px 20px',
120-
alignItems: 'center',
121-
flexDirection: 'row'
122-
}}>
123-
<img
124-
style={{width: 34, height: 34}}
125-
src={`/async-storage/img/${platformIcon}`} />
126-
<p style={{margin: '0 0 0 10px', padding: 0}}>{title}</p>
127-
</div>
128-
);

website/docs/advanced/DedicatedExecutor.md

+1-16
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ id: executor
33
title: Dedicator Thread Executor
44
sidebar_label: Dedicated Executor
55
---
6+
import PlatformSupport from "../../src/components/Platform.js"
67

78
**Supported platforms:**
89
<PlatformSupport title="Android" platformIcon="icon_android.svg"></PlatformSupport>
@@ -27,19 +28,3 @@ Add a `AsyncStorage_dedicatedExecutor` property to your `android/gradle.properti
2728
```
2829
AsyncStorage_dedicatedExecutor=true
2930
```
30-
31-
<!-- ------------------------ COMPONENTS ------------------------ -->
32-
33-
export const PlatformSupport = ({platformIcon, title}) => (
34-
<div style={{
35-
display: 'flex',
36-
margin: '10px 20px',
37-
alignItems: 'center',
38-
flexDirection: 'row'
39-
}}>
40-
<img
41-
style={{width: 34, height: 34}}
42-
src={`/async-storage/img/${platformIcon}`} />
43-
<p style={{margin: '0 0 0 10px', padding: 0}}>{title}</p>
44-
</div>
45-
);

website/docs/advanced/IncreaseDbSize.md

+1-17
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ id: db_size
33
title: Increasing Storage size
44
sidebar_label: Storage space increase
55
---
6-
6+
import PlatformSupport from "../../src/components/Platform.js"
77

88
**Supported platforms:**
99
<PlatformSupport title="Android" platformIcon="icon_android.svg"></PlatformSupport>
@@ -21,19 +21,3 @@ AsyncStorage_db_size_in_MB=10
2121
```
2222

2323
Now you can define the new size in MB. In this example, the new limit is 10 MB.
24-
25-
<!-- ------------------------ COMPONENTS ------------------------ -->
26-
27-
export const PlatformSupport = ({platformIcon, title}) => (
28-
<div style={{
29-
display: 'flex',
30-
margin: '10px 20px',
31-
alignItems: 'center',
32-
flexDirection: 'row'
33-
}}>
34-
<img
35-
style={{width: 34, height: 34}}
36-
src={`/async-storage/img/${platformIcon}`} />
37-
<p style={{margin: '0 0 0 10px', padding: 0}}>{title}</p>
38-
</div>
39-
);

website/sidebars.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
module.exports = {
22
docs: {
33
'Getting started': ['install', 'usage', 'link', 'api'],
4-
Advanced: ['advanced/jest', 'advanced/brownfield', 'advanced/executor', 'advanced/db_size'],
5-
Help: ['help/troubleshooting']
4+
Advanced: ['advanced/jest', 'advanced/brownfield', 'advanced/backup', 'advanced/executor', 'advanced/db_size'],
5+
Help: ['help/troubleshooting'],
66
},
77
};

website/src/components/Platform.js

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import React from "react";
2+
3+
const PlatformSupport = ({ platformIcon, title }) => (
4+
<div
5+
style={{
6+
display: "flex",
7+
margin: "10px 20px",
8+
alignItems: "center",
9+
flexDirection: "row"
10+
}}
11+
>
12+
<img
13+
style={{ width: 34, height: 34 }}
14+
src={`/async-storage/img/${platformIcon}`}
15+
/>
16+
<p style={{ margin: "0 0 0 10px", padding: 0 }}>{title}</p>
17+
</div>
18+
);
19+
20+
export default PlatformSupport;

0 commit comments

Comments
 (0)