我使用 PhoneGap 将 AngularJS 应用程序转换为 Android 和 iOS。我需要升级到适用于 iOS 9 的最新版本的 PhoneGap,但它破坏了 Android 应用程序。
具体来说,它会阻止 ngResource 工作,因此我无法从我的服务器获取身份验证 token 。
Android 在 config.xml 首选项设置为
时工作正常<preference name="phonegap-version" value="3.7.0" />
Android 甚至无法使用其中任何一个向服务器发送请求
<preference name="phonegap-version" value="cli-5.1.1" />
<preference name="phonegap-version" value="cli-5.2.0" />
这是我的 AngularJs 登录函数和 ngResource 工厂。
$scope.login = function () {
AuthenticationService.get({
'clientId':$rootScope.clientId,
'clientSecret':$rootScope.clientSecret,
'username':$scope.loginData.username,
'password':$scope.loginData.password
},
function(data){},
function(error){
toastr.error('Authentication failed, please try again.');
}
)
.$promise.then(function(response){
...
});
};
.factory( 'AuthenticationService', function($resource, $rootScope) {
return $resource(
$rootScope.url+'/oauth/v2/token?client_id=:clientId&client_secret=:clientSecret&grant_type=password&username=:username&password=:password',
{
clientId:'@clientId',
clientSecret:'@clientSecret',
username:'@username',
password:'@password'
},
{
get: { method: 'JSONP', params: { callback: 'JSON_CALLBACK' }, isArray: false }
}
);
})
有谁知道新版本的 PhoneGap for Android 发生了什么变化可能会导致这种情况?
最佳答案
请在您的 config.xml 中添加 whitelist
插件引用
<gap:plugin name="cordova-plugin-whitelist" source="npm" />
关于Android 应用停止使用最新版本的 PhoneGap Build,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32916444/