2013-02-01 65 views
-1

我正在使用NSoperation啓動請求到服務器.Pullparser將被調用,它將啓動A/p & I/P流。在connecitonDidRecievedata我寫數據從服務器到OStream.Imeediately我必須調用自定義方法,而不是讓解析器開始解析。如何處理這種情況。如何處理對解析器的ostream調用並首先處理我的自定義方法,然後在我的自定義方法中,我必須調用解析器。如何使用NSOperation和調度隊列

- (void)run 
{  
    [gObjAppDelegatePtr displayActivityIndicator]; 
    self.m_cObjDownloadOprPtr = [[[NSInvocationOperation alloc]initWithTarget:self selector:@selector(requestToServer) object:nil]autorelease]; 

    if((NSOperationQueue *)nil == m_cObjDownloadOprQueuePtr) 
    { 
     m_cObjDownloadOprQueuePtr = [[NSOperationQueue alloc]init]; 
     [m_cObjDownloadOprQueuePtr setMaxConcurrentOperationCount:1]; 
    } 
    [m_cObjDownloadOprQueuePtr addOperation:self.m_cObjDownloadOprPtr]; 
} 

- (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data 
{ 
    //[self.m_cWebData setLength: 0]; 
    [self.m_cWebData appendData:data];  
    [self.m_cObjOriginalWebDataPtr appendData:data]; 
    [self attemptToWriteToStream]; 
} 

- (void)attemptToWriteToStream 
{ 
    if([self.m_cWebData length] > 0) 
    { 
     [self saveDownloadedData]; 
     NSUInteger written = [oStream write:(const uint8_t *)[m_cWebData bytes] maxLength:[m_cWebData length]]; 
     // NSLog(@"Rcvd Data=%d written = %d",[m_cWebData length],written); 
     [m_cWebData replaceBytesInRange:NSMakeRange(0,written) withBytes:"" length:0]; 
     // NSLog(@"Rcvd Data after Reset =%d ",[m_cWebData length]);[self parseResponse]; 
    } 
} 

self.m_cObjSAXHandler = [self createParser:(id)self]; 
self.m_cCurrentDownloadInfo = pObjEntry;self.m_cObjConfig = (MobileCRMConfiguration*)super.m_cObjParent.m_cObjConfiguration; 
m_cIsSuccess = NO; 

self.m_cIsOrganizationMatches = NO; 
[self.m_cObjXmlParser ParseWithStream:iStream]; 

-(void)ParseWithStream:(NSInputStream *)pInputStream 
{ 
    self.m_cObjXMLParser = [[NSXMLParser alloc] initWithStream:pInputStream]; 
    self.m_cObjXMLParser setDelegate:m_cObjSAXHandler]; 
    dispatch_block_t dispatch_block = ^(void){ 
     [self.m_cObjXMLParser parse]; 
    }; 

    dispatch_queue_t dispatch_queue = dispatch_queue_create("parser.queue", NULL); 
    dispatch_async(dispatch_queue, dispatch_block); 
    dispatch_release(dispatch_queue); 
} 
+0

在此處添加您的代碼。 –

+0

對不起,我已經添加了代碼,但是我的編輯沒有通過堆棧溢出來處理。 – user2031994

+0

您需要正確設置問題的格式,否則幾乎沒有人會考慮回答問題。 –

回答

0

我已經這樣做了pullparser的事兒。必須處理解析器代表和流時,它完成解析數據應該更新和寫入剩餘的數據流。