- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在使用适用于 iOS 的 Pusher 客户端,通过 CocoaPods 安装它(pod 'libPusher', '~> 1.5'
)。
一切都安排得很好,事件进展顺利。但是,如果设备(运行 iOS 9.0.2 的 iPhone 6s)失去互联网连接(由于我进入飞行模式而导致),然后在一分钟后重新获得互联网连接(我从飞行模式中退出),Pusher 就永远不会重新获得连接。
我添加了一些 UIAlertViews 来测试它基于它的委托(delegate)方法正在做什么。
最初显示 connectionWillConnect
和 connectionDidConnect
。
打开飞行模式时connectionWillConnect
,然后显示connectionWillAutomaticallyReconnection afterDelay of 0.0
。
(然后在没有互联网的情况下离开一分钟左右。)
然后什么也没有,即使在重新连接到互联网之后也是如此。并且事件不再被正确接收。
-
这是我用于所有 Pusher 事物的类(用 Swift 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
}
}
关于为什么它不起作用有什么想法吗?
所有想法和理论将不胜感激!谢谢:)
最佳答案
对于我来说,Swift 也不起作用。我安装了swift implementation Pusher 现在工作正常。
let pusher = Pusher(key: "c984997151153c177dc2")
pusher.connect()
let channel = pusher.subscribe("test_channel")
channel.bind("my_event") { (event: AnyObject?) -> Void in
print("my_event push received ")
}
关于iOS Pusher 客户端不会自动重新连接,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33000301/
我不确定我是否正确理解 authentication在 Pusher 工作。这是我担心的一个场景: 用户想要订阅私有(private) channel ,因此 Pusher 库调用我的服务器以获得身份
典型的聊天应用。使用存在 channel 来判断谁在线,但正在寻找一种优雅的方式来使用空闲标志在存在 channel 中标记用户。 最佳答案 对此的完整解决方案可能相当复杂,而且还取决于运行时 - 我
Pusher 似乎是一项不错的服务,但我想知道是否有人知道它是否可以用作持久事件流。例如,我想订阅一个 channel 并获取历史事件,而不仅仅是订阅后的新实时事件事件。 最佳答案 channel 事
我找不到任何关于使用 Pusher 创建 channel 的明确信息。在客户端订阅或在服务器上推送事件时,这只是一个隐式操作吗? class HelloController 'world' })
我有 40 个类别,每个类别都有 10-100 个子类别。默认情况下,用户收听所有类别和子类别。我想让每个用户能够选择从整个类别或特定子类别中取消绑定(bind)。所以,现在我所拥有的是每个类别都是一
是否可以从 API 获取与推送器 (http://pusher.com/) 的事件连接数? 在他们支持的 Python 服务器库中找不到它。虽然我可以在他们基于 Web 的仪表板的统计页面上看到它,但
我想要什么:在 Pusher 中订阅私有(private) channel 后如何获得订阅计数。实际上我只想在 2 个用户之间进行私有(private)聊天。 我所知道的和正在做的事情: .我知道我的
我最近在我的 PHP laravel 项目中使用了 pusher,它运行良好。 我对 pusher 的了解是,它是我们的服务器和客户端之间的实时层,并创建到我们的客户端浏览器的 Web 套接字连接。
我不确定我是否正确理解authentication在Pusher中的工作方式。这是我担心的情况: 用户想要订阅专用频道,因此Pusher库调用我的服务器以获得身份验证令牌。 服务器检查用户是否已登录并
我正在编写多人国际象棋游戏,并在 websocket 服务器部分使用 Pusher。 无论如何,如果我有一个用户列表,并且我选择其中的任何一个并挑战他们,我如何仅向该用户发送挑战?我知道我会使用客户端
我正在使用 Backbone 前端,我们目前正在使用推送器使其实时化。大多数事件都是从我们的 API 触发的,然后我们在主干前端的 channel 上监听它们。 但是,在某些情况下,我们希望通过单击按
我在我的 php 文件中集成了一些脚本。它正在读取 Pusher channel ,并在列出的 channel 上有新事件时执行多项操作。 如果我在浏览器上运行: http:/localhost/pu
我正在使用 nextjs 在 Web 应用程序中实现推送器。它在我的开发环境中按预期工作。但当我将其部署到 vercel 时,它无法正常工作。我只有在浏览器中刷新页面时才能看到结果。 这是客户端的实现
我正在使用 PHP 和 Javscript (jQuery) 测试 Pusher 库,以通过一个相当简单的应用程序来处理 Websocket,您可以在这里找到它:http://jsfiddle.net
我正在开发的实时应用程序遇到问题。我的问题是关于使用 Pusher 的用户状态。例如,我想获得正确的方法来检测用户何时离开页面或保持一段时间不活动以将其状态设置为“离线”。我怎样才能做到这一点?我几乎
我正在尝试实现一项功能,通知用户推送器断开连接,并指示何时重新连接。我的第一个实验只是将更改的推送器状态记录到控制台: var pusher = new Pusher('MY_ACCOUNT_STRI
我正在开发的实时应用程序遇到问题。我的问题是关于使用 Pusher 的用户状态。例如,我想获得正确的方法来检测用户何时离开页面或保持一段时间不活动以将其状态设置为“离线”。我怎样才能做到这一点?我几乎
我正在使用适用于 iOS 的 Pusher 客户端,通过 CocoaPods 安装它(pod 'libPusher', '~> 1.5')。 一切都安排得很好,事件进展顺利。但是,如果设备(运行 iO
我正在使用 Pusher 将事件推送到我订阅的浏览器。 当我向我的服务器发送更新时,我的服务器发出一个 Push 事件,我的客户端(发起请求)和任何其他订阅的客户端都会被触发。 我遇到的问题是事件发起
我正在使用 Pusher 提供的起始代码,当我将其放入基本的 swift 项目并向其发送消息时,没有任何反应。我也安装了 cocoa pod 包。 应打印语句“已收到数据”。 也没有错误。 最佳答案
我是一名优秀的程序员,十分优秀!