久久国产成人av_抖音国产毛片_a片网站免费观看_A片无码播放手机在线观看,色五月在线观看,亚洲精品m在线观看,女人自慰的免费网址,悠悠在线观看精品视频,一级日本片免费的,亚洲精品久,国产精品成人久久久久久久

分享

iOS 5的文件存儲(chǔ)策略應(yīng)對(duì)

 盧瑟的城堡 2012-04-20

蘋果在iOS 5系統(tǒng)時(shí),,對(duì)app的文件存儲(chǔ)提出了新的要求,。從它的guildline來看,,是推薦開發(fā)者盡量把a(bǔ)pp生成的文件放在Caches目錄下的。原文如下:

Only user-generated data or that cannot otherwise be recreated by your application, should be stored in the /Documents directory and rest should be stored to /Library/Caches directory。

照做會(huì)怎么樣,?

如果這么做的話,,會(huì)出現(xiàn)兩種情況

  1. 如果對(duì)此置之不理,繼續(xù)把應(yīng)用生成的文件放在Documents目錄下,,那么這些文件會(huì)被備份到iTunes或者iCloud,。如果這些文件很大,那么用戶可能需要為了同步消耗不少流量,,然后蘋果可能會(huì)因此拒絕你的應(yīng)用上架,,這是一個(gè)悲劇。
  2. 如果開發(fā)者照Apple說的干,,把應(yīng)用生成的文件放在Caches目錄下,,那么蘋果不會(huì)拒絕你的應(yīng)用,很happy,。但是iOS 5會(huì)在磁盤空間緊張的時(shí)候刪除Caches目錄下的文件,,這對(duì)用戶來說可能是一個(gè)更大的悲劇。

如何應(yīng)對(duì)新的文件存儲(chǔ)策略?

開發(fā)者在這時(shí)陷入了兩難的境地,,但是到了iOS 5.0.1的時(shí)候,,開發(fā)者多了第三種選擇:

  • 繼續(xù)把文件存儲(chǔ)在Documents目錄下,但是標(biāo)記這些文件為不需要備份,。詳情請(qǐng)參考 technote (QA1719)

原文如下:

Q: My app has a number of files that need to be stored on the device permanently for my app to function properly offline. However, those files do not contain user data and don’t need to be backed up. How should I store those files in iOS 5?

A: Starting in iOS 5.0.1 a new “do not back up” file attribute has been introduced allowing developers to clearly specify which files should be backed up, which files are local caches only and subject to purge, and which files should not be backed up but should also not be purged. In addition, setting this attribute on a folder will prevent the folder and all of its contents from being backed up.

代碼示例

給文件加上”do not back up”屬性的代碼如下,,需要注意這個(gè)是iOS 5.0.1才有效,低于這個(gè)版本就別費(fèi)勁了,。

#include <sys/xattr.h>
- (BOOL)addSkipBackupAttributeToItemAtURL:(NSURL *)URL
{
    const char* filePath = [[URL path] fileSystemRepresentation];

    const char* attrName = "com.apple.MobileBackup";
    u_int8_t attrValue = 1;

    int result = setxattr(filePath, attrName, &attrValue, sizeof(attrValue), 0, 0);
    return result == 0;
}

    本站是提供個(gè)人知識(shí)管理的網(wǎng)絡(luò)存儲(chǔ)空間,,所有內(nèi)容均由用戶發(fā)布,不代表本站觀點(diǎn),。請(qǐng)注意甄別內(nèi)容中的聯(lián)系方式,、誘導(dǎo)購(gòu)買等信息,謹(jǐn)防詐騙,。如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,,請(qǐng)點(diǎn)擊一鍵舉報(bào)。
    轉(zhuǎn)藏 分享 獻(xiàn)花(0

    0條評(píng)論

    發(fā)表

    請(qǐng)遵守用戶 評(píng)論公約

    類似文章 更多