首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >钛- Android 6权限

钛- Android 6权限
EN

Stack Overflow用户
提问于 2016-04-26 13:55:15
回答 1查看 1.9K关注 0票数 0

当我试图请求Android 6的权限时,我犯了一个错误。

我的职责是:

代码语言:javascript
复制
// check ACCESS_FINE_LOCATION permission
var location2Permission = "android.permission.ACCESS_FINE_LOCATION";
var hasLocation2Permission = Ti.Android.hasPermission(location2Permission);

if(!hasLocation2Permission){
    permissionsToRequest.push(location2Permission);
}

// request permission
Ti.Android.requestPermissions(permissionsToRequest, function(e) {
    if (e.success) {
        Ti.API.info("SUCCESS");
        callback();
    } else {
        Ti.API.info("ERROR: " + e.error);
    }
}); 

错误是:

代码语言:javascript
复制
Message: Uncaught TypeError: Object #<Android> has no method 'requestPermissions'

发生什么事了?因为在钛文档中存在此函数。我使用的是Ti.SDK 5.1.2.GA

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2016-04-26 15:16:43

代码语言:javascript
复制
// The first argument is required on iOS and ignored on other platforms
var hasLocationPermissions = Ti.Geolocation.hasLocationPermissions(Ti.Geolocation.AUTHORIZATION_ALWAYS);
Ti.API.info('Ti.Geolocation.hasLocationPermissions', hasLocationPermissions);

if (hasLocationPermissions) {
    return alert('You already have permission.');
}

Ti.Geolocation.requestLocationPermissions(Ti.Geolocation.AUTHORIZATION_ALWAYS, function(e) {
    Ti.API.info('Ti.Geolocation.requestLocationPermissions', e);

    if (e.success) {

        // Instead, probably call the same method you call if hasLocationPermissions() is true
        alert('You granted permission.');

    } else if (OS_ANDROID) {
        alert('You denied permission for now, forever or the dialog did not show at all because it you denied forever before.');

    } else {

        // We already check AUTHORIZATION_DENIED earlier so we can be sure it was denied now and not before
        Ti.UI.createAlertDialog({
            title: 'You denied permission.',

            // We also end up here if the NSLocationAlwaysUsageDescription is missing from tiapp.xml in which case e.error will say so
            message: e.error
        }).show();
    }
});

要了解更多信息,您可以查看链接文档

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/36867047

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档