$ ionicPlatform.ready()没有触发,Android

时间:2016-09-03 00:34:38

标签: javascript android angularjs cordova ionic-framework

我正在尝试使用完全基于单个WebView的Ionic Android应用程序处理推送通知,通过cordova-plugin-inappbrowser提供。

$ionicPlatform.ready()函数从不调用,因此永远不会创建Ionic.Push对象(不记录设备令牌)。我可以在运行函数内调用console.log之前运行$ionicPlatform.ready(),但不能在$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。

window.open调用的URL有一个文件选择按钮,用于在从Android“图库”选项卡中选择文件时使应用程序崩溃,这是由于某些Android权限问题造成的。一篇论坛帖子建议添加cordova-plugin-camera插件以添加必要的权限,此DID可解决此问题。

但是,现在没有拨打$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>

1 个答案:

答案 0 :(得分:0)

$ ionicPlatform.ready没有开火,因为你没有科尔多瓦。它被注释掉了。