- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
由于我在 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
}
最佳答案
以下是我最终对其进行编码以使其获得批准的方式。这可能有点矫枉过正,但比花一个月的时间试图准确猜测如何获得批准要好。
// 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 the directory does not yet exist on the phone, create it
if (![[NSFileManager defaultManager] fileExistsAtPath:dataPath])
[[NSFileManager defaultManager] createDirectoryAtPath:dataPath withIntermediateDirectories:NO attributes:nil error:nil];
// Assign NSURLIsExcludedFromBackupKey to the directory at dataPath, so is does not backup to iCloud
NSURL *directoryUrl = [NSURL fileURLWithPath:dataPath isDirectory:YES];
NSError *err1 = nil;
BOOL excluded1 = [directoryUrl
setResourceValue:[NSNumber numberWithBool:YES]
forKey:NSURLIsExcludedFromBackupKey
error:&err1];
if (!excluded1) {
//NSLog(@"Failed to exclude directory from backup");
} else {
//NSLog(@"Excluding directory from backup");
}
// Setup the NSURL where the PNG, which will be downloaded, is located
NSURL *imageURL = [NSURL URLWithString:@"http://www.myserver.com/image.png"];
NSError *err2 = nil; // Exclude This Image from the iCloud backup system, Not sure if I need this or not…
BOOL excluded2 = [imageURL setResourceValue:[NSNumber numberWithBool:YES] forKey:NSURLIsExcludedFromBackupKey error:&err2];
if (!excluded2) {
//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 *downloadedImageData = [NSData dataWithData:UIImagePNGRepresentation(image)];
// Path for where we are going to save the image
NSString *storePath = [NSString stringWithFormat:@"%@/myimage.png", dataPath];
if ([downloadedImageData writeToFile:storePath atomically:YES]) {
// the Image is saved to the phone
// NSURL representing the image that is now saved on the phone
NSURL *imageOnPhone = [NSURL fileURLWithPath:storePath isDirectory:YES];
// Exclude this image, which is now stored on the phone, from iCloud Backup
NSError *err3 = nil;
BOOL excluded3 = [imageOnPhone
setResourceValue:[NSNumber numberWithBool:YES]
forKey:NSURLIsExcludedFromBackupKey
error:&err3];
if (!excluded3) {
//NSLog(@"Failed to exclude from backup (standard)");
} else {
//NSLog(@"Excluding from backup (standard)");
}
} else {
// Did not save to phone
}
关于ios - 将 NSURLIsExcludedFromBackupKey 应用于 iPhone 上的服务器 URL 或目录 URL?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19940964/
我的 iPhone 应用程序包含大约 500 MB 数据。并且应用程序将离线使用该数据。所以我将该文件夹标记为不要在 iTunes 上备份/复制。所以我使用下面的网址: https://gist.gi
我的文档目录中有一个巨大的文件和目录树用于缓存。 按照建议,我将使用 NSURLIsExcludedFromBackupKey 来防止 iTunes 使用应用程序保存此数据。 我可以在我的根目录 UR
我试图阻止整个文件夹被 iTunes 备份。我关注了技术报告 http://developer.apple.com/library/ios/#qa/qa1719/_index.html但似乎 falg
我的应用最近因以下原因被拒绝: 2.23: Apps must follow the iOS Data Storage Guidelines or they will be rejected 这是因为
我如何确保使用模拟器为所有文件/文件夹正确设置 NSURLIsExcludedFromBackupKey(我目前没有可用的真实设备)? 最佳答案 您可以使用以下方式检查: NSError *error
我正在尝试设置属性 NSURLIsExcludedFromBackupKey 但找不到文件夹(或文件,如果我尝试分别对每个文件执行此操作)异常。 代码如下: override func viewDid
在 React Native 中我们有: type MkdirOptions = { NSURLIsExcludedFromBackupKey?: boolean; // iOS only };
我的应用被拒绝了,因为我将应用内购买数据保存在 iPhone 的文档文件夹中。 Data that can be recreated but must persist for proper funct
我的应用程序第二次被拒绝,我浪费了 3 周 :( 第一次提交时,我只排除了目录在 iCloud 中的备份。苹果拒绝... 第二次提交时,我将下载的目录和图片排除在 iCloud 中的备份之外。 App
我的应用因未遵循“iOS 数据存储指南”而多次被应用商店拒绝。我已经按照apple review team的建议给所有的文档目录都标上了“不备份”的属性,如图: - (BOOL)addSkipBack
我想为我的 Realm 文件设置 NSURLIsExcludedFromBackupKey。原因是因为我想将它从 iCloud 中排除。我有以下代码: public class func config
我的应用程序被拒绝,因为似乎 7 MB 存储在文档文件夹中,并且它们会自动发送到 icloud。所以我循环了所有将通过这种方法写入文档文件夹的文件: - (BOOL)addSkipBackupAttr
Apple 拒绝了我们的申请,因为我们在 localStorage (/Documents) 下存储供离线查看的文件这是消息的摘录,我们收到了: Data that can be recreated
与许多 iOS 开发人员一样,我在使用 NSURLIsExcludedFromBackupKey 时遇到过应用程序在 5.1 之前的系统上崩溃的问题。 很好地描述了如何评估此线程上此 key 的存在:
可用性检查似乎工作正常,但我似乎无法设置 NSURLIsExcludedFromBackupKey 键而不会在启动时发生崩溃: dyld: Symbol not found: _NSURLIsExcl
由于我在 iPhone 上保存一些下载文件的方式,我正在与应用程序拒绝作斗争。 我已经实现了 NSURLIsExcludedFromBackupKey 但我不清楚我是否正确地执行了它。我应该将 NSU
我看到这显然是可能的 submit apps without Lion installed , 但我的应用程序下载了一些大文件,需要根据 Apple storage guidelines 保存这些文件
我是一名优秀的程序员,十分优秀!