js hap第一次打开,手动授权权限失败

Signed-off-by: wuxiaodan <wuxiaodan5@huawei.com>
This commit is contained in:
wuxiaodan 2022-11-02 20:05:54 +08:00
parent 692b4d77d1
commit bd08cdcb6d
4 changed files with 43 additions and 29 deletions

View File

@ -12,11 +12,28 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import {Core} from 'deccjsunit/index';
import featureAbility from '@ohos.ability.featureAbility';
export default {
onCreate() {
console.info('TestApplication onCreate');
console.info('AceApplication onCreate');
const core = Core.getInstance()
core.init()
const configService = core.getDefaultService('config')
configService.setConfig(this)
console.info('Calc[IndexPage] grantPermission')
let context = featureAbility.getContext()
context.requestPermissionsFromUser(['ohos.permission.DISTRIBUTED_DATASYNC'], 666, function (result) {
console.info('Calc[IndexPage] grantPermission,requestPermissionsFromUser,'+result.requestCode)
setTimeout(()=>{
require('./test/List.test')
core.execute()
},1000)
})
},
onDestroy() {
console.info('TestApplication onDestroy');
console.info('AceApplication onDestroy');
}
};

View File

@ -26,23 +26,11 @@ export default {
},
onInit() {
this.title = this.$t('strings.world');
this.grantPermission();
},
onShow() {
},
onShow() {
console.info('onShow finish')
const core = Core.getInstance()
core.init()
require('../../test/List.test')
core.execute()
},
onReady() {
},
grantPermission() {
console.info(logTag + '[IndexPage] grantPermission')
let context = featureAbility.getContext()
context.requestPermissionsFromUser(['ohos.permission.DISTRIBUTED_DATASYNC'], 666, function (result) {
console.info(logTag + '[IndexPage] grantPermission,requestPermissionsFromUser,' + result.requestCode)
},
onReady() {
},
})
},
}

View File

@ -12,11 +12,28 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import {Core} from 'deccjsunit/index';
import featureAbility from '@ohos.ability.featureAbility';
export default {
onCreate() {
console.info('TestApplication onCreate');
console.info('AceApplication onCreate');
const core = Core.getInstance()
core.init()
const configService = core.getDefaultService('config')
configService.setConfig(this)
console.info('Calc[IndexPage] grantPermission')
let context = featureAbility.getContext()
context.requestPermissionsFromUser(['ohos.permission.DISTRIBUTED_DATASYNC'], 666, function (result) {
console.info('Calc[IndexPage] grantPermission,requestPermissionsFromUser,'+result.requestCode)
setTimeout(()=>{
require('./test/List.test')
core.execute()
},1000)
})
},
onDestroy() {
console.info('TestApplication onDestroy');
console.info('AceApplication onDestroy');
}
};

View File

@ -20,14 +20,6 @@ export default {
},
onInit() {
this.grantPermission();
},
grantPermission() {
console.info('Calc[IndexPage] grantPermission')
let context = featureAbility.getContext()
context.requestPermissionsFromUser(['ohos.permission.DISTRIBUTED_DATASYNC'], 666, function (result) {
console.info('Calc[IndexPage] grantPermission,requestPermissionsFromUser,'+result.requestCode)
})
},
}