harmony 鸿蒙Application Access Control Subsystem Changelog
Application Access Control Subsystem Changelog
cl.access_token.1 Behavior Change When Location Permission Is Requested by requestPermissionsFromUser
Change Impact
Before the change, when requestPermissionsFromUser is called to request the location permission, an authorization dialog box will be displayed in either of the following cases:
The ohos.permission.LOCATION_IN_BACKGROUND permission is requested without the ohos.permission.APPROXIMATELY_LOCATION permission.
The ohos.permission.LOCATION_IN_BACKGROUND and ohos.permission.LOCATION permissions are requested without the ohos.permission.APPROXIMATELY_LOCATION permission.
After the change, the authorization dialog box cannot be displayed in the preceding two cases. When applying for the ohos.permission.LOCATION or ohos.permission.LOCATION_IN_BACKGROUND permission, the application must also apply for or have the ohos.permission.APPROXIMATELY_LOCATION permission.
Adaptation Guide
Refer to requestPermissionsFromUser when modifying EntryAbility.ets and importing GlobalThis.
import abilityAccessCtrl from '@ohos.abilityAccessCtrl';
import { BusinessError } from '@ohos.base';
import common from '@ohos.app.ability.common';
import { GlobalThis } from '../utils/globalThis';
let atManager: abilityAccessCtrl.AtManager = abilityAccessCtrl.createAtManager();
try {
let context: common.UIAbilityContext = GlobalThis.getInstance().getContext('context');
atManager.requestPermissionsFromUser(context, ['ohos.permission.APPROXIMATELY_LOCATION', 'ohos.permission.LOCATION', 'ohos.permission.LOCATION_IN_BACKGROUND']).then((data) => {
console.info('data:' + JSON.stringify(data));
console.info('data permissions:' + data.permissions);
console.info('data authResults:' + data.authResults);
}).catch((err: BusinessError) => {
console.info('data:' + JSON.stringify(err));
})
} catch(err) {
console.log(`catch err->${JSON.stringify(err)}`);
}
你可能感兴趣的鸿蒙文章
harmony 鸿蒙Bundle Manager Subsystem Changelog
- 所属分类: 后端技术
- 本文标签:
热门推荐
-
2、 - 优质文章
-
3、 gate.io
-
8、 golang
-
9、 openharmony
-
10、 Vue中input框自动聚焦