我正在使用推送客户端的iOS,通过CocoaPods(pod 'libPusher', '~> 1.5'
)安装它。iOS推送客户端不会自动重新连接
这一切设置良好,事件通过罚款。但是,如果设备(iPhone 6s运行iOS 9.0.2)失去互联网连接(由我进入飞行模式),然后在一分钟后重新获得它(我从飞机模式中出来),Pusher从未重新获得连接。
我已经添加了一些UIAlertViews来根据它的委托方法来测试它在做什么。
最初显示了connectionWillConnect
和connectionDidConnect
。
当飞机模式打开时connectionWillConnect
则显示connectionWillAutomaticallyReconnection afterDelay of 0.0
。
(然后离开一分钟左右没有互联网。)
然后什么都没有,甚至连接至互联网后。事件不再被正确接收。
-
下面是我用的所有东西推(写在雨燕2.0),直到连接丢失,效果很好的类。
class PusherInterface: NSObject, PTPusherDelegate {
// MARK: - PusherInterface Shared Instance
/// Singleton instance of the PusherInterface class.
private static let sharedInstance = PusherInterface()
// MARK: - Pusher Credentials
private static let pusherAppId = "MY_APP_ID"
private static let pusherKey = "MY_KEY"
private static let pusherSecret = "MY_SECRET"
/// The connected client used by Pusher to connect to event channels
private static var client: PTPusher = {
let pusherClient = PTPusher.pusherWithKey(pusherKey, delegate: PusherInterface.sharedInstance)
pusherClient.connect()
return pusherClient as! PTPusher
}()
// MARK: - Setup Pusher
static func startListening() {
client.subscribeToChannelNamed("MY_CHANNEL")
client.bindToEventNamed("MY_EVENT") { pusherEvent in
// Does some stuff with the data back
}
}
// MARK: - Pusher Delegate
func pusher(pusher: PTPusher!, connectionDidConnect connection: PTPusherConnection!) {
NSOperationQueue.mainQueue().addOperationWithBlock {
UIAlertView(title: "connectionDidConnect", message: "", delegate: nil, cancelButtonTitle: "Dismiss").show()
}
}
func pusher(pusher: PTPusher!, connectionWillAutomaticallyReconnect connection: PTPusherConnection!, afterDelay delay: NSTimeInterval) -> Bool {
NSOperationQueue.mainQueue().addOperationWithBlock {
UIAlertView(title: "connectionWillAutomaticallyReconnect", message: "afterDelay \(delay)", delegate: nil, cancelButtonTitle: "Dismiss").show()
}
return true
}
func pusher(pusher: PTPusher!, connectionWillConnect connection: PTPusherConnection!) -> Bool {
NSOperationQueue.mainQueue().addOperationWithBlock {
UIAlertView(title: "connectionWillConnect", message: "", delegate: nil, cancelButtonTitle: "Dismiss").show()
}
return true
}
}
任何想法,为什么它不工作?
所有想法&理论将非常感激!谢谢:)
它不为我们工作,我们连推而里面的应用程序,我们住在应用程序,并从互联网上断开,所以推也已断开,然后我们连接互联网上,但仍推disconeccted – FosAvance