由于我如何在 iPhone 上保存一些下载的文件,我正在与应用程序拒绝作斗争。
我已经实现了NSURLIsExcludedFromBackupKey
,但我不清楚我是否正确地执行了它。我应该应用NSURLIsExcludedFromBackupKey
到代表服务器上文件的 NSURL,还是以某种方式将其应用到 iPhone 上保存文件的目录?
这是我现在创建的,在应用程序被拒绝后:
// Get / Create the File Directory on the iPhone
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0]; // Get documents folder
NSString *dataPath = [documentsDirectory stringByAppendingPathComponent:@"MyDirectory"];
if (![[NSFileManager defaultManager] fileExistsAtPath:dataPath])
[[NSFileManager defaultManager] createDirectoryAtPath:dataPath withIntermediateDirectories:NO attributes:nil error:nil];
// Setup the NSURL where the PNG is located
NSURL *imageURL = [NSURL URLWithString:@"http://www.myserver.com/image.png"];
NSError *err = nil; // Exclude This Image from the iCloud backup system
BOOL excluded = [imageURL setResourceValue:[NSNumber numberWithBool:YES] forKey:NSURLIsExcludedFromBackupKey error:&err];
if (!excluded) {
//NSLog(@"Failed to exclude from backup");
} else {
//NSLog(@"Excluding from backup"); // this works...
}
// Create the UIImage
UIImage *image = [[UIImage alloc] initWithData:[NSData dataWithContentsOfURL:imageURL]];
// Data about the downloaded image
NSData *data1 = [NSData dataWithData:UIImagePNGRepresentation(image)];
if ([data1 writeToFile:pngFilePath atomically:YES] && [data1 writeToFile:pngFilePathRetina atomically:YES]) {
// Saved to phone
} else {
// Did not save to phone
}