我在项目中遇到了一个关键问题。我是Appcelerator的新手,我不知道如何解决它。这个错误没有进入我的机器。但是在我使用的另一台机器上也是如此。
第一个文件
/**
* Hepers for run-time permissions.
*/
// DEPENDENCIES
var dialogs = require('alloy/dialogs');
// PUBLIC INTERFACE
exports.requestLocationPermissions = requestLocationPermissions;
// PRIVATE FUNCTIONS
function requestLocationPermissions(authorizationType, callback) {
// FIXME: Always returns false on Android 6
// https://jira.appcelerator.org/browse/TIMOB-23135
if (OS_IOS && !Ti.Geolocation.locationServicesEnabled) {
return callback({
success : false,
error : 'Location Services Disabled'
});
}
// Permissions already granted
if (Ti.Geolocation.hasLocationPermissions(authorizationType)) {
return callback({
success : true
});
}
// On iOS we can determine why we do not have permission
if (OS_IOS) {
if (Ti.Geolocation.locationServicesAuthorization === Ti.Geolocation.AUTHORIZATION_RESTRICTED) {
return callback({
success : false,
error : 'Your device policy does not allow Geolocation'
});
} else if (Ti.Geolocation.locationServicesAuthorization === Ti.Geolocation.AUTHORIZATION_DENIED) {
dialogs.confirm({
title : 'You denied permission before',
message : 'Tap Yes to open the Settings app to restore permissions, then try again.',
callback : function() {
Ti.Platform.openURL(Ti.App.iOS.applicationOpenSettingsURL);
}
});
// return success:false without an error since we've informed the user already
return callback({
success : false
});
}
}
// Request permission
Ti.Geolocation.requestLocationPermissions(Ti.Geolocation.AUTHORIZATION_WHEN_IN_USE, function(e) {
if (!e.success) {
return callback({
success : false,
error : e.error || 'Failed to request Location Permissions'
});
} else {
callback({
success : true
});
}
});
}
第二个文件(我在这里添加First(文件名:Permi)。
var Perm = require('Permi');
$.window.addEventListener("focus", function(e) {
Perm.requestLocationPermissions(Ti.Geolocation.AUTHORIZATION_WHEN_IN_USE, function(e) {
if (!e.success) {
if (e.error) {
}
return;
} else {
Titanium.Geolocation.getCurrentPosition(function(e) {
if (e.success == false) {
} else {
longitude = e.coords.longitude;
latitude = e.coords.latitude;
Titanium.Geolocation.reverseGeocoder(latitude, longitude, function(e) {
if (e.success) {
var places = e.places;
if (places && places.length) {
driverCity = places[0].city;
driverState = places[0].address;
annotation.title = e.places[0].displayAddress;
} else {
}
}
});
$.mapview.applyProperties({
mapType : Alloy.Globals.Map.NORMAL_TYPE,
region : {
latitude : latitude,
longitude : longitude,
latitudeDelta : 0.05,
longitudeDelta : 0.05,
},
animate : true,
regionFit : true,
userLocation : false,
});
var annotation = Alloy.Globals.Map.createAnnotation({
latitude : latitude,
longitude : longitude,
title : "The DEMO",
pincolor : Alloy.Globals.Map.ANNOTATION_RED,
myid : 1
});
$.mapview.addAnnotation(annotation);
}
});
}
});
this.removeEventListener('focus', arg);
});
任何帮助都将深表感谢。谢谢
答案 0 :(得分:0)
请使用Titanium SDK 5.4.0.GA
或更高版本,因为该版本包含有关Android 6上运行时权限处理的重大更改。有关详细信息,请参阅Ti.Android.requestPermissions
。