1

全部,

我决定尝试使用 ionic 和 phonegap 构建。在我尝试使用插件之前,一切都很顺利。一旦我尝试调用插件,我就会得到

未找到插件“设备”,或者不是 CDVPlugin

在 weinre 控制台中,我得到

5 秒后 deviceready 未触发。频道未触发:onCordovaInfoReady

我可以在 Phonegap Build 上看到插件被识别,如果我下载 ipa 文件并展开内容,我可以看到一切都在那里。我怀疑这是一个离子问题,因为我正在与 Phonegap 的 Ismael 合作(超级响应和乐于助人,顺便说一句)。他给我发了一个 phonegap 示例,根据他的配置设置和代码,我运行相同但仍然有问题。如果有人可以帮助我,我将不胜感激。

我做了什么

  1. 须藤 npm 安装离子 -g
  2. sudo npm install phonegap -g
  3. 须藤 npm 安装科尔多瓦 -g
  4. sudo 离子开始 xxxx
  5. sudo 离子平台添加 ios
  6. 光盘 xxxx
  7. 光盘 www
  8. phonegap 远程构建 ios

环境

  • OSX 10.9.2
  • 运行 iOS 7.1 的设备 iPhone 4s
  • PhoneGap Build 项目版本 3.3.0
  • 离子-v1.0.0-beta.1
  • phonegap CLI 3.4.0-0.19.8
  • 科尔多瓦 CLI 3.4.0-0.1.3

配置文件

<?xml version='1.0' encoding='utf-8'?>
<widget id="com.xxxx.xxxx" version="0.0.1" xmlns="http://www.w3.org/ns/widgets" xmlns:cdv="http://cordova.apache.org/ns/1.0" xmlns:gap="http://phonegap.com/ns/1.0">
    <name>xxxxxxxx</name>
    <description>
        xxxx
    </description>
    <author email="xxxx@gmail.com">
        xxxx
    </author>
    <content src="index.html" />
    <access origin="*" />
    <preference name="phonegap-version" value="3.3.0" />
    <preference name="fullscreen" value="true" />
    <preference name="webviewbounce" value="false" />
    <preference name="UIWebViewBounce" value="false" />
    <preference name="DisallowOverscroll" value="true" />
    <gap:plugin name="org.apache.cordova.device" />
    <gap:plugin name="org.apache.cordova.media" />
    <gap:plugin name="org.apache.cordova.media-capture" />
    <gap:plugin name="org.apache.cordova.file" />
</widget>

索引.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>Ionic Seed App</title>

    <!-- ionic css -->
    <link href="lib/css/ionic.css" rel="stylesheet">

    <!-- your app's css -->
    <link href="css/app.css" rel="stylesheet">

    <!-- ionic/angularjs scripts -->
    <script src="lib/js/ionic.bundle.js"></script>

    <script src="lib/js/moment.min.js"></script>

    <!-- cordova script (this will be a 404 during development) -->
    <script src="cordova.js"></script>
    <!-- your app's script -->
    <script src="js/app.js"></script>
    <script src="js/services.js"></script>
    <script src="js/controllers.js"></script>

  </head>

  <body ng-app="xxxx" animation="slide-left-right-ios7">

    <!--
      The nav bar that will be updated as we navigate between views
      Additional attributes set its look, ion-nav-bar animation and icons
      Icons provided by Ionicons: http://ionicons.com/
    -->
    <ion-nav-bar type="bar-positive"
             animation="nav-title-slide-ios7"
             back-button-type="button-icon button-clear"
             back-button-icon="ion-ios7-arrow-back"></ion-nav-bar>

    <!--
      The views will be rendered in the <ion-nav-view> directive below
      Templates are in the /templates folder (but you could also
      have templates inline in this html file if you'd like).
    -->
    <ion-nav-view></ion-nav-view>

  </body>
</html>    

应用程序.js

var app = angular.module('xxxx', ['ionic', 'xxxx.services', 'xxxx.controllers']);

app.value('globals', {
    'ACSKey': 'xyz',
    'session_id': '',
    'logged_in_userId': ''
});

app.config(function($stateProvider, $urlRouterProvider) {

    // Ionic uses AngularUI Router which uses the concept of states
    // Learn more here: https://github.com/angular-ui/ui-router
    // Set up the various states which the app can be in.
    // Each state's controller can be found in controllers.js
    $stateProvider

    .state('login', {
        url: "/login",
        templateUrl: "templates/login.html",
        controller: 'LoginCtrl'
    })

    .state('register', {
        url: "/register",
        templateUrl: "templates/register.html",
        controller: 'RegisterCtrl'
    })

    // setup an abstract state for the tabs directive
    .state('tab', {
        url: "/tab",
        abstract: true,
        templateUrl: "templates/tabs.html"
    })

    .state('main', {
        url: "/main",
        templateUrl: "templates/main.html",
        controller: "MainCtrl"
    })

    .state('premise', {
        url: "/premise",
        templateUrl: "templates/premise.html",
        controller: "PremiseOfTheDayCtrl"
    })

    .state('friends', {
        url: "/friends",
        templateUrl: "templates/friends.html",
        controller: "FriendsCtrl"
    })

    .state('tab.about', {
        url: '/about',
        views: {
            'about-tab': {
                templateUrl: 'templates/about.html'
            }
        }
    });

    // if none of the above states are matched, use this as the fallback
    $urlRouterProvider.otherwise('/login');

});

app.run(function($rootScope, $location, $ionicPlatform) {

    document.addEventListener("deviceready", onDeviceReady, false);

    function onDeviceReady() {
        alert('deviceready');
    }

    // $ionicPlatform.ready(function() {
    //     // Initialize plugin here
    //     console.log('ionicPlatform.ready');
    // });

    var _session_id = window.localStorage.getItem("_session_id");
    var logged_in_userId = window.localStorage.getItem("logged_in_userId");

    if (_session_id === null || _session_id === '') {
        // no logged user, we should be going to #login
        if (next.templateUrl === "templates/login.html") {
            // already going to #login, no redirect needed
        } else {
            // not going to #login, we should redirect now
            $location.path("/login");
        }
    } else {
        $location.path("/main");
    }

});
4

2 回答 2

0

我花了相当多的时间在 Phonegap Build 上测试插件,发现这些插件适用于 Phonegap 2.9,但在 Phonegap Build 上的 3.1 和 3.3 版本中会中断。

没有解决方法,我求助于在本地为 iOS 和 Android 构建。

即使在本地构建,Phonegap 平台也存在一些插件问题,这个脚本在 iOS 端为我修复了它:

#!/bin/bash
echo "Killing xcode..."
killall Xcode

rm -rf platforms/ios
rm plugins/ios.json
cordova platform add ios
cordova build ios
node .cordova/hooks/after_build/copy_icons_screens.js 
## Above isn't being caught by the hook during iOS for some reason. Hook is caught by Android build
open platforms/ios/*.xcodeproj

在 Android 端,请务必清理 CordovaLib 项目,然后清理您的 AppName 项目 - 顺序很重要。

这里的复制图标和安装插件钩子也是关键:
http ://devgirl.org/2013/11/12/three-hooks-your-cordovaphonegap-project-needs/

于 2014-04-01T04:27:41.503 回答
0

显然等了几个星期,然后再次尝试让 Phonegap Build 赶上来。当我再次尝试时,插件被识别并显示我的录音对话框......

于 2014-04-20T23:42:47.067 回答