离子推不工作 - 用户未注册 [英] Ionic push not working - user not registered

查看:150
本文介绍了离子推不工作 - 用户未注册的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚刚与我的离子框架的第一次接触。我之前使用Phonegap和AngularJS,所以这不是所有的新的我。
我发现有一个新的功能,通过Ionic推送功能( http://blog.ionic.io/announcing-ionic-push-alpha/ )。

I just had my first contacts with the ionic framework. I've worked with Phonegap and AngularJS before however, so it was not all that new to me. I found out that there is this new feature to use Google Cloud Messaging push notifications in Ionic, through the Ionic Push feature (http://blog.ionic.io/announcing-ionic-push-alpha/).

相关行 app.js

angular.module('starter', ['ionic','ionic.service.core', 'starter.controllers', 'starter.services'])

.run(function($ionicPlatform) {
  $ionicPlatform.ready(function() {
  // 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.styleLightContent();
    }

    // enable push notifications
    Ionic.io(); 

    // enable users (http://docs.ionic.io/docs/user-quick-start)
    // this will give you a fresh user or the previously saved 'current user'
    var user = Ionic.User.current();

    // if the user doesn't have an id, you'll need to give it one.
    if (!user.id) {
      user.id = Ionic.User.anonymousId();
      // user.id = 'your-custom-user-id';
    }
    console.log('user-id:' + user.id);

    //persist the user
    user.save();

    var push = new Ionic.Push({
      "debug": true,
      "onNotification": function(notification) {
        var payload = notification.payload;
        console.log(notification, payload);
      },
      "onRegister": function(data) {
        console.log(data.token);
      }
    });

    push.register(function(token) {
      console.log("Device token:",token.token);
    });
    push.addTokenToUser(user);
    console.log('token added to user');

  });
})

离线服务

ionic $ 0     361081   log      Ionic Core:, init
1     361083   log      Ionic Core:, searching for cordova.js
2     361085   log      Ionic Core:, attempting to mock plugins
3     361155   log      user-id:1cc3d21c-b687-4988-b944-ad07b1a677c8
4     361158   log      Ionic Push:, a token must be registered before you can add it to a user.
5     361159   log      Ionic Push:, token is not a valid Android or iOS registration id. Cannot save to user.
6     361159   log      token added to user
7     361160   log      Ionic Push:, register
8     361160   error    ReferenceError: PushNotification is not defined, http://localhost:8100/lib/ionic-platform-web-client/dist/ionic.io.bundle.min.js, Line: 2
9     361526   log      Ionic User:, saved user

欢迎任何输入,如果需要,我也非常乐意提供更多信息。

Any input is welcome, I am also more than happy to provide more information if needed.

EDIT 10/05 / 2015:

EDIT 10/05/2015:


  • 发现 dev_push = false 只能在物理设备上使用,

  • found out that dev_push = false only works on physical devices, not in browser
  • I tried to add token to user before even registering the user

推荐答案

您还需要在角模块中声明ionic.service.push作为依赖关系,如果您想使用它。

You also need to declare 'ionic.service.push' as a dependency in your angular module if you'd like to use it.

angular.module('starter',['ionic','ionic.service.core',' ionic.service.push '])

angular.module('starter', ['ionic','ionic.service.core', 'ionic.service.push'])

这篇关于离子推不工作 - 用户未注册的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆