2011-11-08 8 views
7

के साथ समस्या मैं एक समस्या पर काम कर रहा हूं जहां मुझे कतार में लगभग 10 अलग-अलग बड़ी फ़ाइलें डाउनलोड करनी होंगी, और मुझे कुल स्थानांतरण की स्थिति का संकेत देने वाली प्रगति पट्टी प्रदर्शित करने की आवश्यकता है। मैं इस iOS4 में ASIHTTPRequest साथ बस ठीक काम कर रहा है, लेकिन मैं AFNetworking में संक्रमण के लिए के बाद से ASIHTTPRequest iOS5 में मुद्दे हैं और अब बनाए रखा है कोशिश कर रहा हूँ।ASIHTTPRequest से AFNetworking पर स्विच करना - ASINetworkQueue

मुझे पता है कि आप AFHTTPRequestOperation के डाउनलोड प्रोग्रेसब्लॉक का उपयोग करके व्यक्तिगत अनुरोधों पर प्रगति की रिपोर्ट कर सकते हैं, लेकिन मुझे एक ही NSOperationQueue पर निष्पादित कई अनुरोधों की समग्र प्रगति की रिपोर्ट करने का कोई तरीका नहीं दिख रहा है।

कोई सुझाव? धन्यवाद!

उत्तर

0

मैं एक उपवर्ग है कि सभी अलग आइटम आप देख रहे हैं का ट्रैक रखता है साथ UIProgressView उपवर्गीकरण की कोशिश करेंगे और फिर तर्क यह है कि उन सब की प्रगति एक साथ जोड़ता है है।

यह शायद की तरह कोड के साथ

:

@implementation customUIProgressView 

-(void) updateItem:(int) itemNum ToPercent:(NSNumber *) percentDoneOnItem { 
    [self.progressQueue itemAtIndexPath:itemNum] = percentDoneOnItem; 

    [self updateProgress]; 
} 
-(void) updateProgress { 
    float tempProgress = 0; 
    for (int i=1; i <= [self.progressQueue count]; i++) { 
    tempProgress += [[self.progressQueue itemAtIndexPath:itemNum] floatValue]; 
    } 
    self.progress = tempProgress/[self.progressQueue count]; 
} 
+0

है यह MVC के लिए अभ्यास कोडिंग बुरा है डिजाइन पैटर्न्स। –

+0

शायद। यह गतिशील रूप से आकार सामग्री के लिए नौकरी के लिए सही उपकरण है। यह सही ढंग से पहले सामग्री के आकार का पता करने के लिए की जरूरत के बिना प्रगति दिखाई देगा। (जैसे वीडियो या फ़ोटो) बड़ी फ़ाइलों के आकार ढूंढना महंगी आपरेशन हो सकता है। – clreina

0

आप उपवर्ग कर सकते हैं AFURLConnectionOperation 2 नए गुण हैं: (NSInteger)totalBytesSent, और (NSInteger)totalBytesExpectedToSend। तुम इतनी तरह NSURLConnection कॉलबैक में इन गुणों को सेट करना चाहिए:

- (void)connection:(NSURLConnection *)__unused connection 
    didSendBodyData:(NSInteger)bytesWritten 
totalBytesWritten:(NSInteger)totalBytesWritten 
totalBytesExpectedToWrite:(NSInteger)totalBytesExpectedToWrite 
{ 
    [super connection: connection didSendBodyData:bytesWritten totalBytesWritten:totalBytesWritten totalBytesExpectedToWrite:totalBytesExpectedToWrite]; 
    self.totalBytesSent = totalBytesWritten; 
    self.totalBytesExpectedToSend = totalBytesExpectedToSend; 
} 

आपका uploadProgress ब्लॉक कुछ ऐसा दिखाई देगा:

……(NSInteger bytesWritten, NSInteger totalBytesWritten, NSInteger totalBytesExpectedToWrite) { 
    NSInteger queueTotalExpected = 0; 
    NSInteger queueTotalSent  = 0; 
    for (AFURLConnectionOperation *operation in self.operationQueue) { 
     queueTotalExpected += operation.totalBytesExpectedToSend; 
     queueTotalSent  += operation.totalBytesSent; 
    } 
    self.totalProgress = (double)queueTotalSent/(double)queueTotalExpected; 
}]; 
1
[operation setUploadProgressBlock:^(NSInteger bytesWritten, NSInteger totalBytesWritten, NSInteger totalBytesExpectedToWrite) { 
    NSLog(@"Sent %d of %d bytes", totalBytesWritten, totalBytesExpectedToWrite); 
}]; 

ऑपरेशन AFHTTPRequestOperation

संबंधित मुद्दे