How can I get an event from Pusher using Starscream on Swift?

I am trying to use Pusher for my iOS app. I have installed Starscream.framework in my application as client side. I was able to connect to a specific Pusher application. And also I was able to disable it by clicking a button in my application. I can see these activities and logs from the Debug Pusher console.

But if I create a new event from the Debug Console, my iOS app won't receive it. The "websocketDidReceiveMessage" function will not work. Debug Console Image

I think I was wrong. Please tell me if there is any error.

Sincerely.

Here is my code.

import UIKit
import Parse
import Starscream

class ViewController: UIViewController, WebSocketDelegate {


var socket = WebSocket(url: NSURL(scheme: "ws", host: "ws.pusherapp.com/app/API_KEY?protocol=7", path: "/")!)


override func viewDidLoad() {
    super.viewDidLoad()

    self.socket.delegate = self
    self.socket.connect()

}

override func didReceiveMemoryWarning() {
    super.didReceiveMemoryWarning()
    // Dispose of any resources that can be recreated.
}



@IBAction func disconnectWasTapped(sender: UIButton) {
    self.socket.disconnect()
}


// MARK: WebSocket
func websocketDidConnect(socket: WebSocket) {
    println("websocket is connected")
}

func websocketDidDisconnect(socket: WebSocket, error: NSError?) {
    println("websocket is disconnected: \(error?.localizedDescription)")
}

func websocketDidReceiveMessage(socket: WebSocket, text: String) {
    //println("got some text!!")
    println("got some text: \(text)")
}

func websocketDidReceiveData(socket: WebSocket, data: NSData) {
    println("got some data: \(data.length)")
}


}

      

UPDATE I was able to fix my problem myself. I decided not to use Pusher. I decided to use PubNub instead of Pusher. He is currently working on Swift. And it's very easy to integrate with Parse to implement real-time interaction.

+3


source to share





All Articles