ios應用, 設定不自動備份到iCloud
原創文章,轉載請註明出處
ios項目,如果有內建下載或者程式動態組建檔案的話,就要注意所下載或產生的檔案,要不要自動備份到iCloud
如果沒有合適的理由就自動上傳大檔案的話,可能在不能通過應用審核. 收到一下類似這樣的回覆
We also found that your app does not follow the iOS Data Storage Guidelines, which is required per the App Store Review Guidelines.
例如有人遇到同樣問題 http://stackoverflow.com/questions/16239147/ios-do-not-back-up-attribute
蘋果給出的設定方法:官方文檔 https://developer.apple.com/Library/ios/qa/qa1719/_index.html
應用到項目中, 具體代碼如下
#define DownLoad_Directory "Download_Dir"#pragma mark Download_Dirvoid DeviceClass::initDownloadDir(){ string l_strDocumentDir = cocos2d::CCFileUtils::sharedFileUtils()->getWritablePath(); l_strDocumentDir.append(DownLoad_Directory); NSString* l_strDownloadDir = [NSString stringWithUTF8String:l_strDocumentDir.c_str()]; NSError* l_error; if (![[NSFileManager defaultManager] fileExistsAtPath:l_strDownloadDir]){ [[NSFileManager defaultManager] createDirectoryAtPath:l_strDownloadDir withIntermediateDirectories:NO attributes:nil error:&l_error]; //Create folder // exclude downloads from iCloud backup NSURL *url = [NSURL fileURLWithPath:l_strDownloadDir]; if(strcmp(g_systemVersion.c_str(), "5.1") >=0 ){ if ([url setResourceValue:[NSNumber numberWithBool:YES] forKey:NSURLIsExcludedFromBackupKey error:&l_error] == NO) { NSLog(@"Error: Unable to exclude l_strDownloadDir from backup: %@", l_error); } } } //this->setDonotBackupInICloud();}就是在可寫目錄下建立一個新檔案夾, 存放下載檔案(需要的話,自動產生的檔案也放到這), 並標記這個目錄不會被上傳到iCloud
感謝梅俊同事的提醒
測試方法:
設定->iCloud->管理儲存空間->備份(如果有多裝置的話,選擇裝置)
應用多的話,點擊"顯示所有應用" 查到你的應用,在iCloud上備份內容的總容量.
開啟和關閉這個介面, 會發現, 你的應用在iCloud上的備份mwjg容量是不是一樣.