Titanium - Android 6 权限
Titanium - Android 6 permissions
我在 Android 6.
上尝试请求权限时遇到错误
我的职能是:
// 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);
}
});
错误是:
Message: Uncaught TypeError: Object #<Android> has no method 'requestPermissions'
发生什么事了?因为在 Titanium Docs 中存在这个功能。我正在使用 Ti.SDK 5.1.2.GA
// 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();
}
});
中查看更多内容
我在 Android 6.
上尝试请求权限时遇到错误我的职能是:
// 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);
}
});
错误是:
Message: Uncaught TypeError: Object #<Android> has no method 'requestPermissions'
发生什么事了?因为在 Titanium Docs 中存在这个功能。我正在使用 Ti.SDK 5.1.2.GA
// 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();
}
});
中查看更多内容