Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
OpenHarmony
Docs
提交
93041aad
D
Docs
项目概览
OpenHarmony
/
Docs
大约 1 年 前同步成功
通知
159
Star
292
Fork
28
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
D
Docs
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
93041aad
编写于
10月 26, 2022
作者:
D
duanweiling
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
增加首选项错误码文档
Signed-off-by:
N
duanweiling
<
duanweiling@huawei.com
>
上级
061300e8
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
130 addition
and
128 deletion
+130
-128
zh-cn/application-dev/reference/apis/js-apis-data-preferences.md
...pplication-dev/reference/apis/js-apis-data-preferences.md
+127
-127
zh-cn/application-dev/reference/errorcodes/errorcode-preferences.md
...ication-dev/reference/errorcodes/errorcode-preferences.md
+3
-1
未找到文件。
zh-cn/application-dev/reference/apis/js-apis-data-preferences.md
浏览文件 @
93041aad
...
@@ -53,16 +53,15 @@ let context = featureAbility.getContext();
...
@@ -53,16 +53,15 @@ let context = featureAbility.getContext();
let
preferences
=
null
;
let
preferences
=
null
;
try
{
try
{
data_preferences
.
getPreferences
(
context
,
'
mystore
'
,
function
(
err
,
val
)
{
data_preferences
.
getPreferences
(
context
,
'
mystore
'
,
function
(
err
,
val
)
{
if
(
err
)
{
if
(
err
)
{
console
.
info
(
"
Failed to get preferences. code =
"
+
err
.
code
+
"
, message =
"
+
err
.
message
);
console
.
info
(
"
Failed to get preferences. code =
"
+
err
.
code
+
"
, message =
"
+
err
.
message
);
return
;
return
;
}
}
preferences
=
object
;
console
.
info
(
"
Succeeded in getting preferences.
"
);
console
.
info
(
"
Succeeded in getting preferences.
"
);
})
})
}
catch
(
err
)
{
}
catch
(
err
)
{
console
.
info
(
"
Failed to get preferences. code =
"
+
err
.
code
+
"
, message =
"
+
err
.
message
);
console
.
info
(
"
Failed to get preferences. code =
"
+
err
.
code
+
"
, message =
"
+
err
.
message
);
}
}
```
```
...
@@ -80,16 +79,15 @@ class MainAbility extends Ability{
...
@@ -80,16 +79,15 @@ class MainAbility extends Ability{
let
preferences
=
null
;
let
preferences
=
null
;
try
{
try
{
data_preferences
.
getPreferences
(
context
,
'
mystore
'
,
function
(
err
,
val
)
{
data_preferences
.
getPreferences
(
context
,
'
mystore
'
,
function
(
err
,
val
)
{
if
(
err
)
{
if
(
err
)
{
console
.
info
(
"
Failed to get preferences. code =
"
+
err
.
code
+
"
, message =
"
+
err
.
message
);
console
.
info
(
"
Failed to get preferences. code =
"
+
err
.
code
+
"
, message =
"
+
err
.
message
);
return
;
return
;
}
}
preferences
=
object
;
console
.
info
(
"
Succeeded in getting preferences.
"
);
console
.
info
(
"
Succeeded in getting preferences.
"
);
})
})
}
catch
(
err
)
{
}
catch
(
err
)
{
console
.
info
(
"
Failed to get preferences. code =
"
+
err
.
code
+
"
, message =
"
+
err
.
message
);
console
.
info
(
"
Failed to get preferences. code =
"
+
err
.
code
+
"
, message =
"
+
err
.
message
);
}
}
```
```
...
@@ -125,15 +123,15 @@ let context = featureAbility.getContext();
...
@@ -125,15 +123,15 @@ let context = featureAbility.getContext();
let
preferences
=
null
;
let
preferences
=
null
;
try
{
try
{
let
promise
=
data_preferences
.
getPreferences
(
context
,
'
mystore
'
);
let
promise
=
data_preferences
.
getPreferences
(
context
,
'
mystore
'
);
promise
.
then
((
object
)
=>
{
promise
.
then
((
object
)
=>
{
preferences
=
object
;
preferences
=
object
;
console
.
info
(
"
Succeeded in getting preferences.
"
);
console
.
info
(
"
Succeeded in getting preferences.
"
);
}).
catch
((
err
)
=>
{
}).
catch
((
err
)
=>
{
console
.
log
(
"
Failed to get preferences. code =
"
+
err
.
code
+
"
, message =
"
+
err
.
message
);
console
.
log
(
"
Failed to get preferences. code =
"
+
err
.
code
+
"
, message =
"
+
err
.
message
);
})
})
}
catch
(
err
)
{
}
catch
(
err
)
{
console
.
log
(
"
Failed to get preferences. code =
"
+
err
.
code
+
"
, message =
"
+
err
.
message
);
console
.
log
(
"
Failed to get preferences. code =
"
+
err
.
code
+
"
, message =
"
+
err
.
message
);
}
}
```
```
...
@@ -151,17 +149,16 @@ class MainAbility extends Ability{
...
@@ -151,17 +149,16 @@ class MainAbility extends Ability{
let
preferences
=
null
;
let
preferences
=
null
;
try
{
try
{
let
promise
=
data_preferences
.
getPreferences
(
context
,
'
mystore
'
);
let
promise
=
data_preferences
.
getPreferences
(
context
,
'
mystore
'
);
promise
.
then
((
object
)
=>
{
promise
.
then
((
object
)
=>
{
preferences
=
object
;
preferences
=
object
;
console
.
info
(
"
Succeeded in getting preferences.
"
);
console
.
info
(
"
Succeeded in getting preferences.
"
);
}).
catch
((
err
)
=>
{
}).
catch
((
err
)
=>
{
console
.
log
(
"
Failed to get preferences. code =
"
+
err
.
code
+
"
, message =
"
+
err
.
message
);
console
.
log
(
"
Failed to get preferences. code =
"
+
err
.
code
+
"
, message =
"
+
err
.
message
);
})
})
}
catch
(
err
)
{
}
catch
(
err
)
{
console
.
log
(
"
Failed to get preferences. code =
"
+
err
.
code
+
"
, message =
"
+
err
.
message
);
console
.
log
(
"
Failed to get preferences. code =
"
+
err
.
code
+
"
, message =
"
+
err
.
message
);
}
}
```
```
## data_preferences.deletePreferences
## data_preferences.deletePreferences
...
@@ -203,11 +200,11 @@ let context = featureAbility.getContext();
...
@@ -203,11 +200,11 @@ let context = featureAbility.getContext();
try
{
try
{
data_preferences
.
deletePreferences
(
context
,
'
mystore
'
,
function
(
err
,
val
)
{
data_preferences
.
deletePreferences
(
context
,
'
mystore
'
,
function
(
err
,
val
)
{
if
(
err
)
{
if
(
err
)
{
console
.
info
(
"
Failed to delete preferences. code =
"
+
err
.
code
+
"
, message =
"
+
err
.
message
);
console
.
info
(
"
Failed to delete preferences. code =
"
+
err
.
code
+
"
, message =
"
+
err
.
message
);
return
;
return
;
}
}
console
.
info
(
"
Succeeded in deleting preferences.
"
);
console
.
info
(
"
Succeeded in deleting preferences.
"
);
})
})
}
catch
(
err
)
{
}
catch
(
err
)
{
console
.
info
(
"
Failed to delete preferences. code =
"
+
err
.
code
+
"
, message =
"
+
err
.
message
);
console
.
info
(
"
Failed to delete preferences. code =
"
+
err
.
code
+
"
, message =
"
+
err
.
message
);
...
@@ -228,11 +225,11 @@ class MainAbility extends Ability{
...
@@ -228,11 +225,11 @@ class MainAbility extends Ability{
try
{
try
{
data_preferences
.
deletePreferences
(
context
,
'
mystore
'
,
function
(
err
,
val
)
{
data_preferences
.
deletePreferences
(
context
,
'
mystore
'
,
function
(
err
,
val
)
{
if
(
err
)
{
if
(
err
)
{
console
.
info
(
"
Failed to delete preferences. code =
"
+
err
.
code
+
"
, message =
"
+
err
.
message
);
console
.
info
(
"
Failed to delete preferences. code =
"
+
err
.
code
+
"
, message =
"
+
err
.
message
);
return
;
return
;
}
}
console
.
info
(
"
Succeeded in deleting preferences.
"
);
console
.
info
(
"
Succeeded in deleting preferences.
"
);
})
})
}
catch
(
err
)
{
}
catch
(
err
)
{
console
.
info
(
"
Failed to delete preferences. code =
"
+
err
.
code
+
"
, message =
"
+
err
.
message
);
console
.
info
(
"
Failed to delete preferences. code =
"
+
err
.
code
+
"
, message =
"
+
err
.
message
);
...
@@ -282,14 +279,14 @@ import featureAbility from '@ohos.ability.featureAbility';
...
@@ -282,14 +279,14 @@ import featureAbility from '@ohos.ability.featureAbility';
let
context
=
featureAbility
.
getContext
();
let
context
=
featureAbility
.
getContext
();
try
{
try
{
let
promise
=
data_preferences
.
deletePreferences
(
context
,
'
mystore
'
);
let
promise
=
data_preferences
.
deletePreferences
(
context
,
'
mystore
'
);
promise
.
then
(()
=>
{
promise
.
then
(()
=>
{
console
.
info
(
"
Succeeded in deleting preferences.
"
);
console
.
info
(
"
Succeeded in deleting preferences.
"
);
}).
catch
((
err
)
=>
{
}).
catch
((
err
)
=>
{
console
.
info
(
"
Failed to delete preferences. code =
"
+
err
.
code
+
"
, message =
"
+
err
.
message
);
console
.
info
(
"
Failed to delete preferences. code =
"
+
err
.
code
+
"
, message =
"
+
err
.
message
);
})
})
}
catch
(
err
)
{
}
catch
(
err
)
{
console
.
info
(
"
Failed to delete preferences. code =
"
+
err
.
code
+
"
, message =
"
+
err
.
message
);
console
.
info
(
"
Failed to delete preferences. code =
"
+
err
.
code
+
"
, message =
"
+
err
.
message
);
}
}
```
```
...
@@ -306,9 +303,9 @@ class MainAbility extends Ability{
...
@@ -306,9 +303,9 @@ class MainAbility extends Ability{
}
}
try
{
try
{
let
promise
=
data_preferences
.
deletePreferences
(
context
,
'
mystore
'
);
let
promise
=
data_preferences
.
deletePreferences
(
context
,
'
mystore
'
);
promise
.
then
(()
=>
{
promise
.
then
(()
=>
{
console
.
info
(
"
Succeeded in deleting preferences.
"
);
console
.
info
(
"
Succeeded in deleting preferences.
"
);
}).
catch
((
err
)
=>
{
}).
catch
((
err
)
=>
{
console
.
info
(
"
Failed to delete preferences. code =
"
+
err
.
code
+
"
, message =
"
+
err
.
message
);
console
.
info
(
"
Failed to delete preferences. code =
"
+
err
.
code
+
"
, message =
"
+
err
.
message
);
})
})
...
@@ -346,12 +343,13 @@ let context = featureAbility.getContext();
...
@@ -346,12 +343,13 @@ let context = featureAbility.getContext();
try
{
try
{
data_preferences
.
removePreferencesFromCache
(
context
,
'
mystore
'
,
function
(
err
,
val
)
{
data_preferences
.
removePreferencesFromCache
(
context
,
'
mystore
'
,
function
(
err
,
val
)
{
if
(
err
)
{
if
(
err
)
{
console
.
info
(
"
Failed to remove preferences. code =
"
+
err
.
code
+
"
, message =
"
+
err
.
message
);
console
.
info
(
"
Failed to remove preferences. code =
"
+
err
.
code
+
"
, message =
"
+
err
.
message
);
return
;
return
;
}
}
console
.
info
(
"
Succeeded in removing preferences.
"
);
expect
(
true
).
assertEqual
(
val
);
})
console
.
info
(
"
Succeeded in removing preferences.
"
);
})
}
catch
(
err
)
{
}
catch
(
err
)
{
console
.
info
(
"
Failed to remove preferences. code =
"
+
err
.
code
+
"
, message =
"
+
err
.
message
);
console
.
info
(
"
Failed to remove preferences. code =
"
+
err
.
code
+
"
, message =
"
+
err
.
message
);
}
}
...
@@ -371,15 +369,17 @@ class MainAbility extends Ability{
...
@@ -371,15 +369,17 @@ class MainAbility extends Ability{
try
{
try
{
data_preferences
.
removePreferencesFromCache
(
context
,
'
mystore
'
,
function
(
err
,
val
)
{
data_preferences
.
removePreferencesFromCache
(
context
,
'
mystore
'
,
function
(
err
,
val
)
{
if
(
err
)
{
if
(
err
)
{
console
.
info
(
"
Failed to remove preferences. code =
"
+
err
.
code
+
"
, message =
"
+
err
.
message
);
console
.
info
(
"
Failed to remove preferences. code =
"
+
err
.
code
+
"
, message =
"
+
err
.
message
);
return
;
return
;
}
}
console
.
info
(
"
Succeeded in removing preferences.
"
);
expect
(
true
).
assertEqual
(
val
);
})
console
.
info
(
"
Succeeded in removing preferences.
"
);
})
}
catch
(
err
)
{
}
catch
(
err
)
{
console
.
info
(
"
Failed to remove preferences. code =
"
+
err
.
code
+
"
, message =
"
+
err
.
message
);
console
.
info
(
"
Failed to remove preferences. code =
"
+
err
.
code
+
"
, message =
"
+
err
.
message
);
}
}
```
```
## data_preferences.removePreferencesFromCache
## data_preferences.removePreferencesFromCache
...
@@ -482,10 +482,11 @@ try {
...
@@ -482,10 +482,11 @@ try {
console
.
info
(
"
Failed to get value of 'startup'. code =
"
+
err
.
code
+
"
, message =
"
+
err
.
message
);
console
.
info
(
"
Failed to get value of 'startup'. code =
"
+
err
.
code
+
"
, message =
"
+
err
.
message
);
return
;
return
;
}
}
console
.
info
(
"
Succeeded in getting value of 'startup'. val:
"
+
val
);
expect
(
true
).
assertEqual
(
val
);
console
.
info
(
"
Succeeded in getting value of 'startup'. val:
"
+
val
);
})
})
}
catch
(
err
)
{
}
catch
(
err
)
{
console
.
info
(
"
Failed to get value of 'startup'. code =
"
+
err
.
code
+
"
, message =
"
+
err
.
message
);
console
.
info
(
"
Failed to get value of 'startup'. code =
"
+
err
.
code
+
"
, message =
"
+
err
.
message
);
}
}
```
```
...
@@ -515,14 +516,14 @@ get(key: string, defValue: ValueType): Promise<ValueType>
...
@@ -515,14 +516,14 @@ get(key: string, defValue: ValueType): Promise<ValueType>
```
js
```
js
try
{
try
{
let
promise
=
preferences
.
get
(
'
startup
'
,
'
default
'
);
let
promise
=
preferences
.
get
(
'
startup
'
,
'
default
'
);
promise
.
then
((
data
)
=>
{
promise
.
then
((
data
)
=>
{
console
.
info
(
"
Succeeded in getting value of 'startup'. Data:
"
+
data
);
console
.
info
(
"
Succeeded in getting value of 'startup'. Data:
"
+
data
);
}).
catch
((
err
)
=>
{
}).
catch
((
err
)
=>
{
console
.
info
(
"
Failed to get value of 'startup'. code =
"
+
err
.
code
+
"
, message =
"
+
err
.
message
);
console
.
info
(
"
Failed to get value of 'startup'. code =
"
+
err
.
code
+
"
, message =
"
+
err
.
message
);
})
})
}
catch
(
err
)
{
}
catch
(
err
)
{
console
.
info
(
"
Failed to get value of 'startup'. code =
"
+
err
.
code
+
"
, message =
"
+
err
.
message
);
console
.
info
(
"
Failed to get value of 'startup'. code =
"
+
err
.
code
+
"
, message =
"
+
err
.
message
);
}
}
```
```
...
@@ -555,7 +556,7 @@ try {
...
@@ -555,7 +556,7 @@ try {
})
})
}
catch
(
err
)
{
}
catch
(
err
)
{
console
.
info
(
"
Failed to get all key-values. code =
"
+
err
.
code
+
"
, message =
"
+
err
.
message
);
console
.
info
(
"
Failed to get all key-values. code =
"
+
err
.
code
+
"
, message =
"
+
err
.
message
);
}
;
}
```
```
...
@@ -577,8 +578,8 @@ getAll(): Promise<Object>
...
@@ -577,8 +578,8 @@ getAll(): Promise<Object>
```
js
```
js
try
{
try
{
let
promise
=
preferences
.
getAll
();
let
promise
=
preferences
.
getAll
();
promise
.
then
((
value
)
=>
{
promise
.
then
((
value
)
=>
{
let
allKeys
=
Object
.
keys
(
value
);
let
allKeys
=
Object
.
keys
(
value
);
console
.
info
(
'
getAll keys =
'
+
allKeys
);
console
.
info
(
'
getAll keys =
'
+
allKeys
);
console
.
info
(
"
getAll object =
"
+
JSON
.
stringify
(
value
));
console
.
info
(
"
getAll object =
"
+
JSON
.
stringify
(
value
));
...
@@ -649,7 +650,7 @@ put(key: string, value: ValueType): Promise<void>
...
@@ -649,7 +650,7 @@ put(key: string, value: ValueType): Promise<void>
```
js
```
js
try
{
try
{
let
promise
=
preferences
.
put
(
'
startup
'
,
'
auto
'
);
let
promise
=
preferences
.
put
(
'
startup
'
,
'
auto
'
);
promise
.
then
(()
=>
{
promise
.
then
(()
=>
{
console
.
info
(
"
Succeeded in putting value of 'startup'.
"
);
console
.
info
(
"
Succeeded in putting value of 'startup'.
"
);
}).
catch
((
err
)
=>
{
}).
catch
((
err
)
=>
{
console
.
info
(
"
Failed to put value of 'startup'. code =
"
+
err
.
code
+
"
, message =
"
+
err
.
message
);
console
.
info
(
"
Failed to put value of 'startup'. code =
"
+
err
.
code
+
"
, message =
"
+
err
.
message
);
...
@@ -678,18 +679,18 @@ has(key: string, callback: AsyncCallback<boolean>): void
...
@@ -678,18 +679,18 @@ has(key: string, callback: AsyncCallback<boolean>): void
**示例:**
**示例:**
```
js
```
js
try
{
try
{
preferences
.
has
(
'
startup
'
,
function
(
err
,
val
)
{
preferences
.
has
(
'
startup
'
,
function
(
err
,
val
)
{
if
(
err
)
{
if
(
err
)
{
console
.
info
(
"
Failed to check the key 'startup'. code =
"
+
err
.
code
+
"
, message =
"
+
err
.
message
);
console
.
info
(
"
Failed to check the key 'startup'. code =
"
+
err
.
code
+
"
, message =
"
+
err
.
message
);
return
;
return
;
}
}
if
(
val
)
{
if
(
val
)
{
console
.
info
(
"
The key 'startup' is contained.
"
);
console
.
info
(
"
The key 'startup' is contained.
"
);
}
else
{
}
else
{
console
.
info
(
"
The key 'startup' dose not contain.
"
);
console
.
info
(
"
The key 'startup' dose not contain.
"
);
}
}
})
})
}
catch
(
err
)
{
}
catch
(
err
)
{
console
.
info
(
"
Failed to check the key 'startup'. code =
"
+
err
.
code
+
"
, message =
"
+
err
.
message
);
console
.
info
(
"
Failed to check the key 'startup'. code =
"
+
err
.
code
+
"
, message =
"
+
err
.
message
);
}
}
...
@@ -719,21 +720,20 @@ has(key: string): Promise<boolean>
...
@@ -719,21 +720,20 @@ has(key: string): Promise<boolean>
**示例:**
**示例:**
```
js
```
js
try
{
try
{
let
promise
=
preferences
.
has
(
'
startup
'
);
let
promise
=
preferences
.
has
(
'
startup
'
);
promise
.
then
((
val
)
=>
{
promise
.
then
((
val
)
=>
{
if
(
val
)
{
if
(
val
)
{
console
.
info
(
"
The key 'startup' is contained.
"
);
console
.
info
(
"
The key 'startup' is contained.
"
);
}
else
{
}
else
{
console
.
info
(
"
The key 'startup' dose not contain.
"
);
console
.
info
(
"
The key 'startup' dose not contain.
"
);
}
}
}).
catch
((
err
)
=>
{
}).
catch
((
err
)
=>
{
console
.
info
(
"
Failed to check the key 'startup'. code =
"
+
err
.
code
+
"
, message =
"
+
err
.
message
);
console
.
info
(
"
Failed to check the key 'startup'. code =
"
+
err
.
code
+
"
, message =
"
+
err
.
message
);
})
})
}
catch
(
err
)
{
}
catch
(
err
)
{
console
.
info
(
"
Failed to check the key 'startup'. code =
"
+
err
.
code
+
"
, message =
"
+
err
.
message
);
console
.
info
(
"
Failed to check the key 'startup'. code =
"
+
err
.
code
+
"
, message =
"
+
err
.
message
);
}
}
```
```
...
@@ -793,7 +793,7 @@ delete(key: string): Promise<void>
...
@@ -793,7 +793,7 @@ delete(key: string): Promise<void>
```
js
```
js
try
{
try
{
let
promise
=
preferences
.
delete
(
'
startup
'
);
let
promise
=
preferences
.
delete
(
'
startup
'
);
promise
.
then
(()
=>
{
promise
.
then
(()
=>
{
console
.
info
(
"
Succeeded in deleting the key 'startup'.
"
);
console
.
info
(
"
Succeeded in deleting the key 'startup'.
"
);
}).
catch
((
err
)
=>
{
}).
catch
((
err
)
=>
{
...
@@ -855,7 +855,7 @@ flush(): Promise<void>
...
@@ -855,7 +855,7 @@ flush(): Promise<void>
```
js
```
js
try
{
try
{
let
promise
=
preferences
.
flush
();
let
promise
=
preferences
.
flush
();
promise
.
then
(()
=>
{
promise
.
then
(()
=>
{
console
.
info
(
"
Succeeded in flushing.
"
);
console
.
info
(
"
Succeeded in flushing.
"
);
}).
catch
((
err
)
=>
{
}).
catch
((
err
)
=>
{
console
.
info
(
"
Failed to flush. code =
"
+
err
.
code
+
"
, message =
"
+
err
.
message
);
console
.
info
(
"
Failed to flush. code =
"
+
err
.
code
+
"
, message =
"
+
err
.
message
);
...
@@ -915,7 +915,7 @@ clear(): Promise<void>
...
@@ -915,7 +915,7 @@ clear(): Promise<void>
```
js
```
js
try
{
try
{
let
promise
=
preferences
.
clear
()
let
promise
=
preferences
.
clear
()
promise
.
then
(()
=>
{
promise
.
then
(()
=>
{
console
.
info
(
"
Succeeded in clearing.
"
);
console
.
info
(
"
Succeeded in clearing.
"
);
}).
catch
((
err
)
=>
{
}).
catch
((
err
)
=>
{
...
@@ -946,34 +946,34 @@ on(type: 'change', callback: Callback<{ key : string }>): void
...
@@ -946,34 +946,34 @@ on(type: 'change', callback: Callback<{ key : string }>): void
```
js
```
js
try
{
try
{
data_preferences
.
getPreferences
(
this
.
context
,
'
mystore
'
,
function
(
err
,
preferences
)
{
data_preferences
.
getPreferences
(
this
.
context
,
'
mystore
'
,
function
(
err
,
preferences
)
{
if
(
err
)
{
console
.
info
(
"
Failed to get preferences.
"
);
return
;
}
let
observer
=
function
(
key
)
{
console
.
info
(
"
The key
"
+
key
+
"
changed.
"
);
}
preferences
.
on
(
'
change
'
,
observer
);
preferences
.
put
(
'
startup
'
,
'
manual
'
,
function
(
err
)
{
if
(
err
)
{
console
.
info
(
"
Failed to put the value of 'startup'. Cause:
"
+
err
);
return
;
}
console
.
info
(
"
Succeeded in putting the value of 'startup'.
"
);
preferences
.
flush
(
function
(
err
)
{
if
(
err
)
{
if
(
err
)
{
console
.
info
(
"
Failed to
flush. Cause:
"
+
err
);
console
.
info
(
"
Failed to
get preferences.
"
);
return
;
return
;
}
}
console
.
info
(
"
Succeeded in flushing.
"
);
// observer will be called.
let
observer
=
function
(
key
)
{
console
.
info
(
"
The key
"
+
key
+
"
changed.
"
);
}
preferences
.
on
(
'
change
'
,
observer
);
preferences
.
put
(
'
startup
'
,
'
manual
'
,
function
(
err
)
{
if
(
err
)
{
console
.
info
(
"
Failed to put the value of 'startup'. Cause:
"
+
err
);
return
;
}
console
.
info
(
"
Succeeded in putting the value of 'startup'.
"
);
preferences
.
flush
(
function
(
err
)
{
if
(
err
)
{
console
.
info
(
"
Failed to flush. Cause:
"
+
err
);
return
;
}
console
.
info
(
"
Succeeded in flushing.
"
);
// observer will be called.
})
})
})
})
})
}
catch
(
err
)
{
})
console
.
info
(
"
Failed to flush. code =
"
+
err
.
code
+
"
, message =
"
+
err
.
message
);
}
catch
(
error
)
{
}
console
.
info
(
"
Failed to flush. code =
"
+
err
.
code
+
"
, message =
"
+
err
.
message
);
}
```
```
...
@@ -996,34 +996,34 @@ off(type: 'change', callback?: Callback<{ key : string }>): void
...
@@ -996,34 +996,34 @@ off(type: 'change', callback?: Callback<{ key : string }>): void
```
js
```
js
try
{
try
{
data_preferences
.
getPreferences
(
this
.
context
,
'
mystore
'
,
function
(
err
,
preferences
)
{
data_preferences
.
getPreferences
(
this
.
context
,
'
mystore
'
,
function
(
err
,
preferences
)
{
if
(
err
)
{
console
.
info
(
"
Failed to get preferences.
"
);
return
;
}
let
observer
=
function
(
key
)
{
console
.
info
(
"
The key
"
+
key
+
"
changed.
"
);
}
preferences
.
on
(
'
change
'
,
observer
);
preferences
.
put
(
'
startup
'
,
'
auto
'
,
function
(
err
)
{
if
(
err
)
{
if
(
err
)
{
console
.
info
(
"
Failed to
put the value of 'startup'. Cause:
"
+
err
);
console
.
info
(
"
Failed to
get preferences.
"
);
return
;
return
;
}
}
console
.
info
(
"
Succeeded in putting the value of 'startup'.
"
);
let
observer
=
function
(
key
)
{
console
.
info
(
"
The key
"
+
key
+
"
changed.
"
);
preferences
.
flush
(
function
(
err
)
{
}
preferences
.
on
(
'
change
'
,
observer
);
preferences
.
put
(
'
startup
'
,
'
auto
'
,
function
(
err
)
{
if
(
err
)
{
if
(
err
)
{
console
.
info
(
"
Failed to
flush
. Cause:
"
+
err
);
console
.
info
(
"
Failed to
put the value of 'startup'
. Cause:
"
+
err
);
return
;
return
;
}
}
console
.
info
(
"
Succeeded in flushing.
"
);
// observer will be called.
console
.
info
(
"
Succeeded in putting the value of 'startup'.
"
);
preferences
.
flush
(
function
(
err
)
{
if
(
err
)
{
console
.
info
(
"
Failed to flush. Cause:
"
+
err
);
return
;
}
console
.
info
(
"
Succeeded in flushing.
"
);
// observer will be called.
})
preferences
.
off
(
'
change
'
,
observer
);
})
})
preferences
.
off
(
'
change
'
,
observer
);
})
})
})
}
catch
(
err
)
{
}
catch
(
error
)
{
console
.
info
(
"
Failed to flush. code =
"
+
err
.
code
+
"
, message =
"
+
err
.
message
);}
console
.
info
(
"
Failed to flush. code =
"
+
err
.
code
+
"
, message =
"
+
err
.
message
);}
```
```
## ValueType
## ValueType
...
...
zh-cn/application-dev/reference/errorcodes/errorcode-preferences.md
浏览文件 @
93041aad
...
@@ -8,7 +8,9 @@ Failed to delete preferences.
...
@@ -8,7 +8,9 @@ Failed to delete preferences.
删除首选项失败。
删除首选项失败。
**可能原因**
<br>
**可能原因**
<br>
系统错误导致文件删除失败。
系统错误导致文件删除失败,可能原因如下:
1.
要删除的文件不存在。
2.
没有操作权限。
**处理步骤**
<br>
**处理步骤**
<br>
重启设备后再次尝试。
重启设备后再次尝试。
\ No newline at end of file
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录