Firebase使用Swift 3.0返回Optional()(Firebase returning Optional() with Swift 3.0)
自从更新到Swift 3.0以来,此代码现在在应用程序中显示数据为Optional('data')。 任何的想法?
let ring1FightRef = FIRDatabase.database().reference().child("Ring1Fighting") @IBOutlet weak var ring1Fighting: UILabel!
这是viewDidLoad中的代码
ring1FightRef.observe(.value) { (snap: FIRDataSnapshot) in self.ring1Fighting.text = (snap.value as AnyObject).description }
This code is now displaying data in the app as Optional('data') since updating to Swift 3.0. Any idea?
let ring1FightRef = FIRDatabase.database().reference().child("Ring1Fighting") @IBOutlet weak var ring1Fighting: UILabel!
Here is the code in viewDidLoad
ring1FightRef.observe(.value) { (snap: FIRDataSnapshot) in self.ring1Fighting.text = (snap.value as AnyObject).description }
原文:
最满意答案
在你的连接方法中,你可以离开
不要使用相同的端点“hello”和MessageMapping,会混淆
public void registerStompEndpoints(StompEndpointRegistry registry) { registry.addEndpoint("/ws") .setAllowedOrigins("*").withSockJS(); } var socket = new SockJS('/hello');
这里还删除了contextPath vix
stompClient.subscribe('/topic/greetings', function(greeting){ showGreeting(JSON.parse(greeting.body).content); });
这里再次相同
stompClient.send("/app/hello", {}, JSON.stringify({ 'name': name }));
基本上,所有问题都是添加上下文,因为在添加第一个“/”时默认添加上下文
In your connect method you can just leave
Don't use the same endpoint "hello" and MessageMapping, will be confuse
public void registerStompEndpoints(StompEndpointRegistry registry) { registry.addEndpoint("/ws") .setAllowedOrigins("*").withSockJS(); } var socket = new SockJS('/hello');
Here also remove the contextPath vix
stompClient.subscribe('/topic/greetings', function(greeting){ showGreeting(JSON.parse(greeting.body).content); });
Here again the same
stompClient.send("/app/hello", {}, JSON.stringify({ 'name': name }));
Basically, all problem was adding the context because the context was added by default when you add the first "/"
相关问答
更多-
AWS EB:WebSocket握手期间出错:意外响应代码:400(AWS EB: Error during WebSocket handshake: Unexpected response code: 400)[2023-04-08]
您的ELB是使用HTTP / HTTP侦听器还是TCP / SSL侦听器? Websockets仅适用于后一种协议类型。 将侦听器更改为TCP,它将起作用。 或者,如果使用CLI或API构建环境,则还可以使用应用程序负载均衡器(ALB)而不是经典负载均衡器(ELB)来重建ElasticBeanstalk应用程序,因为ALB也支持websockets。 无法通过Web控制台使用此选项。 Is your ELB using HTTP/HTTP listeners or TCP/SSL listeners? We ... -
Tomcat上的WebSocket握手返回意外的响应代码500(WebSocket Handshake on Tomcat returns Unexpected Response Code 500)[2022-07-30]
好的,经过很多调试后,我发现modifyHandshake()抛出了导致此问题的NPE。 我很惊讶,即使将日志级别设置为FINE,也没有记录任何内容。 OK, after much debugging I found that modifyHandshake() threw an NPE which caused this issue. I'm surprised that nothing about that was logged even with the log level set to FINE. -
我找到了问题并解决了它。 这是问题,在我的ProxyPass中,我正在将wss传递给wss。 对我而言,这应该是ws ws。 我的旧代码(错误的)是 ProxyPass "/wss/" "wss://localhost:9090/wss" 我的新代码(正确的)是 ProxyPass "/wss" "ws://localhost:9090" I found the issue and solved it. Here was the issue, in my ProxyPass I was passin ...
-
上面的配置用于Spring MVC的DispatcherServlet 。 您是否在Web应用程序中配置了一个? 根据servlet映射(上面未显示),您很可能需要在URL中添加一个部分以匹配servlet映射。 更长的解释是@EnableWebSocket创建了一个HandlerMapping,它将“/ echo”映射到WebSocketHandler。 HandlerMapping需要驻留在DispatcherServlet的配置中,以便处理HTTP握手。 The above configuration ...
-
根据https://tools.ietf.org/html/rfc6455#section-4.1 一旦发送了客户端的打开握手,客户端必须等待服务器的响应,然后再发送任何其他数据。 客户端必须按如下方式验证服务器的响应: 如果从服务器收到的状态代码不是101,则客户端根据HTTP [RFC2616]过程处理响应。 特别是,如果客户端收到401状态代码,则可能会执行身份验证; 服务器可能使用3xx状态代码重定向客户端(但客户端不需要遵循它们)等。否则,请按以下步骤操作。 第4.2.2节详细说明:除了响应代码1 ...
-
您的问题与安全性无关。 你只是在Stomp connect和subscribe函数中传递错误的参数。 如果您需要传递其他标头,connect()方法还会接受另外两个变体: client.connect(headers,connectCallback); client.connect(headers,connectCallback,errorCallback); 其中header是map,connectCallback和errorCallback是函数。 this.stompClient.connect(th ...
-
没有权限重定向到不同的端口。 您可以通过在注册stomp端点时将所有原点设置为允许来绕过此限制。 我想指出,这是一个非常糟糕的解决方案。 您应该利用代理,但我在这里缺乏信息来帮助您。 以下是您可能会发现有用的代码: public void registerStompEndpoints(StompEndpointRegistry registry) { registry.addEndpoint("/your_endpoint").setAllowedOrigins("*").withSockJS(); ...
-
在你的连接方法中,你可以离开 不要使用相同的端点“hello”和MessageMapping,会混淆 public void registerStompEndpoints(StompEndpointRegistry registry) { registry.addEndpoint("/ws") .setAllowedOrigins("*").withSockJS(); } var socket = new SockJS('/hello'); 这里还删除了contextPath v ...
-
p:套接字在WebSocket握手期间出错:意外的响应代码:200(p:socket Error during WebSocket handshake: Unexpected response code: 200)[2022-08-02]
我通过将我的Glassfish版本更新到4.1.1(版本1)解决了这个问题,原始版本已经很老了(2014)。 I resolved this by updating my version of Glassfish to 4.1.1 (build 1), the original build was quite old (2014). -
我得到了这个查询的答案。 这是因为添加的jar会覆盖apache tomcat中的内部jar。 我正在使用没有websocket-api.jar的旧tomcat 所以我对这个问题的解决方案是使用glashfish 4.x或者使用apache tomcat 8.x,它给我们提供了运行websocket所需的jar。 不需要添加任何额外的websocket api jar。 I got answer for this query. This is because the added jar overrides ...