It looks like you are implicitly assuming that the OS will send you
chunks of stream data that correspond to single, complete parsable
chunks. That may have worked accidentally because that happened to be
how they arrived in time, but it is definitely unreliable (as you
found). What you should do in connection:didReceiveData: is buffer the
data you received, and split it up yourself by looking for the
delimiters that separate individual tweets, and then parse those
individual tweets.

-josh


On Sun, Apr 18, 2010 at 5:29 AM, Carl Knott <carl.kn...@gmail.com> wrote:
> I have developed an iPhone app that connects to the streaming API.... the
> app was running correctly for 2 months but since yesterday it has not! I can
> still receive a response from the stream but now I can not parse the JSON
> correctly... My parser believes that the stream is incorrectly structured. I
> get a few correctly structured results and then I get errors. Is it a
> problem at twitters end or mine? Below is a snippet of my code.
> To initialize the HTTP request:
> request = [NSURLRequest requestWithURL:[NSURL URLWithString:[NSString
> stringWithFormat:
> @"http://%@:%@@stream.twitter.com/1/statuses/filter.json?track=%@";,
> [[NSUserDefaults standardUserDefaults] stringForKey:@"UsernameKey"],
> [[NSUserDefaults standardUserDefaults] stringForKey:@"PasswordKey"],
> searchFormat]] ];
>
> - (void)connection:(NSURLConnection *)connection didReceiveData:(NSData
> *)data {
> NSString *responseString = [[[NSString alloc]  initWithData:data
> encoding:NSUTF8StringEncoding] autorelease];
> NSDictionary *dictionary = (NSDictionary *) [parser
> objectWithString:responseString error:nil];
> NSDictionary *user = (NSDictionary *) [dictionary valueForKey:@"user"];
> if([user valueForKey:@"screen_name"] != nil) {
> Tweet *tweet = [[Tweet alloc] init];
> [tweet setScreenName:[user valueForKey:@"screen_name"]];
> [tweet setLink:[user valueForKey:@"profile_image_url"]];
> [tweet setMessage:[dictionary valueForKey:@"text"]];
>                 //do something
> [tweet release];
> }
> }
>


-- 
Subscription settings: 
http://groups.google.com/group/twitter-development-talk/subscribe?hl=en

Reply via email to