@bacons/apple-targets 3.0.0 → 3.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md
CHANGED
|
@@ -388,6 +388,8 @@ ExtensionStorage.reloadWidget();
|
|
|
388
388
|
|
|
389
389
|
- `set(key: string, value: string | number | Record<string, string | number> | Array<Record<string, string | number>> | undefined): void` - Sets a value in the shared storage for a given key. Setting `undefined` will remove the key.
|
|
390
390
|
- `ExtensionStorage.reloadWidget(name?: string): void` - A static method for reloading the widget. Behind the scenes, this calls `WidgetCenter.shared.reloadAllTimelines()`. If given a name, it will reload a specific widget using `WidgetCenter.shared.reloadTimelines(ofKind: timeline)`.
|
|
391
|
+
- `remove(key: string): void` - A method for removing the key from the shared storage.
|
|
392
|
+
- `get(key: string): string | null` - A static method for getting the value from the shared storage.
|
|
391
393
|
|
|
392
394
|
### Accessing shared data
|
|
393
395
|
|
|
@@ -3,4 +3,6 @@ export declare class ExtensionStorage {
|
|
|
3
3
|
static reloadWidget(name?: string): void;
|
|
4
4
|
constructor(appGroup: string);
|
|
5
5
|
set(key: string, value?: string | number | Record<string, string | number> | Array<Record<string, string | number>>): void;
|
|
6
|
+
get(key: string): string | null;
|
|
7
|
+
remove(key: string): void;
|
|
6
8
|
}
|
|
@@ -7,10 +7,11 @@ const ExtensionStorageModule = (_a = expo === null || expo === void 0 ? void 0 :
|
|
|
7
7
|
const nativeModule = ExtensionStorageModule !== null && ExtensionStorageModule !== void 0 ? ExtensionStorageModule : {
|
|
8
8
|
setInt() { },
|
|
9
9
|
setString() { },
|
|
10
|
-
reloadWidget() { },
|
|
11
10
|
setObject() { },
|
|
12
|
-
remove() { },
|
|
13
11
|
setArray() { },
|
|
12
|
+
reloadWidget() { },
|
|
13
|
+
get() { },
|
|
14
|
+
remove() { },
|
|
14
15
|
};
|
|
15
16
|
const originalSetObject = nativeModule.setObject;
|
|
16
17
|
// Sweet API doesn't support doing this natively.
|
|
@@ -44,5 +45,11 @@ class ExtensionStorage {
|
|
|
44
45
|
nativeModule.setObject(key, value, this.appGroup);
|
|
45
46
|
}
|
|
46
47
|
}
|
|
48
|
+
get(key) {
|
|
49
|
+
return nativeModule.get(key, this.appGroup);
|
|
50
|
+
}
|
|
51
|
+
remove(key) {
|
|
52
|
+
nativeModule.remove(key, this.appGroup);
|
|
53
|
+
}
|
|
47
54
|
}
|
|
48
55
|
exports.ExtensionStorage = ExtensionStorage;
|
|
@@ -48,6 +48,24 @@ public class ExtensionStorageModule: Module {
|
|
|
48
48
|
Function("setString") { (key: String, value: String, group: String?) in
|
|
49
49
|
let userDefaults = UserDefaults(suiteName: group)
|
|
50
50
|
userDefaults?.set(value, forKey: key)
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
Function("get") { (key: String, group: String?) -> String? in
|
|
54
|
+
let userDefaults = UserDefaults(suiteName: group)
|
|
55
|
+
if let data = userDefaults?.data(forKey: key) {
|
|
56
|
+
do {
|
|
57
|
+
let jsonObject = try JSONSerialization.jsonObject(with: data, options: [])
|
|
58
|
+
let jsonData = try JSONSerialization.data(withJSONObject: jsonObject, options: [.prettyPrinted])
|
|
59
|
+
return String(data: jsonData, encoding: .utf8)
|
|
60
|
+
} catch {
|
|
61
|
+
return nil
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
if let value = userDefaults?.object(forKey: key) {
|
|
66
|
+
return String(describing: value)
|
|
67
|
+
}
|
|
68
|
+
return nil
|
|
51
69
|
}
|
|
52
70
|
}
|
|
53
71
|
}
|