आप इस प्रकार का उन डिवाइस के लिए उपलब्ध डिस्क स्थान प्राप्त कर सकते हैं:
- (NSNumber *)getAvailableDiskSpace
{
NSDictionary *attributes = [[NSFileManager defaultManager] attributesOfFileSystemForPath:@"/var" error:nil];
return [attributes objectForKey:NSFileSystemFreeSize];
}
आप की संभावना फ़ाइल आप डाउनलोड कर रहे हैं के आकार पाने के लिए डाउनलोड शुरू करने की आवश्यकता होगी।
- (void)URLSession:(NSURLSession *)session downloadTask:(NSURLSessionDownloadTask *)downloadTask didResumeAtOffset:(int64_t)fileOffset expectedTotalBytes:(int64_t)expectedTotalBytes
{
// Check if we have enough disk space to store the file
NSNumber *availableDiskSpace = [self getAvailableDiskSpace];
if (availableDiskSpace.longLongValue < expectedTotalBytes)
{
// If not, cancel the task
[downloadTask cancel];
// Alert the user
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"Low Disk Space" message:@"You don't have enough space on your device to download this file. Please clear up some space and try again." delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];
[alertView show];
}
}
डाउनलोड शुरू करने से पहले, फ़ाइल का आकार मिलता है और डिवाइस में खाली स्थान की जाँच: वहाँ है कि आप की उम्मीद बाइट्स देता NSURLSession के लिए एक सुविधाजनक प्रतिनिधि विधि अधिकार के रूप में काम शुरू करने की जाती है। ताकि यदि कोई पर्याप्त खाली स्थान न हो तो आप उपयोगकर्ता को सूचित कर सकते हैं। – Mrunal
यहां खाली स्थान की जांच करने का एक तरीका है: http://stackoverflow.com/questions/5712527/how-to-detect-total-available- फ्री-डिस्क- स्पेस-on-the-iphone-ipad-device – Mrunal
@Mrunal यह समस्या को पूरी तरह से हल नहीं करता है। क्या होगा यदि पृष्ठभूमि में एक बड़ी फ़ाइल डाउनलोड करने वाला कोई अन्य ऐप है? – HAS