標籤:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// 讀取Documents目錄代碼
NSArray *pathsDocuments=NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMask,YES);
NSString *pathDocuments=[pathsDocuments objectAtIndex:0];
// NSLog(@"pathDocuments~~~~~~%@ pathsDocuments----%@",pathDocuments,pathsDocuments);
/*
pathDocuments~~~~~~/Users/yhj/Library/Developer/CoreSimulator/Devices/65FC33FE-6234-427B-A4F2-4F22ACE36842/data/Containers/Data/Application/12EA0817-D2C0-40E5-B3CC-1EB642FCDF9F/Documents pathsDocuments----(
"/Users/yhj/Library/Developer/CoreSimulator/Devices/65FC33FE-6234-427B-A4F2-4F22ACE36842/data/Containers/Data/Application/12EA0817-D2C0-40E5-B3CC-1EB642FCDF9F/Documents"
)
*/
// 讀取Cache目錄代碼
NSArray *pathsCache=NSSearchPathForDirectoriesInDomains(NSCachesDirectory,NSUserDomainMask,YES);
NSString *pathCache=[pathsCache objectAtIndex:0];
// NSLog(@"pathCache~~~~~~%@ pathsCache----%@",pathsCache,pathCache);
/*
pathCache~~~~~~(
"/Users/yhj/Library/Developer/CoreSimulator/Devices/65FC33FE-6234-427B-A4F2-4F22ACE36842/data/Containers/Data/Application/823489C8-00DA-403B-95AB-76C8FBE8AAAA/Library/Caches"
) pathsCache----/Users/yhj/Library/Developer/CoreSimulator/Devices/65FC33FE-6234-427B-A4F2-4F22ACE36842/data/Containers/Data/Application/823489C8-00DA-403B-95AB-76C8FBE8AAAA/Library/Caches
*/
// 讀取Library目錄
NSArray *pathsLibrary=NSSearchPathForDirectoriesInDomains(NSLibraryDirectory,NSUserDomainMask, YES);
NSString *pathLibrary=[pathsLibrary objectAtIndex:0];
// NSLog(@"pathsLibrary~~~~~~%@ pathLibrary----%@",pathsLibrary,pathLibrary);
/*
pathsLibrary~~~~~~(
"/Users/yhj/Library/Developer/CoreSimulator/Devices/65FC33FE-6234-427B-A4F2-4F22ACE36842/data/Containers/Data/Application/05969A2D-E6BD-4F4B-A57E-4414D987D240/Library"
) pathLibrary----/Users/yhj/Library/Developer/CoreSimulator/Devices/65FC33FE-6234-427B-A4F2-4F22ACE36842/data/Containers/Data/Application/05969A2D-E6BD-4F4B-A57E-4414D987D240/Library
*/
// 讀取temp檔案夾
NSString *tempDir=NSTemporaryDirectory();
// NSLog(@"tempDir~~~%@",tempDir);
/*
tempDir~~~/Users/yhj/Library/Developer/CoreSimulator/Devices/65FC33FE-6234-427B-A4F2-4F22ACE36842/data/Containers/Data/Application/CEF70855-6285-46D9-B7BF-B4C9AAB1816B/tmp/
*/
// 項目內建的.bundle資產庫放在.bundle中這些資源唯讀不能寫
NSString *defaultDBPath=[[NSBundle mainBundle] resourcePath];
NSLog(@"defaultDBPath~~%@",defaultDBPath);
/*
defaultDBPath~~/Users/yhj/Library/Developer/CoreSimulator/Devices/65FC33FE-6234-427B-A4F2-4F22ACE36842/data/Containers/Bundle/Application/D94DD7F5-0CE9-4EEF-8E47-37C4737EF2CF/IOS沙箱Files目錄說明和常用操作.app
*/
// 可以保證app的documents檔案內容不備份到icloud上
[self addSkipBackupAttributeToItemAtURL:[NSURL fileURLWithPath:pathDocuments]];
return YES;
}
// 用NSURLIsExcludedFromBackupKey 或 kCFURLIsExcludedFromBackupKey 檔案屬性來防止檔案被備份。這些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;
}
IOS沙箱Files目錄說明和常用操作