新手问题 调试 iOS 的推送脚本

i5ting · 2013年01月15日 · 最后由 i5ting 回复于 2013年03月08日 · 4586 次阅读

初衷

调试 ios 的推送,想发的时候在命令里输入内容,然后回车。“啪”的一下就过去了

准备

  • gem install apns
  • ruby do.rb

下面是 do.rb 代码

#!/usr/bin/env ruby  
# encoding: utf-8

require 'APNS'

#APNS.host = 'gateway.push.apple.com' 
APNS.host = 'gateway.sandbox.push.apple.com' 
#gateway.sandbox.push.apple.com is default

APNS.pem  = '/Users/me/push/rapns/my_push.pem'
# this is the file you just created

APNS.port = 2195 
# this is also the default. Shouldn't ever have to set this, but just in case Apple goes crazy, you can.

device_token = '1c47f5a74714b28a00014684a64f02c7f60426e6c9a6ee6b068efddb57c9d6a9'

print "please enter the news content:"  

while gets.chomp
  puts "The news is :#{$_}         \n-----------------------\n" 
  APNS.send_notification(device_token, :alert => "#{$_}", :badge => 1, :sound => 'default', :other => {:hash => 'zlrltPL'})
end

说明

  • 这是测试环境的脚本,所以 host 是 gateway.sandbox.push.apple.com
  • pem 文件是要根据证书生成的

关键是编译这个 pem 还有 获取 device_token

@i5ting device_token = '1c47f5a74714b28a00014684a64f02c7f60426e6c9a6ee6b068efddb57c9d6a9' 你这个 device_token 不是真实的吧,真实的 token 里面会有几个空格的

#2 楼 @liuhui998 处理过了,哈哈

我想问一下,如果 pem 和 device_token 设置对了的话,就应该能成功么?返回时是不是 nil?

#4 楼 @siriuszhuang 请求发出去之后,你就不用管了,需要在 iOS 的 appdelegate 里增加断点

需要 登录 后方可回复, 如果你还没有账号请 注册新账号