提交 d87d33e6 编写于 作者: C chenshixu1
上级 502dce4a
...@@ -14,7 +14,8 @@ ...@@ -14,7 +14,8 @@
## 导入模块 ## 导入模块
```ts ```ts
import systemparameter from '@ohos.systemparameter' import systemparameter from '@ohos.systemparameter';
import { BusinessError } from '@ohos.base';
``` ```
## systemparameter.getSync<sup>(deprecated)</sup> ## systemparameter.getSync<sup>(deprecated)</sup>
...@@ -42,7 +43,7 @@ getSync(key: string, def?: string): string ...@@ -42,7 +43,7 @@ getSync(key: string, def?: string): string
```ts ```ts
try { try {
var info = systemparameter.getSync("const.ohos.apiversion"); let info = systemparameter.getSync("const.ohos.apiversion");
console.log(JSON.stringify(info)); console.log(JSON.stringify(info));
} catch(e) { } catch(e) {
console.log("getSync unexpected error: " + e); console.log("getSync unexpected error: " + e);
...@@ -68,7 +69,7 @@ get(key: string, callback: AsyncCallback&lt;string&gt;): void ...@@ -68,7 +69,7 @@ get(key: string, callback: AsyncCallback&lt;string&gt;): void
```ts ```ts
try { try {
systemparameter.get("const.ohos.apiversion", function (err, data) { systemparameter.get("const.ohos.apiversion", (err:BusinessError, data:string) => {
if (err == undefined) { if (err == undefined) {
console.log("get test.parameter.key value success:" + data) console.log("get test.parameter.key value success:" + data)
} else { } else {
...@@ -99,7 +100,7 @@ get(key: string, def: string, callback: AsyncCallback&lt;string&gt;): void ...@@ -99,7 +100,7 @@ get(key: string, def: string, callback: AsyncCallback&lt;string&gt;): void
```ts ```ts
try { try {
systemparameter.get("const.ohos.apiversion", "default", function (err, data) { systemparameter.get("const.ohos.apiversion", "default", (err:BusinessError, data:string) => {
if (err == undefined) { if (err == undefined) {
console.log("get test.parameter.key value success:" + data) console.log("get test.parameter.key value success:" + data)
} else { } else {
...@@ -136,10 +137,10 @@ get(key: string, def?: string): Promise&lt;string&gt; ...@@ -136,10 +137,10 @@ get(key: string, def?: string): Promise&lt;string&gt;
```ts ```ts
try { try {
var p = systemparameter.get("const.ohos.apiversion"); let p = systemparameter.get("const.ohos.apiversion");
p.then(function (value) { p.then((value:string) => {
console.log("get test.parameter.key success: " + value); console.log("get test.parameter.key success: " + value);
}).catch(function (err) { }).catch((err:BusinessError) => {
console.log("get test.parameter.key error: " + err.code); console.log("get test.parameter.key error: " + err.code);
}); });
} catch(e) { } catch(e) {
...@@ -201,7 +202,7 @@ set(key: string, value: string, callback: AsyncCallback&lt;void&gt;): void ...@@ -201,7 +202,7 @@ set(key: string, value: string, callback: AsyncCallback&lt;void&gt;): void
```ts ```ts
try { try {
systemparameter.set("test.parameter.key", "testValue", function (err, data) { systemparameter.set("test.parameter.key", "testValue", (err:BusinessError, data:string) =>{
if (err == undefined) { if (err == undefined) {
console.log("set test.parameter.key value success :" + data) console.log("set test.parameter.key value success :" + data)
} else { } else {
...@@ -241,10 +242,10 @@ set(key: string, value: string): Promise&lt;void&gt; ...@@ -241,10 +242,10 @@ set(key: string, value: string): Promise&lt;void&gt;
```ts ```ts
try { try {
var p = systemparameter.set("test.parameter.key", "testValue"); let p = systemparameter.set("test.parameter.key", "testValue");
p.then(function (value) { p.then((value:string) => {
console.log("set test.parameter.key success: " + value); console.log("set test.parameter.key success: " + value);
}).catch(function (err) { }).catch((err:BusinessError) => {
console.log(" set test.parameter.key error: " + err.code); console.log(" set test.parameter.key error: " + err.code);
}); });
} catch(e) { } catch(e) {
......
...@@ -13,7 +13,8 @@ ...@@ -13,7 +13,8 @@
## 导入模块 ## 导入模块
```ts ```ts
import systemparameter from '@ohos.systemParameterEnhance' import systemparameter from '@ohos.systemParameterEnhance';
import { BusinessError } from '@ohos.base';
``` ```
## systemparameter.getSync ## systemparameter.getSync
...@@ -41,7 +42,7 @@ getSync(key: string, def?: string): string ...@@ -41,7 +42,7 @@ getSync(key: string, def?: string): string
```ts ```ts
try { try {
var info = systemparameter.getSync("const.ohos.apiversion"); let info = systemparameter.getSync("const.ohos.apiversion");
console.log(JSON.stringify(info)); console.log(JSON.stringify(info));
} catch(e) { } catch(e) {
console.log("getSync unexpected error: " + e); console.log("getSync unexpected error: " + e);
...@@ -67,7 +68,7 @@ get(key: string, callback: AsyncCallback&lt;string&gt;): void ...@@ -67,7 +68,7 @@ get(key: string, callback: AsyncCallback&lt;string&gt;): void
```ts ```ts
try { try {
systemparameter.get("const.ohos.apiversion", function (err, data) { systemparameter.get("const.ohos.apiversion", (err:BusinessError, data:string) => {
if (err == undefined) { if (err == undefined) {
console.log("get test.parameter.key value success:" + data) console.log("get test.parameter.key value success:" + data)
} else { } else {
...@@ -98,7 +99,7 @@ get(key: string, def: string, callback: AsyncCallback&lt;string&gt;): void ...@@ -98,7 +99,7 @@ get(key: string, def: string, callback: AsyncCallback&lt;string&gt;): void
```ts ```ts
try { try {
systemparameter.get("const.ohos.apiversion", "default", function (err, data) { systemparameter.get("const.ohos.apiversion", "default", (err:BusinessError, data:string) => {
if (err == undefined) { if (err == undefined) {
console.log("get test.parameter.key value success:" + data) console.log("get test.parameter.key value success:" + data)
} else { } else {
...@@ -135,10 +136,10 @@ get(key: string, def?: string): Promise&lt;string&gt; ...@@ -135,10 +136,10 @@ get(key: string, def?: string): Promise&lt;string&gt;
```ts ```ts
try { try {
var p = systemparameter.get("const.ohos.apiversion"); let p = systemparameter.get("const.ohos.apiversion");
p.then(function (value) { p.then((value:string) => {
console.log("get test.parameter.key success: " + value); console.log("get test.parameter.key success: " + value);
}).catch(function (err) { }).catch((err:BusinessError) => {
console.log("get test.parameter.key error: " + err.code); console.log("get test.parameter.key error: " + err.code);
}); });
} catch(e) { } catch(e) {
...@@ -191,7 +192,7 @@ set(key: string, value: string, callback: AsyncCallback&lt;void&gt;): void ...@@ -191,7 +192,7 @@ set(key: string, value: string, callback: AsyncCallback&lt;void&gt;): void
```ts ```ts
try { try {
systemparameter.set("test.parameter.key", "testValue", function (err, data) { systemparameter.set("test.parameter.key", "testValue", (err:BusinessError, data:string) => {
if (err == undefined) { if (err == undefined) {
console.log("set test.parameter.key value success :" + data) console.log("set test.parameter.key value success :" + data)
} else { } else {
...@@ -227,10 +228,10 @@ set(key: string, value: string): Promise&lt;void&gt; ...@@ -227,10 +228,10 @@ set(key: string, value: string): Promise&lt;void&gt;
```ts ```ts
try { try {
var p = systemparameter.set("test.parameter.key", "testValue"); let p = systemparameter.set("test.parameter.key", "testValue");
p.then(function (value) { p.then((value:string) => {
console.log("set test.parameter.key success: " + value); console.log("set test.parameter.key success: " + value);
}).catch(function (err) { }).catch((err:BusinessError) => {
console.log(" set test.parameter.key error: " + err.code); console.log(" set test.parameter.key error: " + err.code);
}); });
} catch(e) { } catch(e) {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册