@capacitor/preferences 4.0.0-beta.0
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/CHANGELOG.md +299 -0
- package/CapacitorPreferences.podspec +17 -0
- package/LICENSE +23 -0
- package/README.md +259 -0
- package/android/build.gradle +57 -0
- package/android/src/main/AndroidManifest.xml +3 -0
- package/android/src/main/java/com/capacitorjs/plugins/preferences/Preferences.java +45 -0
- package/android/src/main/java/com/capacitorjs/plugins/preferences/PreferencesConfiguration.java +18 -0
- package/android/src/main/java/com/capacitorjs/plugins/preferences/PreferencesPlugin.java +129 -0
- package/dist/docs.json +348 -0
- package/dist/esm/definitions.d.ts +135 -0
- package/dist/esm/definitions.js +2 -0
- package/dist/esm/definitions.js.map +1 -0
- package/dist/esm/index.d.ts +4 -0
- package/dist/esm/index.js +7 -0
- package/dist/esm/index.js.map +1 -0
- package/dist/esm/web.d.ts +17 -0
- package/dist/esm/web.js +71 -0
- package/dist/esm/web.js.map +1 -0
- package/dist/plugin.cjs.js +87 -0
- package/dist/plugin.cjs.js.map +1 -0
- package/dist/plugin.js +90 -0
- package/dist/plugin.js.map +1 -0
- package/ios/Plugin/Info.plist +24 -0
- package/ios/Plugin/Preferences.swift +64 -0
- package/ios/Plugin/PreferencesPlugin.h +10 -0
- package/ios/Plugin/PreferencesPlugin.m +15 -0
- package/ios/Plugin/PreferencesPlugin.swift +106 -0
- package/package.json +83 -0
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,299 @@
|
|
|
1
|
+
# Change Log
|
|
2
|
+
|
|
3
|
+
All notable changes to this project will be documented in this file.
|
|
4
|
+
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
5
|
+
|
|
6
|
+
# 4.0.0-beta.0 (2022-06-27)
|
|
7
|
+
|
|
8
|
+
**Note:** Version bump only for package @capacitor/preferences
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
## [1.2.5](https://github.com/ionic-team/capacitor-plugins/compare/@capacitor/storage@1.2.4...@capacitor/storage@1.2.5) (2022-03-03)
|
|
15
|
+
|
|
16
|
+
**Note:** Version bump only for package @capacitor/storage
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
## [1.2.4](https://github.com/ionic-team/capacitor-plugins/compare/@capacitor/storage@1.2.3...@capacitor/storage@1.2.4) (2022-01-19)
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
### Bug Fixes
|
|
26
|
+
|
|
27
|
+
* inline source code in esm map files ([#760](https://github.com/ionic-team/capacitor-plugins/issues/760)) ([a960489](https://github.com/ionic-team/capacitor-plugins/commit/a960489a19db0182b90d187a50deff9dfbe51038))
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
## [1.2.3](https://github.com/ionic-team/capacitor-plugins/compare/@capacitor/storage@1.2.2...@capacitor/storage@1.2.3) (2021-11-03)
|
|
34
|
+
|
|
35
|
+
**Note:** Version bump only for package @capacitor/storage
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
## [1.2.2](https://github.com/ionic-team/capacitor-plugins/compare/@capacitor/storage@1.2.1...@capacitor/storage@1.2.2) (2021-10-14)
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
### Bug Fixes
|
|
45
|
+
|
|
46
|
+
* remove postpublish scripts ([#656](https://github.com/ionic-team/capacitor-plugins/issues/656)) ([ed6ac49](https://github.com/ionic-team/capacitor-plugins/commit/ed6ac499ebf4a47525071ccbfc36c27503e11f60))
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
## [1.2.1](https://github.com/ionic-team/capacitor-plugins/compare/@capacitor/storage@1.2.0...@capacitor/storage@1.2.1) (2021-10-13)
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
### Bug Fixes
|
|
56
|
+
|
|
57
|
+
* correct addListeners links ([#655](https://github.com/ionic-team/capacitor-plugins/issues/655)) ([f9871e7](https://github.com/ionic-team/capacitor-plugins/commit/f9871e7bd53478addb21155e148829f550c0e457))
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
# [1.2.0](https://github.com/ionic-team/capacitor-plugins/compare/@capacitor/storage@1.1.0...@capacitor/storage@1.2.0) (2021-09-15)
|
|
64
|
+
|
|
65
|
+
|
|
66
|
+
### Features
|
|
67
|
+
|
|
68
|
+
* **storage:** Add removeOld function ([#585](https://github.com/ionic-team/capacitor-plugins/issues/585)) ([698350e](https://github.com/ionic-team/capacitor-plugins/commit/698350e38a756abc90fb38212b8adfa890c77ce5))
|
|
69
|
+
|
|
70
|
+
|
|
71
|
+
|
|
72
|
+
|
|
73
|
+
|
|
74
|
+
# [1.1.0](https://github.com/ionic-team/capacitor-plugins/compare/@capacitor/storage@1.0.3...@capacitor/storage@1.1.0) (2021-09-01)
|
|
75
|
+
|
|
76
|
+
|
|
77
|
+
### Features
|
|
78
|
+
|
|
79
|
+
* **storage:** make StorageConfiguration init public ([#532](https://github.com/ionic-team/capacitor-plugins/issues/532)) ([4271b5d](https://github.com/ionic-team/capacitor-plugins/commit/4271b5d18a98201582bd95f41d5b5104c83e5b29))
|
|
80
|
+
|
|
81
|
+
|
|
82
|
+
|
|
83
|
+
|
|
84
|
+
|
|
85
|
+
## [1.0.3](https://github.com/ionic-team/capacitor-plugins/compare/@capacitor/storage@1.0.2...@capacitor/storage@1.0.3) (2021-07-07)
|
|
86
|
+
|
|
87
|
+
**Note:** Version bump only for package @capacitor/storage
|
|
88
|
+
|
|
89
|
+
|
|
90
|
+
|
|
91
|
+
|
|
92
|
+
|
|
93
|
+
## [1.0.2](https://github.com/ionic-team/capacitor-plugins/compare/@capacitor/storage@1.0.1...@capacitor/storage@1.0.2) (2021-06-23)
|
|
94
|
+
|
|
95
|
+
**Note:** Version bump only for package @capacitor/storage
|
|
96
|
+
|
|
97
|
+
|
|
98
|
+
|
|
99
|
+
|
|
100
|
+
|
|
101
|
+
## [1.0.1](https://github.com/ionic-team/capacitor-plugins/compare/@capacitor/storage@1.0.0...@capacitor/storage@1.0.1) (2021-06-09)
|
|
102
|
+
|
|
103
|
+
**Note:** Version bump only for package @capacitor/storage
|
|
104
|
+
|
|
105
|
+
|
|
106
|
+
|
|
107
|
+
|
|
108
|
+
|
|
109
|
+
# [1.0.0](https://github.com/ionic-team/capacitor-plugins/compare/@capacitor/storage@0.3.10...@capacitor/storage@1.0.0) (2021-05-19)
|
|
110
|
+
|
|
111
|
+
**Note:** Version bump only for package @capacitor/storage
|
|
112
|
+
|
|
113
|
+
|
|
114
|
+
|
|
115
|
+
|
|
116
|
+
|
|
117
|
+
## [0.3.10](https://github.com/ionic-team/capacitor-plugins/compare/@capacitor/storage@0.3.9...@capacitor/storage@0.3.10) (2021-05-11)
|
|
118
|
+
|
|
119
|
+
**Note:** Version bump only for package @capacitor/storage
|
|
120
|
+
|
|
121
|
+
|
|
122
|
+
|
|
123
|
+
|
|
124
|
+
|
|
125
|
+
## [0.3.9](https://github.com/ionic-team/capacitor-plugins/compare/@capacitor/storage@0.3.8...@capacitor/storage@0.3.9) (2021-05-10)
|
|
126
|
+
|
|
127
|
+
**Note:** Version bump only for package @capacitor/storage
|
|
128
|
+
|
|
129
|
+
|
|
130
|
+
|
|
131
|
+
|
|
132
|
+
|
|
133
|
+
## [0.3.8](https://github.com/ionic-team/capacitor-plugins/compare/@capacitor/storage@0.3.7...@capacitor/storage@0.3.8) (2021-05-07)
|
|
134
|
+
|
|
135
|
+
**Note:** Version bump only for package @capacitor/storage
|
|
136
|
+
|
|
137
|
+
|
|
138
|
+
|
|
139
|
+
|
|
140
|
+
|
|
141
|
+
## [0.3.7](https://github.com/ionic-team/capacitor-plugins/compare/@capacitor/storage@0.3.6...@capacitor/storage@0.3.7) (2021-04-29)
|
|
142
|
+
|
|
143
|
+
**Note:** Version bump only for package @capacitor/storage
|
|
144
|
+
|
|
145
|
+
|
|
146
|
+
|
|
147
|
+
|
|
148
|
+
|
|
149
|
+
## [0.3.6](https://github.com/ionic-team/capacitor-plugins/compare/@capacitor/storage@0.3.5...@capacitor/storage@0.3.6) (2021-03-10)
|
|
150
|
+
|
|
151
|
+
**Note:** Version bump only for package @capacitor/storage
|
|
152
|
+
|
|
153
|
+
|
|
154
|
+
|
|
155
|
+
|
|
156
|
+
|
|
157
|
+
## [0.3.5](https://github.com/ionic-team/capacitor-plugins/compare/@capacitor/storage@0.3.4...@capacitor/storage@0.3.5) (2021-03-02)
|
|
158
|
+
|
|
159
|
+
**Note:** Version bump only for package @capacitor/storage
|
|
160
|
+
|
|
161
|
+
|
|
162
|
+
|
|
163
|
+
|
|
164
|
+
|
|
165
|
+
## [0.3.4](https://github.com/ionic-team/capacitor-plugins/compare/@capacitor/storage@0.3.3...@capacitor/storage@0.3.4) (2021-02-27)
|
|
166
|
+
|
|
167
|
+
|
|
168
|
+
### Bug Fixes
|
|
169
|
+
|
|
170
|
+
* **storage:** configure doesn't resolve on Android and iOS ([#266](https://github.com/ionic-team/capacitor-plugins/issues/266)) ([4f51b24](https://github.com/ionic-team/capacitor-plugins/commit/4f51b24d18890ae207090304c153af6c0067fdff))
|
|
171
|
+
|
|
172
|
+
|
|
173
|
+
|
|
174
|
+
|
|
175
|
+
|
|
176
|
+
## [0.3.3](https://github.com/ionic-team/capacitor-plugins/compare/@capacitor/storage@0.3.2...@capacitor/storage@0.3.3) (2021-02-10)
|
|
177
|
+
|
|
178
|
+
**Note:** Version bump only for package @capacitor/storage
|
|
179
|
+
|
|
180
|
+
|
|
181
|
+
|
|
182
|
+
|
|
183
|
+
|
|
184
|
+
## [0.3.2](https://github.com/ionic-team/capacitor-plugins/compare/@capacitor/storage@0.3.1...@capacitor/storage@0.3.2) (2021-02-05)
|
|
185
|
+
|
|
186
|
+
**Note:** Version bump only for package @capacitor/storage
|
|
187
|
+
|
|
188
|
+
|
|
189
|
+
|
|
190
|
+
|
|
191
|
+
|
|
192
|
+
## [0.3.1](https://github.com/ionic-team/capacitor-plugins/compare/@capacitor/storage@0.3.0...@capacitor/storage@0.3.1) (2021-01-26)
|
|
193
|
+
|
|
194
|
+
**Note:** Version bump only for package @capacitor/storage
|
|
195
|
+
|
|
196
|
+
|
|
197
|
+
|
|
198
|
+
|
|
199
|
+
|
|
200
|
+
# [0.3.0](https://github.com/ionic-team/capacitor-plugins/compare/@capacitor/storage@0.2.0...@capacitor/storage@0.3.0) (2021-01-14)
|
|
201
|
+
|
|
202
|
+
**Note:** Version bump only for package @capacitor/storage
|
|
203
|
+
|
|
204
|
+
|
|
205
|
+
|
|
206
|
+
|
|
207
|
+
|
|
208
|
+
# [0.2.0](https://github.com/ionic-team/capacitor-plugins/compare/@capacitor/storage@0.1.4...@capacitor/storage@0.2.0) (2021-01-13)
|
|
209
|
+
|
|
210
|
+
|
|
211
|
+
### Bug Fixes
|
|
212
|
+
|
|
213
|
+
* add es2017 lib to tsconfig ([#180](https://github.com/ionic-team/capacitor-plugins/issues/180)) ([2c3776c](https://github.com/ionic-team/capacitor-plugins/commit/2c3776c38ca025c5ee965dec10ccf1cdb6c02e2f))
|
|
214
|
+
|
|
215
|
+
|
|
216
|
+
### Features
|
|
217
|
+
|
|
218
|
+
* add commonjs output format ([#179](https://github.com/ionic-team/capacitor-plugins/issues/179)) ([8e9e098](https://github.com/ionic-team/capacitor-plugins/commit/8e9e09862064b3f6771d7facbc4008e995d9b463))
|
|
219
|
+
|
|
220
|
+
|
|
221
|
+
|
|
222
|
+
|
|
223
|
+
|
|
224
|
+
## [0.1.4](https://github.com/ionic-team/capacitor-plugins/compare/@capacitor/storage@0.1.3...@capacitor/storage@0.1.4) (2021-01-13)
|
|
225
|
+
|
|
226
|
+
**Note:** Version bump only for package @capacitor/storage
|
|
227
|
+
|
|
228
|
+
|
|
229
|
+
|
|
230
|
+
|
|
231
|
+
|
|
232
|
+
## [0.1.3](https://github.com/ionic-team/capacitor-plugins/compare/@capacitor/storage@0.1.2...@capacitor/storage@0.1.3) (2021-01-08)
|
|
233
|
+
|
|
234
|
+
**Note:** Version bump only for package @capacitor/storage
|
|
235
|
+
|
|
236
|
+
|
|
237
|
+
|
|
238
|
+
|
|
239
|
+
|
|
240
|
+
## [0.1.2](https://github.com/ionic-team/capacitor-plugins/compare/@capacitor/storage@0.1.1...@capacitor/storage@0.1.2) (2020-12-27)
|
|
241
|
+
|
|
242
|
+
**Note:** Version bump only for package @capacitor/storage
|
|
243
|
+
|
|
244
|
+
|
|
245
|
+
|
|
246
|
+
|
|
247
|
+
|
|
248
|
+
## [0.1.1](https://github.com/ionic-team/capacitor-plugins/compare/@capacitor/storage@0.1.0...@capacitor/storage@0.1.1) (2020-12-20)
|
|
249
|
+
|
|
250
|
+
|
|
251
|
+
### Bug Fixes
|
|
252
|
+
|
|
253
|
+
* support deprecated types from Capacitor 2 ([#139](https://github.com/ionic-team/capacitor-plugins/issues/139)) ([2d7127a](https://github.com/ionic-team/capacitor-plugins/commit/2d7127a488e26f0287951921a6db47c49d817336))
|
|
254
|
+
|
|
255
|
+
|
|
256
|
+
|
|
257
|
+
|
|
258
|
+
|
|
259
|
+
# [0.1.0](https://github.com/ionic-team/capacitor-plugins/compare/@capacitor/storage@0.0.3...@capacitor/storage@0.1.0) (2020-12-02)
|
|
260
|
+
|
|
261
|
+
**Note:** Version bump only for package @capacitor/storage
|
|
262
|
+
|
|
263
|
+
|
|
264
|
+
|
|
265
|
+
|
|
266
|
+
|
|
267
|
+
## [0.0.3](https://github.com/ionic-team/capacitor-plugins/compare/@capacitor/storage@0.0.2...@capacitor/storage@0.0.3) (2020-10-30)
|
|
268
|
+
|
|
269
|
+
|
|
270
|
+
### Bug Fixes
|
|
271
|
+
|
|
272
|
+
* **storage:** Remove warning on getString usage ([#85](https://github.com/ionic-team/capacitor-plugins/issues/85)) ([db9c9c0](https://github.com/ionic-team/capacitor-plugins/commit/db9c9c0d6743488e13c86e3b4efd192b4a28a193))
|
|
273
|
+
|
|
274
|
+
|
|
275
|
+
|
|
276
|
+
|
|
277
|
+
|
|
278
|
+
## [0.0.2](https://github.com/ionic-team/capacitor-plugins/compare/@capacitor/storage@0.0.1...@capacitor/storage@0.0.2) (2020-10-12)
|
|
279
|
+
|
|
280
|
+
|
|
281
|
+
### Bug Fixes
|
|
282
|
+
|
|
283
|
+
* better ignore rules for npm distribution ([#32](https://github.com/ionic-team/capacitor-plugins/issues/32)) ([b8d55b9](https://github.com/ionic-team/capacitor-plugins/commit/b8d55b9233e4ad7b8a1cd41110b4e580fc2a059f))
|
|
284
|
+
|
|
285
|
+
|
|
286
|
+
|
|
287
|
+
|
|
288
|
+
|
|
289
|
+
## 0.0.1 (2020-09-01)
|
|
290
|
+
|
|
291
|
+
|
|
292
|
+
### Bug Fixes
|
|
293
|
+
|
|
294
|
+
* use correct package in manifest files ([#22](https://github.com/ionic-team/capacitor-plugins/issues/22)) ([ab62987](https://github.com/ionic-team/capacitor-plugins/commit/ab629877e1951f944594f1b23e1bffefcbc783dd))
|
|
295
|
+
|
|
296
|
+
|
|
297
|
+
### Features
|
|
298
|
+
|
|
299
|
+
* Storage plugin ([#15](https://github.com/ionic-team/capacitor-plugins/issues/15)) ([9dfdd85](https://github.com/ionic-team/capacitor-plugins/commit/9dfdd85b39c0df90db416a4bed094d03640fbe34))
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
require 'json'
|
|
2
|
+
|
|
3
|
+
package = JSON.parse(File.read(File.join(__dir__, 'package.json')))
|
|
4
|
+
|
|
5
|
+
Pod::Spec.new do |s|
|
|
6
|
+
s.name = 'CapacitorPreferences'
|
|
7
|
+
s.version = package['version']
|
|
8
|
+
s.summary = package['description']
|
|
9
|
+
s.license = package['license']
|
|
10
|
+
s.homepage = 'https://capacitorjs.com'
|
|
11
|
+
s.author = package['author']
|
|
12
|
+
s.source = { :git => 'https://github.com/ionic-team/capacitor-plugins.git', :tag => package['name'] + '@' + package['version'] }
|
|
13
|
+
s.source_files = 'ios/Plugin/**/*.{swift,h,m,c,cc,mm,cpp}', 'preferences/ios/Plugin/**/*.{swift,h,m,c,cc,mm,cpp}'
|
|
14
|
+
s.ios.deployment_target = '13.0'
|
|
15
|
+
s.dependency 'Capacitor'
|
|
16
|
+
s.swift_version = '5.1'
|
|
17
|
+
end
|
package/LICENSE
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
Copyright 2020-present Ionic
|
|
2
|
+
https://ionic.io
|
|
3
|
+
|
|
4
|
+
MIT License
|
|
5
|
+
|
|
6
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
|
7
|
+
a copy of this software and associated documentation files (the
|
|
8
|
+
"Software"), to deal in the Software without restriction, including
|
|
9
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
|
10
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
|
11
|
+
permit persons to whom the Software is furnished to do so, subject to
|
|
12
|
+
the following conditions:
|
|
13
|
+
|
|
14
|
+
The above copyright notice and this permission notice shall be
|
|
15
|
+
included in all copies or substantial portions of the Software.
|
|
16
|
+
|
|
17
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
18
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
19
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
20
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
|
21
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
|
22
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
|
23
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,259 @@
|
|
|
1
|
+
# @capacitor/preferences
|
|
2
|
+
|
|
3
|
+
The Preferences API provides a simple key/value persistent store for lightweight data.
|
|
4
|
+
|
|
5
|
+
Mobile OSs may periodically clear data set in `window.localStorage`, so this
|
|
6
|
+
API should be used instead. This API will fall back to using `localStorage`
|
|
7
|
+
when running as a Progressive Web App.
|
|
8
|
+
|
|
9
|
+
This plugin will use
|
|
10
|
+
[`UserDefaults`](https://developer.apple.com/documentation/foundation/userdefaults)
|
|
11
|
+
on iOS and
|
|
12
|
+
[`SharedPreferences`](https://developer.android.com/reference/android/content/SharedPreferences)
|
|
13
|
+
on Android. Stored data is cleared if the app is uninstalled.
|
|
14
|
+
|
|
15
|
+
**Note**: This API is _not_ meant to be used as a local database. If your app
|
|
16
|
+
stores a lot of data, has high read/write load, or requires complex querying,
|
|
17
|
+
we recommend taking a look at a SQLite-based solution. One such solution is [Ionic Secure Storage](https://ionic.io/docs/secure-storage), a SQLite-based engine with full encryption support. The [Capacitor Community](https://github.com/capacitor-community/) has also built a number of other storage engines.
|
|
18
|
+
|
|
19
|
+
## Install
|
|
20
|
+
|
|
21
|
+
```bash
|
|
22
|
+
npm install @capacitor/preferences
|
|
23
|
+
npx cap sync
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
## Example
|
|
27
|
+
|
|
28
|
+
```typescript
|
|
29
|
+
import { Preferences } from '@capacitor/preferences';
|
|
30
|
+
|
|
31
|
+
const setName = async () => {
|
|
32
|
+
await Preferences.set({
|
|
33
|
+
key: 'name',
|
|
34
|
+
value: 'Max',
|
|
35
|
+
});
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
const checkName = async () => {
|
|
39
|
+
const { value } = await Preferences.get({ key: 'name' });
|
|
40
|
+
|
|
41
|
+
console.log(`Hello ${value}!`);
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
const removeName = async () => {
|
|
45
|
+
await Preferences.remove({ key: 'name' });
|
|
46
|
+
};
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
## Working with JSON
|
|
50
|
+
|
|
51
|
+
The Preferences API only supports string values. You can, however, use JSON if you `JSON.stringify` the object before calling `set()`, then `JSON.parse` the value returned from `get()`.
|
|
52
|
+
|
|
53
|
+
This method can also be used to store non-string values, such as numbers and booleans.
|
|
54
|
+
|
|
55
|
+
## API
|
|
56
|
+
|
|
57
|
+
<docgen-index>
|
|
58
|
+
|
|
59
|
+
* [`configure(...)`](#configure)
|
|
60
|
+
* [`get(...)`](#get)
|
|
61
|
+
* [`set(...)`](#set)
|
|
62
|
+
* [`remove(...)`](#remove)
|
|
63
|
+
* [`clear()`](#clear)
|
|
64
|
+
* [`keys()`](#keys)
|
|
65
|
+
* [`migrate()`](#migrate)
|
|
66
|
+
* [`removeOld()`](#removeold)
|
|
67
|
+
* [Interfaces](#interfaces)
|
|
68
|
+
|
|
69
|
+
</docgen-index>
|
|
70
|
+
|
|
71
|
+
<docgen-api>
|
|
72
|
+
<!--Update the source file JSDoc comments and rerun docgen to update the docs below-->
|
|
73
|
+
|
|
74
|
+
### configure(...)
|
|
75
|
+
|
|
76
|
+
```typescript
|
|
77
|
+
configure(options: ConfigureOptions) => Promise<void>
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
Configure the preferences plugin at runtime.
|
|
81
|
+
|
|
82
|
+
Options that are `undefined` will not be used.
|
|
83
|
+
|
|
84
|
+
| Param | Type |
|
|
85
|
+
| ------------- | ------------------------------------------------------------- |
|
|
86
|
+
| **`options`** | <code><a href="#configureoptions">ConfigureOptions</a></code> |
|
|
87
|
+
|
|
88
|
+
**Since:** 1.0.0
|
|
89
|
+
|
|
90
|
+
--------------------
|
|
91
|
+
|
|
92
|
+
|
|
93
|
+
### get(...)
|
|
94
|
+
|
|
95
|
+
```typescript
|
|
96
|
+
get(options: GetOptions) => Promise<GetResult>
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
Get the value from preferences of a given key.
|
|
100
|
+
|
|
101
|
+
| Param | Type |
|
|
102
|
+
| ------------- | ------------------------------------------------- |
|
|
103
|
+
| **`options`** | <code><a href="#getoptions">GetOptions</a></code> |
|
|
104
|
+
|
|
105
|
+
**Returns:** <code>Promise<<a href="#getresult">GetResult</a>></code>
|
|
106
|
+
|
|
107
|
+
**Since:** 1.0.0
|
|
108
|
+
|
|
109
|
+
--------------------
|
|
110
|
+
|
|
111
|
+
|
|
112
|
+
### set(...)
|
|
113
|
+
|
|
114
|
+
```typescript
|
|
115
|
+
set(options: SetOptions) => Promise<void>
|
|
116
|
+
```
|
|
117
|
+
|
|
118
|
+
Set the value in preferences for a given key.
|
|
119
|
+
|
|
120
|
+
| Param | Type |
|
|
121
|
+
| ------------- | ------------------------------------------------- |
|
|
122
|
+
| **`options`** | <code><a href="#setoptions">SetOptions</a></code> |
|
|
123
|
+
|
|
124
|
+
**Since:** 1.0.0
|
|
125
|
+
|
|
126
|
+
--------------------
|
|
127
|
+
|
|
128
|
+
|
|
129
|
+
### remove(...)
|
|
130
|
+
|
|
131
|
+
```typescript
|
|
132
|
+
remove(options: RemoveOptions) => Promise<void>
|
|
133
|
+
```
|
|
134
|
+
|
|
135
|
+
Remove the value from preferences for a given key, if any.
|
|
136
|
+
|
|
137
|
+
| Param | Type |
|
|
138
|
+
| ------------- | ------------------------------------------------------- |
|
|
139
|
+
| **`options`** | <code><a href="#removeoptions">RemoveOptions</a></code> |
|
|
140
|
+
|
|
141
|
+
**Since:** 1.0.0
|
|
142
|
+
|
|
143
|
+
--------------------
|
|
144
|
+
|
|
145
|
+
|
|
146
|
+
### clear()
|
|
147
|
+
|
|
148
|
+
```typescript
|
|
149
|
+
clear() => Promise<void>
|
|
150
|
+
```
|
|
151
|
+
|
|
152
|
+
Clear keys and values from preferences.
|
|
153
|
+
|
|
154
|
+
**Since:** 1.0.0
|
|
155
|
+
|
|
156
|
+
--------------------
|
|
157
|
+
|
|
158
|
+
|
|
159
|
+
### keys()
|
|
160
|
+
|
|
161
|
+
```typescript
|
|
162
|
+
keys() => Promise<KeysResult>
|
|
163
|
+
```
|
|
164
|
+
|
|
165
|
+
Return the list of known keys in preferences.
|
|
166
|
+
|
|
167
|
+
**Returns:** <code>Promise<<a href="#keysresult">KeysResult</a>></code>
|
|
168
|
+
|
|
169
|
+
**Since:** 1.0.0
|
|
170
|
+
|
|
171
|
+
--------------------
|
|
172
|
+
|
|
173
|
+
|
|
174
|
+
### migrate()
|
|
175
|
+
|
|
176
|
+
```typescript
|
|
177
|
+
migrate() => Promise<MigrateResult>
|
|
178
|
+
```
|
|
179
|
+
|
|
180
|
+
Migrate data from the Capacitor 2 Storage plugin.
|
|
181
|
+
|
|
182
|
+
This action is non-destructive. It will not remove old data and will only
|
|
183
|
+
write new data if they key was not already set.
|
|
184
|
+
To remove the old data after being migrated, call removeOld().
|
|
185
|
+
|
|
186
|
+
**Returns:** <code>Promise<<a href="#migrateresult">MigrateResult</a>></code>
|
|
187
|
+
|
|
188
|
+
**Since:** 1.0.0
|
|
189
|
+
|
|
190
|
+
--------------------
|
|
191
|
+
|
|
192
|
+
|
|
193
|
+
### removeOld()
|
|
194
|
+
|
|
195
|
+
```typescript
|
|
196
|
+
removeOld() => Promise<void>
|
|
197
|
+
```
|
|
198
|
+
|
|
199
|
+
Removes old data with `_cap_` prefix from the Capacitor 2 Storage plugin.
|
|
200
|
+
|
|
201
|
+
**Since:** 1.1.0
|
|
202
|
+
|
|
203
|
+
--------------------
|
|
204
|
+
|
|
205
|
+
|
|
206
|
+
### Interfaces
|
|
207
|
+
|
|
208
|
+
|
|
209
|
+
#### ConfigureOptions
|
|
210
|
+
|
|
211
|
+
| Prop | Type | Description | Default | Since |
|
|
212
|
+
| ----------- | ------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ----------------------------- | ----- |
|
|
213
|
+
| **`group`** | <code>string</code> | Set the preferences group. Preferences groups are used to organize key/value pairs. Using the value 'NativeStorage' provides backwards-compatibility with [`cordova-plugin-nativestorage`](https://www.npmjs.com/package/cordova-plugin-nativestorage). WARNING: The `clear()` method can delete unintended values when using the 'NativeStorage' group. | <code>CapacitorStorage</code> | 1.0.0 |
|
|
214
|
+
|
|
215
|
+
|
|
216
|
+
#### GetResult
|
|
217
|
+
|
|
218
|
+
| Prop | Type | Description | Since |
|
|
219
|
+
| ----------- | --------------------------- | --------------------------------------------------------------------------------------------------------------------------------- | ----- |
|
|
220
|
+
| **`value`** | <code>string \| null</code> | The value from preferences associated with the given key. If a value was not previously set or was removed, value will be `null`. | 1.0.0 |
|
|
221
|
+
|
|
222
|
+
|
|
223
|
+
#### GetOptions
|
|
224
|
+
|
|
225
|
+
| Prop | Type | Description | Since |
|
|
226
|
+
| --------- | ------------------- | ------------------------------------------------- | ----- |
|
|
227
|
+
| **`key`** | <code>string</code> | The key whose value to retrieve from preferences. | 1.0.0 |
|
|
228
|
+
|
|
229
|
+
|
|
230
|
+
#### SetOptions
|
|
231
|
+
|
|
232
|
+
| Prop | Type | Description | Since |
|
|
233
|
+
| ----------- | ------------------- | ------------------------------------------------------------- | ----- |
|
|
234
|
+
| **`key`** | <code>string</code> | The key to associate with the value being set in preferences. | 1.0.0 |
|
|
235
|
+
| **`value`** | <code>string</code> | The value to set in preferences with the associated key. | 1.0.0 |
|
|
236
|
+
|
|
237
|
+
|
|
238
|
+
#### RemoveOptions
|
|
239
|
+
|
|
240
|
+
| Prop | Type | Description | Since |
|
|
241
|
+
| --------- | ------------------- | ----------------------------------------------- | ----- |
|
|
242
|
+
| **`key`** | <code>string</code> | The key whose value to remove from preferences. | 1.0.0 |
|
|
243
|
+
|
|
244
|
+
|
|
245
|
+
#### KeysResult
|
|
246
|
+
|
|
247
|
+
| Prop | Type | Description | Since |
|
|
248
|
+
| ---------- | --------------------- | ------------------------------ | ----- |
|
|
249
|
+
| **`keys`** | <code>string[]</code> | The known keys in preferences. | 1.0.0 |
|
|
250
|
+
|
|
251
|
+
|
|
252
|
+
#### MigrateResult
|
|
253
|
+
|
|
254
|
+
| Prop | Type | Description | Since |
|
|
255
|
+
| -------------- | --------------------- | ------------------------------------------------------------------------------------------------------------------------------------- | ----- |
|
|
256
|
+
| **`migrated`** | <code>string[]</code> | An array of keys that were migrated. | 1.0.0 |
|
|
257
|
+
| **`existing`** | <code>string[]</code> | An array of keys that were already migrated or otherwise exist in preferences that had a value in the Capacitor 2 Preferences plugin. | 1.0.0 |
|
|
258
|
+
|
|
259
|
+
</docgen-api>
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
ext {
|
|
2
|
+
junitVersion = project.hasProperty('junitVersion') ? rootProject.ext.junitVersion : '4.13.2'
|
|
3
|
+
androidxAppCompatVersion = project.hasProperty('androidxAppCompatVersion') ? rootProject.ext.androidxAppCompatVersion : '1.4.2'
|
|
4
|
+
androidxJunitVersion = project.hasProperty('androidxJunitVersion') ? rootProject.ext.androidxJunitVersion : '1.1.3'
|
|
5
|
+
androidxEspressoCoreVersion = project.hasProperty('androidxEspressoCoreVersion') ? rootProject.ext.androidxEspressoCoreVersion : '3.4.0'
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
buildscript {
|
|
9
|
+
repositories {
|
|
10
|
+
google()
|
|
11
|
+
mavenCentral()
|
|
12
|
+
}
|
|
13
|
+
dependencies {
|
|
14
|
+
classpath 'com.android.tools.build:gradle:7.2.1'
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
apply plugin: 'com.android.library'
|
|
19
|
+
|
|
20
|
+
android {
|
|
21
|
+
compileSdkVersion project.hasProperty('compileSdkVersion') ? rootProject.ext.compileSdkVersion : 32
|
|
22
|
+
defaultConfig {
|
|
23
|
+
minSdkVersion project.hasProperty('minSdkVersion') ? rootProject.ext.minSdkVersion : 22
|
|
24
|
+
targetSdkVersion project.hasProperty('targetSdkVersion') ? rootProject.ext.targetSdkVersion : 32
|
|
25
|
+
versionCode 1
|
|
26
|
+
versionName "1.0"
|
|
27
|
+
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
|
|
28
|
+
}
|
|
29
|
+
buildTypes {
|
|
30
|
+
release {
|
|
31
|
+
minifyEnabled false
|
|
32
|
+
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
lintOptions {
|
|
36
|
+
abortOnError false
|
|
37
|
+
}
|
|
38
|
+
compileOptions {
|
|
39
|
+
sourceCompatibility JavaVersion.VERSION_11
|
|
40
|
+
targetCompatibility JavaVersion.VERSION_11
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
repositories {
|
|
45
|
+
google()
|
|
46
|
+
mavenCentral()
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
dependencies {
|
|
51
|
+
implementation fileTree(dir: 'libs', include: ['*.jar'])
|
|
52
|
+
implementation project(':capacitor-android')
|
|
53
|
+
implementation "androidx.appcompat:appcompat:$androidxAppCompatVersion"
|
|
54
|
+
testImplementation "junit:junit:$junitVersion"
|
|
55
|
+
androidTestImplementation "androidx.test.ext:junit:$androidxJunitVersion"
|
|
56
|
+
androidTestImplementation "androidx.test.espresso:espresso-core:$androidxEspressoCoreVersion"
|
|
57
|
+
}
|