Apps must follow the iOS Data Storage Guidelines or they will be rejected

2.23 - Apps must follow the iOS Data Storage Guidelines or they will be rejected

On launch and content download, your app stores 19.1MB, which does not comply with the iOS Data Storage Guidelines.

原因是我把下載的內容放到 <Application_Home>/Documents 底下,而這目錄預設是會備份到 iCloud 以及 iTunes 。依照 Guidelines 來看,Documents 只能放由使用者操作後產生的,而那種能重複下載或產生的要放在 <Application_Home>/Library/Caches ,暫存檔則放在 <Application_Home>/tmp

Cachestmp 不會備份,且 Caches 不是永久的,當裝置容量不夠時會刪除、系統還原時也會清空,如果想要永久就只能放 Documents 。 Library 底下除了 Caches 以外都會備份到 iTunes ,但不會上傳至 iCloud 。

放在 Documents 的檔案也可以手動標示為不要備份,由於我想永久保留至 App 內所以我採用此方法。

- (BOOL)addSkipBackupAttributeToItemAtURL:(NSURL *)URL

{

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

    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;

}

請照以下步驟檢查 Documents 是否肥大
Install and launch your app
Go to Settings > iCloud > Storage > Manage Storage
Select your device
If necessary, tap "Show all apps"
Check your app's storage

參考連結
iOS Data Storage Guidelines
How do I prevent files from being backed up to iCloud and iTunes?
File System Programming Guide

發佈留言

發佈留言必須填寫的電子郵件地址不會公開。 必填欄位標示為 *