码迷,mamicode.com
首页 > 移动开发 > 详细

Clojure:两步发送iOS推送通知(apns)

时间:2014-08-14 10:24:38      阅读:224      评论:0      收藏:0      [点我收藏+]

标签:des   style   blog   color   使用   os   io   div   

首先在project.clj中,添加对notnoop 类库的引用:[com.notnoop.apns/apns "0.2.3"]

然后使用如下方法就可以发送推送消息了:

 1 (ns demo.apns
 2   (:import (com.notnoop.apns APNS)))
 3 
 4 (defn send-push-notification
 5   [device-tokens message]
 6   (loop [rest-device-tokens device-tokens
 7          sent-count 0]
 8     (if (empty? rest-device-tokens)
 9       sent-count
10       (do
11         (let [service (.build (.withSandboxDestination
12                                 (.withCert (APNS/newService)
13                                            "resources/demo.p12"
14                                            "password")))
15               payload (.build (.alertBody (APNS/newPayload) message))]
16           (.push service (first rest-device-tokens) payload))
17         (recur (rest rest-device-tokens) (inc sent-count))))))

调用方法如下:

(send-push-notification [“token1” “token2” …] “test message”)

 

需要注意证书必须为p12格式(可以通过KeyChain Access软件转换)

 

Clojure:两步发送iOS推送通知(apns),布布扣,bubuko.com

Clojure:两步发送iOS推送通知(apns)

标签:des   style   blog   color   使用   os   io   div   

原文地址:http://www.cnblogs.com/ilovewindy/p/3910815.html

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