您的位置:首页 > 移动开发

app上架,iCloud存储的内容过多问题。

2015-01-23 00:17 337 查看
问题描述:我的db 图片 MP3 文件 当用户启动app的时候都把它们拷贝到/Documents 目录下 这样貌似不行。

In particular, we found that on launch and/or content download, your app stores 2.02 MB. To check how much data your app is storing:

- Install and launch your app
- Go to Settings > iCloud > Storage & Backup > Manage Storage
- If necessary, tap "Show all apps"
- Check your app's storage

上边英文主要是说,除用户自己创建的文件,其他文件如app的自己离线文件,都不能存到icloud上,这是苹果的存储规则。

问题解决:

1、最好不要把app自己生成的文件和用户的文件放在一个文件目录下,方便以后获取路径。

2、如何防止文件被备份到iCloud 和iTunes

从iOS 5.1开始,应用可以使用NSURLIsExcludedFromBackupKeykCFURLIsExcludedFromBackupKey 文件属性来防止文件被备份。这些API是通过通过旧的,弃用的方式的直接设置额外属性。所有运行在iOS5.1的都应该使用这些API包防止文件被备份。

在iOS5 .1上防止文件被备份


- (BOOL)addSkipBackupAttributeToItemAtURL:(NSURL *)URL

{

assert([[NSFileManager defaultManager] fileExistsAtPath: [URL path]]);

NSError *error = nil;

BOOL success = [URL setResourceValue: [NSNumber numberWithBool: YES]

forKey: NSURLIsExcludedFromBackupKey error: &error];

if(!success){

NSLog(@"Error excluding %@ from backup %@", [URL lastPathComponent], error);

}

return success;

}

addSkipBackupAttributeToItemAtURL 方法怎么用呢?
然后更改为此在 app delegate.m 中:
[code]NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory , NSUserDomainMask, YES);
documentsDir = [paths objectAtIndex:0];
[self addSkipBackupAttributeToItemAtURL:[NSURL fileURLWithPath:
documentsDir
];

这样就可以保证app的documents文件内容不备份到icloud上,其他文件目录同理。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: