码迷,mamicode.com
首页 > 其他好文 > 详细

用 Houston 在本地调试远程通知

时间:2015-05-03 07:08:09      阅读:104      评论:0      收藏:0      [点我收藏+]

标签:houston   远程通知   

Houston 的背景

Houston 在 GitHub 上的地址:https://github.com/nomad/Houston,作者又是Mattt Thompson,简直是惨无人道啊,又高产,又有质量技术分享

Houston 能让我们在本地、甚至终端很方便的调试远程通知。


安装

首先在终端安装:

$ gem install houston

我第一次安装的时候报了错,但是第二次就安装成功了:

...
Installing ri documentation for houston-2.2.3
1 gem installed

安装成功后执行gem list命令可以看到 houston 和它的版本号:
技术分享

然后也能执行apn命令了:

$ apn
error: undefined method `size‘ for nil:NilClass. Use --trace to view backtrace

准备证书

在正式的使用之前需要先准备好pem证书文件:

  1. Keychain Access里选择你的Push Services证书和通过它左侧的小箭头展开的私钥文件
  2. 选择这两个文件后,右键选择Export 2 items...
  3. 选择p12格式并将导出的文件命名为cert.p12
  4. 最后将这个p12文件转成pem文件
$ openssl pkcs12 -in cert.p12 -out apple_push_notification.pem -nodes -clcerts

如果你的 Keychain Access 里没有 Push Services 证书的话,你可能需要下载或创建一个:
1. 登录到 iPhone Developer Connection Portal(http://developer.apple.com/iphone/manage/overview/index.action )并点击 App IDs
2. 创建一个不使用通配符的 App ID ,这是因为通配符 ID 不能用于推送通知服务
3. 点击 App ID 旁的“Configure”,然后按下按钮生产 推送通知许可证。根据“向导” 的步骤生成一个签名并上传,最后下载生成的许可证
4. 通过双击 .cer 文件将你的 aps_developer_identity.cer 添加到 Keychain Access中
5. 添加后Push Services证书后就开始pem文件,步骤同上

然后就能在终端测试远程通知了。


发送远程通知

需要在apn命令里指定DeviceTokenpem证书路径。

普通文本

比如测试一下普通的文本通知:

$ apn push "<d10c67b0 079cfdc0 27b5dd81 2fd537ce 16831f40 ca55fa34 8b14ffde 626435f6>" -c ~/Desktop/apple_push_notification.pem -m "Hello"

成功后的终端提示:

1 push notification sent successfully

自定义参数

带参数的远程通知:

$ apn push "<d10c67b0 079cfdc0 27b5dd81 2fd537ce 16831f40 ca55fa34 8b14ffde 626435f6>" -c ~/Desktop/apple_push_notification.pem  -m "Hello" -d content-id=42

自定义多个参数

多个参数之间用逗号分隔:

$ apn push "<d10c67b0 079cfdc0 27b5dd81 2fd537ce 16831f40 ca55fa34 8b14ffde 626435f6>" -c ~/Desktop/apple_push_notification.pem  -m "Hello" -d content-id=42,icon=image.png

静默通知

$ apn push "<d10c67b0 079cfdc0 27b5dd81 2fd537ce 16831f40 ca55fa34 8b14ffde 626435f6>" -c ~/Desktop/apple_push_notification.pem  -s "" -n

静默通知要把 sound 设为空字符串,并且要启用content_available

终端可用选项

  • ‘-m’, ‘–alert ALERT’, ‘Body of the alert to send in the push notification’
  • ‘-b’, ‘–badge NUMBER’, ‘Badge number to set with the push notification’
  • ‘-s’, ‘–sound SOUND’, ‘Sound to play with the notification’
  • ‘-y’, ‘–category CATEGORY’, ‘Category of notification’
  • ‘-n’, ‘–[no]-newsstand’, ‘Indicates content available for Newsstand’
  • ‘-d’, ‘–data KEY=VALUE’, Array, ‘Passes custom data to payload (as comma-delimited “key=value” declarations)’
  • ‘-P’, ‘–payload PAYLOAD’, ‘JSON payload for notifications’
  • ‘-e’, ‘–environment ENV’, [:production, :development], ‘Environment to send push notification (production or development (default))’
  • ‘-c’, ‘–certificate CERTIFICATE’, ‘Path to certificate (.pem) file’
  • ‘-p’, ‘–[no]-passphrase’, ‘Prompt for a certificate passphrase’

用 Houston 在本地调试远程通知

标签:houston   远程通知   

原文地址:http://blog.csdn.net/zhangao0086/article/details/45448785

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!