How can I stop a stream when using STTWitter

白昼怎懂夜的黑 提交于 2019-12-24 14:26:39

问题


On iOS (but I think this would be just the same on OSX) I'm using STTWitter.

Among other things, I want to use it to stream the main public timeline.

I've successfully used getStatusesSampleDelimited:stallWarnings:progressBlock:stallWarningBlock:errorBlock: to start streaming tweets.

How can I stop the stream once I've got enough, or want to switch to a different stream (e.g. streaming a search)?

I've tried destroying the STTWitterAPI object - with no effect. I can't see a method on the object to stop streaming, and I've traced the source code through and don't see any way I can stop a stream once it's started.

What have I missed?


回答1:


The library didn't support cancelling request, so I just added this feature:

id request = [twitter getStatusesSampleDelimited:nil
                                   stallWarnings:nil
                                   progressBlock:^(id response) {
    // ...
} stallWarningBlock:nil
         errorBlock:^(NSError *error) {
    // ...
}];

// ...

[request cancel]; // when you're done with it

After request cancellation, the error block is called once with a cancellation error.

Let me know if it doesn't fulfil your needs.



来源:https://stackoverflow.com/questions/19859569/how-can-i-stop-a-stream-when-using-sttwitter

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!