Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ionic-framework/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/unit-testing/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Push notification 离子推送通知_Push Notification_Ionic Framework_Push - Fatal编程技术网

Push notification 离子推送通知

Push notification 离子推送通知,push-notification,ionic-framework,push,Push Notification,Ionic Framework,Push,我尝试使用Ionic.io发送推送通知 所以我要做的比这个演示更多: 但当我在android上运行时,我有一个错误: app.js:27未捕获类型错误:Ionic.User.anonymousId不是函数 这是我的index.html: <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <meta name="viewport" content="initial

我尝试使用Ionic.io发送推送通知

所以我要做的比这个演示更多:

但当我在android上运行时,我有一个错误:

app.js:27未捕获类型错误:Ionic.User.anonymousId不是函数

这是我的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">
      <meta http-equiv="Content-Security-Policy" content="default-src *; script-src 'self' 'unsafe-inline' 'unsafe-eval' *; style-src  'self' 'unsafe-inline' *">
    <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>
    <script src="js/controllers.js"></script>
    <script src="js/services.js"></script>
  </head>
  <body ng-app="starter">
    <!--
      The nav bar that will be updated as we navigate between views.
    -->
    <ion-nav-bar class="bar-stable">
      <ion-nav-back-button>
      </ion-nav-back-button>
    </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>

还有我的app.js:

  // Ionic Starter App

// angular.module is a global place for creating, registering and retrieving Angular modules
// 'starter' is the name of this angular module example (also set in a <body> attribute in index.html)
// the 2nd parameter is an array of 'requires'
// 'starter.services' is found in services.js
// 'starter.controllers' is found in controllers.js
angular.module('starter', ['ionic', 'ionic.service.core', 'starter.controllers', 'starter.services', 'ionic.service.push'])

.run(function($ionicPlatform) {
    $ionicPlatform.ready(function () {

        var io = Ionic.io();
        var push = new Ionic.Push({
            "onNotification": function (notification) {
                alert('Received push notification!');
            },
            "pluginConfig": {
                "android": {
                    "iconColor": "#0000FF"
                }
            }
        });
        var user = Ionic.User.current();

        if (!user.id) {
            user.id = Ionic.User.anonymousId();
        }

        // Just add some dummy data..
        user.set('name', 'Simon');
        user.set('bio', 'This is my little bio');
        user.save();

        var callback = function (data) {
            push.addTokenToUser(user);
            user.save();
        };
        push.register(callback);


    // Hide the accessory bar by default (remove this to show the accessory bar above the keyboard
    // for form inputs)
    if (window.cordova && window.cordova.plugins && window.cordova.plugins.Keyboard) {
      cordova.plugins.Keyboard.hideKeyboardAccessoryBar(true);
      cordova.plugins.Keyboard.disableScroll(true);

    }
    if (window.StatusBar) {
      // org.apache.cordova.statusbar required
      StatusBar.styleDefault();
    }
  });
})

.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

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

  // Each tab has its own nav history stack:

  .state('tab.dash', {
    url: '/dash',
    views: {
      'tab-dash': {
        templateUrl: 'templates/tab-dash.html',
        controller: 'DashCtrl'
      }
    }
  })

  .state('tab.chats', {
      url: '/chats',
      views: {
        'tab-chats': {
          templateUrl: 'templates/tab-chats.html',
          controller: 'ChatsCtrl'
        }
      }
    })
    .state('tab.chat-detail', {
      url: '/chats/:chatId',
      views: {
        'tab-chats': {
          templateUrl: 'templates/chat-detail.html',
          controller: 'ChatDetailCtrl'
        }
      }
    })

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

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

});
//Ionic Starter应用程序
//angular.module是创建、注册和检索angular模块的全局位置
//“starter”是此角度模块示例的名称(也在index.html中的属性中设置)
//第二个参数是“requires”的数组
//可以在services.js中找到“starter.services”
//可以在controllers.js中找到“starter.controllers”
angular.module('starter'、['ionic','ionic.service.core','starter.Controller','starter.services','ionic.service.push']))
.run(函数($ionicPlatform){
$ionicPlatform.ready(函数(){
var io=Ionic.io();
var push=新的Ionic.push({
“通知”:功能(通知){
警报('收到推送通知!');
},
“pluginConfig”:{
“安卓”:{
“iconColor”:“#0000FF”
}
}
});
var user=Ionic.user.current();
如果(!user.id){
user.id=Ionic.user.anonymousId();
}
//只需添加一些虚拟数据。。
user.set('name','Simon');
set('bio','这是我的小bio');
user.save();
var callback=函数(数据){
push.addTokenToUser(用户);
user.save();
};
推送寄存器(回调);
//默认情况下隐藏附件栏(删除此选项可在键盘上方显示附件栏)
//表格输入)
if(window.cordova&&window.cordova.plugins&&window.cordova.plugins.Keyboard){
插件键盘hideKeyboardAccessoryBar(真);
插件。键盘。禁用滚动(真);
}
如果(窗口状态栏){
//需要org.apache.cordova.statusbar
StatusBar.styleDefault();
}
});
})
.config(函数($stateProvider,$urlRouterProvider){
//Ionic使用AngularUI路由器,它使用状态的概念
//在此处了解更多信息:https://github.com/angular-ui/ui-router
//设置应用程序可以处于的各种状态。
//每个州的控制器都可以在controllers.js中找到
$stateProvider
//设置tabs指令的抽象状态
.state('tab'{
url:“/tab”,
摘要:没错,
templateUrl:'templates/tabs.html'
})
//每个选项卡都有自己的导航历史堆栈:
.state('tab.dash'{
url:“/dash”,
观点:{
“制表符”{
templateUrl:'templates/tab dash.html',
控制器:“DashCtrl”
}
}
})
.state('tab.chats'{
url:“/chats”,
观点:{
“选项卡聊天”:{
templateUrl:'templates/tab chats.html',
控制器:“ChatsCtrl”
}
}
})
.state('tab.chat detail'{
url:“/chats/:chatId”,
观点:{
“选项卡聊天”:{
templateUrl:'templates/chat detail.html',
控制器:“ChatDetailCtrl”
}
}
})
.state('tab.account'{
url:“/account”,
观点:{
“选项卡帐户”:{
templateUrl:'templates/tab account.html',
控制器:“AccountCtrl”
}
}
});
//如果上述状态均不匹配,则将其用作回退
$urlRouterProvider。否则('/tab/dash');
});
我只遵循以下指示:

ionic启动devdactic android推送cd devdactic android推送ionic添加 离子平台web客户端离子插件添加phonegap插件推送 --变量SENDER_ID=您的gcm项目编号IONAL io init

ionic push——google api密钥您的google api密钥ionic配置集 gcm_键入您的gcm项目编号ionic config set dev_push false


您能帮助我吗?

您可能只想从尝试有限推送设置开始,爱奥尼亚公司提供了自己的指南,非常容易遵循:

如果你明白了这一点,你可以向你的应用程序发送通知,应用程序将打开一条包含通知内容的警报消息。然后,您可以开始使用本机推送,这需要几乎相同的代码:

下面是关于如何使用ionic.io框架发送推送的指南: