3

编辑 3

我使用 RhoMobile 来获取 device_token,我正在访问服务器

def register_device
    @person = Person.find(:first)
    unless System.get_property('is_emulator')
     url = "#{@base}/users/#{@person.remote_id}/register_device?os=#{System.get_property('platform')}&device_token=#{System.get_property('device_id')}"
     Rho::AsyncHttp.get(
        :url => url,
        :headers => {'User-Agent' => Rho::RhoConfig.user_agent}
      )
    end
    finish_and_go_to_venue
  end

编辑 2

拥有 device_token 但不断获得Error=NotRegistered

编辑

好的,所以第一个错误是使用了错误的设备 ID。现在工作,但电话没有提醒消息。

原来的

第一次从 Rails 服务器发送 android Push 消息的用户。

使用https://github.com/sghael/speedy_c2dm

我在谷歌注册并收到了白名单电子邮件。

在下面尝试 test.rb,但没有任何内容发送到手机。

require 'rubygems'
require 'bundler'
Bundler.setup(:default, :development)
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
$LOAD_PATH.unshift(File.dirname(__FILE__))
require 'speedy_c2dm'


TEST_EMAIL = "my_push_email@gmail.com"
TEST_PASSWORD = "MY_PASSWORD"
TEST_REGISTRATION_ID = "DEVICE_TOKEN_RECEIVED_FROM_PHONE"

speedyC2DM = SpeedyC2DM::API.new(TEST_EMAIL, TEST_PASSWORD)

options = {
  :registration_id => TEST_REGISTRATION_ID,
  :message => "Hi!",
  :extra_data => 42,
  :collapse_key => "some-collapse-key"
}


response = speedyC2DM.send_notification(options) 
4

1 回答 1

1

尝试添加一个名为 Push 的控制器,并且在控制器内您需要具有以下内容:

require 'rho/rhocontroller'
require 'helpers/browser_helper'

class PushController < Rho::RhoController
  include BrowserHelper

  def push_callback

    Alert.show_popup @params['message'] #this will show you a popup with your push message
    puts "push_callback : #{@params}" #you'll see what you are receiving with this
    "rho_push"  #to run rhodes push command processing (for alerts, sounds, etc…)
  end


end

您需要通过将以下行添加到您的 application.rb 来设置您的应用程序来调用

System.set_push_notification "/app/Push/push_callback", ''

另外,您是否正确配置了 build.yml?

android:
  push:
    notification: always
    sender: your-sender-email@gmail.com
capabilities:
  - push
  - vibrate

至少对于我的应用程序,我需要运行应用程序才能获取消息。

于 2011-11-23T00:43:39.863 回答