我正试图让推送通知工作在Ionic Android应用程序完全基于一个单一的WebView,通过cordova-plugin-inappbrowser
服务。
$ionicPlatform.ready()
函数从未调用,因此,Ionic.Push
对象从未创建(没有设备令牌记录)。我能够在$ionicPlatform.ready()
被调用之前运行console.log
,在运行函数内部,但不是在$ionicPlatform.ready()
的回调内部。
我错过了什么明显的吗?
app.js
var websiteURL = 'http://example.com';
angular.module('abc', ['ionic'])
.run(function($ionicPlatform) {
$ionicPlatform.ready(function() {
if(window.cordova && window.cordova.plugins.Keyboard) {
// Hide the accessory bar by default (remove this to show the accessory bar above the keyboard
// for form inputs)
cordova.plugins.Keyboard.hideKeyboardAccessoryBar(true);
//stops the viewport from snapping when text inputs are focused. Ionic handles this internally for
// a much nicer keyboard experience.
cordova.plugins.Keyboard.disableScroll(true);
}
if(window.StatusBar) {
StatusBar.styleDefault();
}
// bootstrap for push notifications, set debug to true to use Ionic's push notification platform, not Google's/Apple's
var push = new Ionic.Push({
"debug": true
});
// register the apps token so that the ionic platform can communicate with it
push.register(function(token) {
console.log("Device token:",token.token);
});
});
})
.controller("AppController", function($scope) {
$scope.openWebsite = function()
{
// open up the peoplemovers site in the in app browser window
window.open(websiteURL,'_self');
};
})
index . html
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="initial-scale=1, maximum-scale=1, user-scalable=no, width=device-width">
<title></title>
<link href="lib/ionic/css/ionic.css" rel="stylesheet">
<link href="css/style.css" rel="stylesheet">
<!-- IF using Sass (run gulp sass first), then uncomment below and remove the CSS includes above
<link href="css/ionic.app.css" rel="stylesheet">
-->
<!-- ionic/angularjs js -->
<script src="lib/ionic/js/ionic.bundle.js"></script>
<script src="lib/ionic-platform-web-client/dist/ionic.io.bundle.min.js"></script>
<!-- cordova script (this will be a 404 during development) -->
<!-- Cordova is bootstrapped by ionic-platform-web-client, uncomment this if you remove ionic-platform-web-client... -->
<!-- <script src="cordova.js"></script> -->
<!-- your app's js -->
<script src="js/app.js"></script>
</head>
<body ng-app="abc">
<ion-pane>
<ion-content ng-controller="AppController" ng-init="openWebsite()" padding="true">
</ion-content>
</ion-pane>
</body>
</html>
编辑
我重新安装了Ionic, Cordova, node, npm, Android Studio和Android sdk。
该窗口的URL。open calls有一个文件选择按钮,当从Android"Gallery"选项卡中选择文件时,该按钮会导致应用程序崩溃,这是由于一些Android权限问题。一个论坛帖子建议添加cordova-plugin-camera
插件来添加必要的权限,这确实解决了这个问题。
然而,现在没有进行$ionicPlatform.ready
调用。即使我运行ionic plugin remove cordova-plugin-camera
,我似乎也不能让$ionicPlatform.ready
再调用了。
我没有收到任何错误信息,应用程序加载良好。这种行为在LG Android 6.0手机、Android模拟器(SDK 23)和Genymotion模拟器上的测试是一致的。
有一个更简单的方法来获得文件权限从手机除了相机插件?如果没有,是否有一个设置或配置行,我需要让$ionicPlatform.ready
函数触发?
这是新的app.js:
var websiteURL = 'http://example.com';
angular.module('lmgapp', ['ionic'])
.run(function($ionicPlatform) {
$ionicPlatform.ready(function() {
console.log('firing');
if(window.cordova && window.cordova.plugins.Keyboard) {
cordova.plugins.Keyboard.hideKeyboardAccessoryBar(true);
cordova.plugins.Keyboard.disableScroll(true);
}
if(window.StatusBar) {
StatusBar.styleDefault();
}
});
})
.controller("AppController", function($scope) {
$scope.openWebsite = function()
{
console.log('in the controller');
// open up the site in the in app browser window
window.open(websiteURL,'_self');
};
});
重新安装后的新index.html:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="initial-scale=1, maximum-scale=1, user-scalable=no, width=device-width">
<title></title>
<link href="lib/ionic/css/ionic.css" rel="stylesheet">
<link href="css/style.css" rel="stylesheet">
<!-- ionic/angularjs js -->
<script src="lib/ionic/js/ionic.bundle.js"></script>
<!-- cordova script (this will be a 404 during development) -->
<script src="cordova.js"></script>
<!-- your app's js -->
<script src="js/app.js"></script>
</head>
<body ng-app="lmgapp">
<ion-pane>
<ion-content ng-controller="AppController" ng-init="openWebsite()">
</ion-content>
</ion-pane>
</body>
</html>
$ionicPlatform。准备不是开火,因为你没有科多瓦。