未验证 提交 586887d0 编写于 作者: O openharmony_ci 提交者: Gitee

!14984 分布式数据对象开发指导-开发步骤增加STAGE模型请求权限示例

Merge pull request !14984 from wangxiyue/monthly_distributedobject_guide
......@@ -111,18 +111,43 @@
这个权限还需要在应用首次启动的时候弹窗获取用户授权。
```js
// FA模型
import featureAbility from '@ohos.ability.featureAbility';
function grantPermission() {
console.info('grantPermission');
let context = featureAbility.getContext();
context.requestPermissionsFromUser(['ohos.permission.DISTRIBUTED_DATASYNC'], 666, function (result) {
console.info(`result.requestCode=${result.requestCode}`)
console.info(`requestPermissionsFromUser CallBack`);
})
console.info('end grantPermission');
}
grantPermission();
```
```ts
// Stage模型
import UIAbility from '@ohos.app.ability.UIAbility';
let context = null;
class EntryAbility extends UIAbility {
onWindowStageCreate(windowStage) {
context = this.context;
}
}
function grantPermission() {
let permissions = ['ohos.permission.DISTRIBUTED_DATASYNC'];
context.requestPermissionsFromUser(permissions).then((data) => {
console.log('success: ${data}');
}).catch((error) => {
console.error('failed: ${error}');
});
}
grantPermission();
```
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册