无法在Pusher的ios应用程序上接收推送通知

时间:2019-05-08 17:18:23

标签: python swift real-time pusher pusherswift

在我的自定义ubuntu服务器上,我有一个python应用程序,该应用程序在无限循环中运行,每2秒触发一次push事件,该事件将消息发送到pusher网站,并且我成功接收到通知。

在我的服务器上,我触发了此消息:

pusher_client.trigger('my-channel', 'my-event', {'message': "test"})

现在使用swift进入我的ios应用程序,我想从服务器接收消息,并且我有以下代码由推送网站提供给我

override func viewDidLoad() {
    super.viewDidLoad()
    getUpdates()

}

func getUpdates(){

    let options = PusherClientOptions(
        host: .cluster("myCluster")
    )

    let pusher = Pusher(
        key: "MY_KEY",
        options: options
    )

    // subscribe to channel and bind to event
    let channel = pusher.subscribe("my-channel")

    let _ = channel.bind(eventName: "my-event", callback: { (data: Any?) -> Void in
        if let data = data as? [String : AnyObject] {
            if let message = data["message"] as? String {
                print(message)
            }
        }
    })
    pusher.connect()
}

即使在网站上检测到推送事件,我也无法触发“打印(消息)”,我的代码是否有问题,或者我缺少什么?非常感谢使打印消息正常工作的任何帮助

0 个答案:

没有答案