我正在制作一个私人聊天应用程序,在其中我遇到了一些问题,比如-
1.有时我会多次收到最后一次聊天。2.有时长数据就像一个大图像,不合适。
通过这段代码,我每隔5秒调用一次web服务-
NSInvocation *invocation = [NSInvocation invocationWithMethodSignature:
[self methodSignatureForSelector: @selector(getNewMessages)]];
[invocation setTarget:self];
[invocation setSelector:@selector(getNewMessages)];
timer1 = [NSTimer scheduledTimerWithTimeInterval:5.0 invocation:invocation repeats:YES];所以我想问一下,在接收到完整的数据后,调用web服务的正确方式是什么。我正在使用NSXMLParser来获取数据。
发布于 2012-12-13 13:54:21
有两种方法可以解决这个问题-
1)当您收到第一个请求的完整数据时,您可以调用另一个请求,方法如下
-(void) connection:(NSURLConnection *) connection didReceiveData:(NSData *) data 2)当您完成解析后,您可以触发另一个请求-
-(void)parser:(NSXMLParser *)parser didEndElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName发布于 2012-12-13 13:50:43
请看here,它给了你一个在objective-c中选择最好的xml解析器的想法。
尝试使用TBXML解析器,因为它解析xml比NSXML解析器快得多,这可能会解决您的问题。
https://stackoverflow.com/questions/13853421
复制相似问题