fix: 解决授权依次授权的问题
This commit is contained in:
parent
b4cd064c67
commit
3f6137f4f2
@ -11,6 +11,7 @@ import { InitTable } from '../utils/table/Operation';
|
||||
import FileUtils from '../utils/FileUtils';
|
||||
import { EntryTag } from '../config';
|
||||
import { dConsole } from '../utils/LogWorker';
|
||||
import { UseAuth } from '../utils/Common';
|
||||
|
||||
export default class EntryAbility extends UIAbility {
|
||||
async onCreate(want: Want, launchParam: AbilityConstant.LaunchParam) {
|
||||
@ -24,7 +25,7 @@ export default class EntryAbility extends UIAbility {
|
||||
if (data !== '' && data !== undefined) {
|
||||
const result: EnvironmentConfigurationType = JSON.parse(data)
|
||||
AppStorage.setOrCreate<EnvironmentConfigurationType>("EnvironmentConfiguration", result)
|
||||
if(result.isOpenLog){
|
||||
if (result.isOpenLog) {
|
||||
dConsole.init(result.isOpenLog)
|
||||
}
|
||||
const host = `http://${result.centerIp}:${result.centerPort}`
|
||||
@ -46,6 +47,7 @@ export default class EntryAbility extends UIAbility {
|
||||
|
||||
async onWindowStageCreate(windowStage: window.WindowStage) {
|
||||
console.log(EntryTag, "onWindowStageCreate", "窗口创建完成")
|
||||
await UseAuth(this.context)
|
||||
const windowClass = await windowStage.getMainWindow();
|
||||
let rect = windowClass.getWindowProperties().windowRect
|
||||
let width = rect.width
|
||||
|
||||
@ -5,7 +5,7 @@ import { HomeTag, JudgeConfig } from '../config';
|
||||
import VoiceAnnounce from './judgeSDK/utils/voiceAnnouncements';
|
||||
import { BaseInfoType } from '../model/Common';
|
||||
import { CarInfoType, InitializeTheCentralTableType, MASYSSETTableType, TimeSynchronizationRspBody } from '../model';
|
||||
import { CreateAlbum, GetCarInfo, GetDeviceInfo, SetCurrentTime, UseAuth } from './Index/utils';
|
||||
import { CreateAlbum, GetCarInfo, GetDeviceInfo, SetCurrentTime } from './Index/utils';
|
||||
import { GetSyncData, InitializeTheCentralTable } from '../utils/table/Operation';
|
||||
import { BusinessError } from '@ohos.base';
|
||||
import { delPic } from '../utils/Video';
|
||||
@ -60,7 +60,7 @@ struct Index {
|
||||
}
|
||||
|
||||
async aboutToAppear() {
|
||||
await UseAuth(this.context)
|
||||
dConsole.log("权限首页 aboutToAppear")
|
||||
this.ratio = AppStorage.get<BaseInfoType>('baseInfo')?.ratio || 1.4
|
||||
this.angle = 0
|
||||
AppStorage.set('lsh', '1111111111111')
|
||||
@ -76,8 +76,7 @@ struct Index {
|
||||
}
|
||||
|
||||
async onPageShow(): Promise<void> {
|
||||
dConsole.log("首页 onPageShow2")
|
||||
await UseAuth(this.context)
|
||||
dConsole.log("权限首页 onPageShow2")
|
||||
if (!this.isPlay) {
|
||||
this.avPlayer.playAudio(['welcome.wav'])
|
||||
this.isPlay = true
|
||||
|
||||
@ -14,8 +14,6 @@ import {
|
||||
} from '../../model';
|
||||
import dayTs from '../../utils/Date';
|
||||
import { obtainCarExamInfo, timeSynchronization } from '../../api';
|
||||
import abilityAccessCtrl, { Permissions } from '@ohos.abilityAccessCtrl';
|
||||
import { BusinessError } from '@ohos.base';
|
||||
import systemTime from '@ohos.systemTime';
|
||||
import { VideoConfigData } from '../../mock';
|
||||
import FileUtils from '../../utils/FileUtils';
|
||||
@ -61,37 +59,6 @@ export async function GetCarInfo(): Promise<CarInfoType> {
|
||||
return {}
|
||||
}
|
||||
|
||||
// 获取授权
|
||||
export async function UseAuth(context: common.UIAbilityContext): Promise<boolean> {
|
||||
return new Promise((resolve, reject) => {
|
||||
const permissions: Array<Permissions> =
|
||||
[
|
||||
"ohos.permission.SET_TIME",
|
||||
"ohos.permission.READ_IMAGEVIDEO",
|
||||
"ohos.permission.DISTRIBUTED_DATASYNC",
|
||||
"ohos.permission.CONNECTIVITY_INTERNAL",
|
||||
"ohos.permission.CAMERA",
|
||||
"ohos.permission.READ_MEDIA",
|
||||
"ohos.permission.WRITE_MEDIA",
|
||||
"ohos.permission.FILE_ACCESS_MANAGER"
|
||||
];
|
||||
abilityAccessCtrl.createAtManager().requestPermissionsFromUser(context, permissions).then(res => {
|
||||
let grantStatus: Array<number> = res.authResults;
|
||||
let length: number = grantStatus.length;
|
||||
resolve(true)
|
||||
for (let i = 0; i < length; i++) {
|
||||
if (grantStatus[i] !== 0) {
|
||||
reject(false)
|
||||
return;
|
||||
}
|
||||
}
|
||||
}).catch((err: BusinessError) => {
|
||||
dConsole.error("获取权限失败", JSON.stringify(err))
|
||||
reject(false)
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
//获取时间同步
|
||||
export async function SetCurrentTime(): Promise<void> {
|
||||
let deviceNo: string = AppStorage.get<string>('deviceNo')!;
|
||||
|
||||
@ -4,6 +4,8 @@ import { BusinessError } from '@ohos.base';
|
||||
import { CommonFileTag } from '../config';
|
||||
import abilityAccessCtrl, { Permissions } from '@ohos.abilityAccessCtrl';
|
||||
import Prompt from '@system.prompt';
|
||||
import { dConsole } from './LogWorker';
|
||||
import common from '@ohos.app.ability.common';
|
||||
|
||||
enum timeType {
|
||||
fulltime = 1
|
||||
@ -253,4 +255,43 @@ export function ApplyForAuthorization(context: Context, permissionList: Array<Pe
|
||||
})
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
/*
|
||||
* 使用权限
|
||||
* @param context 上下文
|
||||
* @return 返回一个 Promise,解析为 true 如果授权成功,否则为 false
|
||||
*/
|
||||
export async function UseAuth(context: common.UIAbilityContext): Promise<boolean> {
|
||||
dConsole.log("权限授权开始1")
|
||||
return new Promise((resolve, reject) => {
|
||||
const permissions: Array<Permissions> =
|
||||
[
|
||||
"ohos.permission.SET_TIME",
|
||||
"ohos.permission.READ_IMAGEVIDEO",
|
||||
"ohos.permission.DISTRIBUTED_DATASYNC",
|
||||
"ohos.permission.CONNECTIVITY_INTERNAL",
|
||||
"ohos.permission.CAMERA",
|
||||
"ohos.permission.READ_MEDIA",
|
||||
"ohos.permission.WRITE_MEDIA",
|
||||
"ohos.permission.FILE_ACCESS_MANAGER"
|
||||
];
|
||||
dConsole.log("权限授权开始2")
|
||||
abilityAccessCtrl.createAtManager().requestPermissionsFromUser(context, permissions).then(res => {
|
||||
let grantStatus: Array<number> = res.authResults;
|
||||
let length: number = grantStatus.length;
|
||||
dConsole.log("权限", length)
|
||||
dConsole.log("权限状态", JSON.stringify(grantStatus))
|
||||
resolve(true)
|
||||
for (let i = 0; i < length; i++) {
|
||||
if (grantStatus[i] !== 0) {
|
||||
reject(false)
|
||||
return;
|
||||
}
|
||||
}
|
||||
}).catch((err: BusinessError) => {
|
||||
dConsole.error("获取权限失败", JSON.stringify(err))
|
||||
reject(false)
|
||||
})
|
||||
})
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user