How do I use the Streaming API in TwitterKit on iOS?

ios
streaming

#1

After logging in with loginWithCompletion:, I can use the following code to retrieve some data from the Twitter REST API, for example the direct messages call:

var clientError : NSError?

let request = Twitter.sharedInstance().APIClient.URLRequestWithMethod(
    "GET",
    URL: "https://api.twitter.com/1.1/direct_messages.json",
    parameters: Dictionary(),
    error: &clientError)

Twitter.sharedInstance().APIClient.sendTwitterRequest(request) {
    (response, data, connectionError) -> Void in
    println("response: \(response)")
}

This returns a response with a status code of 200. It works fine.

I want to access the Twitter streaming API for User Streams, but it seems that using this same method wouldn’t work. Changing the URL in the call means I get no response:

var clientError : NSError?

let request = Twitter.sharedInstance().APIClient.URLRequestWithMethod(
    "GET",
    URL: "https://userstream.twitter.com/1.1/user.json",
    parameters: Dictionary(),
    error: &clientError)

Twitter.sharedInstance().APIClient.sendTwitterRequest(request) {
    (response, data, connectionError) -> Void in
    println("response: \(response)")
}

Response comes back as nil. Listening for the error shows that I only got a response as a timeout on the call.

If this isn’t the way to do it, then how can I access the Streaming API from iOS, in particular when using TwitterKit for authentication.


#2