2015-07-03 6 views
13

हम आपको पृष्ठभूमि FETCHआईओएस पृष्ठभूमि स्थानांतरण - com.apple.nsurlsessiond फ़ोल्डर tmp फ़ाइलें से भरा

का उपयोग कर json सूची के रूप में नवीनतम वीडियो की एक सूची प्राप्त करने के लिए अनुमति देता है एक मीडिया आवेदन में लिखा है तो यह करने के लिए पृष्ठभूमि स्थानांतरण का उपयोग करता है वीडियो को एक-एक करके डाउनलोड करने के लिए आईओएस बताएं और सोने के लिए वापस जाएं और ऐप को पूरा करने के लिए जागृत करें।

यह सब कुछ करता है लेकिन हमने देखा है कि अंतरिक्ष उपयोग बढ़ रहा है और बढ़ रहा है।

हमने सभी डाउनलोड किए गए वीडियो को साफ़ करने के लिए कोड जोड़ा लेकिन अंतरिक्ष उपयोग सेटिंग में हाय रहा।

हमने एक्सकोड> ऑर्गनाइज़र> डिवाइस का उपयोग करके ऐप फ़ोल्डरों को डाउनलोड किया और पाया कि बैकग्राउंड ट्रांसफर टीएमपी फ़ोल्डर टीएमपी फाइलों की सुस्त थी।

इन बाहर साफ नहीं किया जाना चाहिए हो रही

यह सामान्य रूप से कोड मैं का उपयोग करें। मुझे लगता है कि मुख्य है कि मैं एक पृष्ठभूमि सत्र में एकाधिक डाउनलोडटास्क (30 तक हो सकता है) संलग्न करता हूं। फाइलें फिल्मों से पीडीएफ में आकार में भिन्न होती हैं।

NSURLSession * backgroundSession_ = [NSURLSessionConfiguration backgroundSessionConfigurationWithIdentifier:identifier]; 


backgroundSession_ = [NSURLSession sessionWithConfiguration:urlSessionConfigurationBACKGROUND_ 
                delegate:self 
               delegateQueue:[NSOperationQueue mainQueue]]; 

NSOperationQueue *mainQueue_ = [NSOperationQueue mainQueue]; 



NSURLSessionDownloadTask * downloadTask_ = [backgroundSession_ downloadTaskWithURL:url_]; 

downloadStarted_ = TRUE; 
[downloadTask_ resume]; 

enter image description here

उत्तर

0

didFinishDownloadingToURL से लौटने से पहले कुछ इस तरह का प्रयास करें:

// App's Documents directory path 
NSString *docsPath = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES)firstObject]; 

// Creating the path for the downloaded file 
docsPath = [docsPath stringByAppendingPathComponent:downloadTask.response.suggestedFilename]; 

// Moving the file from temp location to App's Documents directory 
[[NSFileManager defaultManager] moveItemAtPath:location.path toPath:docsPath error:NULL]; 

documentation कहा गया है कि आप "फ़ाइल एक स्थायी स्थान के लिए अपने app के सैंडबॉक्स में आगे बढ़ना चाहिए इस प्रतिनिधि विधि से लौटने से पहले कंटेनर निर्देशिका " (शायद दस्तावेज़ निर्देशिका)।

ओएस के विवेक (आमतौर पर स्मृति दबाव के तहत) पर didFinishDownloadingToURL (या डाउनलोड विफल हुआ) से लौटने के बाद अस्थायी फ़ाइलें जो साफ़ हो जाती हैं।

0

मेरे पास एक ही समस्या है लेकिन कुछ अलग परिस्थितियों में: पुराने डिवाइस (आईफोन 4 एस या पुराने) पर ऐप आमतौर पर ओएस द्वारा प्राप्त पृष्ठभूमि के दौरान मारा जाता है। शायद स्मृति मुक्त करने के लिए। इस मामले में टीएमपी फाइलें बरकरार रखी जाती हैं (और अनचाहे)। अगली बार जब ऐप को लाने का अवसर मिलेगा, तो नई फाइलें बनाई गई हैं ... और यह चक्र चालू रहता है जब तक उपयोगकर्ता पहचानता है कि ऐप 4 जीबी स्टोरेज स्पेस का उपयोग नहीं करता है - और इसे हटा देता है।

मैं अभी तक सही समाधान नहीं मिला है - के बाद भी मैं एक कस्टम (प्रलेखन का कहना है यह डिफ़ॉल्ट रूप से नहीं के बराबर है) एक रास्ता एक ही निर्देशिका (defaultCacheDir/com.apple साथ करने के लिए पृष्ठभूमि विन्यास के -NSURLSessionConfiguration Urlcache सेट .nsurlsessiond/...) का उपयोग किया गया था - लेकिन एक सफाई विधि बनाई और इसका उपयोग तब किया जब मुझे यकीन है कि प्रगति में कोई डाउनलोड नहीं है।

+ (BOOL)clearCache:(NSError * __autoreleasing *)error 
{ 
    __block BOOL successOnLegacyPath = NO; 
    __block NSError *errorOnLegacyPath = nil; 

    NSString *cacheDirPath = [NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES) lastObject]; 

    NSArray *allSubPaths = [[NSFileManager defaultManager] subpathsAtPath:cacheDirPath]; 

    if (!allSubPaths) { 
     NSLog(@"No subpaths of cache:\n%@", cacheDirPath); 
    } else { 
     [allSubPaths enumerateObjectsUsingBlock:^(NSString *subpath, NSUInteger idx, BOOL *stop) { 
static NSString * const kNSURLSessionPathComponent = @"nsurlsession"; // this is a non-documented way, Uncle Apple can change the path at any time 
      if ([subpath containsString:kNSURLSessionPathComponent]) { 
       successOnLegacyPath = [[NSFileManager defaultManager] removeItemAtPath:[cacheDirPath stringByAppendingPathComponent:subpath] 
                       error:&errorOnLegacyPath]; 
       if (!successOnLegacyPath) { 
        NSLog(@"Error while deleting cache subpath:\n%@\nError:\n%@", subpath, errorOnLegacyPath); 
       } 
       // First we find is the root > bail out 
       *stop = YES; 
      } 
     }]; 
    } 

    if (!successOnLegacyPath && !errorOnLegacyPath) { 
     // Couldn't find the nsurlsession's cache directory 
     if (error) *error = [NSError errorWithDomain:NSCocoaErrorDomain 
               code:NSFileNoSuchFileError 
              userInfo:nil]; 

     // OR 
     successOnLegacyPath = YES; 
    } 

    return successOnLegacyPath; 
} 

यह एक समाधान नहीं है और इस करता है, तो कोई डाउनलोड प्रगति पर है उपयोग करने के लिए सिफारिश की है। अगर परीक्षण चल रहे हैं और tmp फ़ाइलों को हटाने की कोशिश कर रहे हैं तो परीक्षण नहीं किया गया है।

भले ही मुझे कोई समाधान मिल जाए, पहले भी बनाई गई tmp फ़ाइलें अभी भी अनचाहे रहती हैं, इसलिए उन्हें इस तरह की विधि से हटा दिया जाना चाहिए।

बीटीडब्ल्यू, this एक ही प्रश्न प्रतीत होता है - निष्कर्ष के बिना।

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