第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

什么是文件目錄(NSDocumentDirectory)?

什么是文件目錄(NSDocumentDirectory)?

楊__羊羊 2019-08-16 16:27:29
什么是文件目錄(NSDocumentDirectory)?有人可以向我解釋iOS應(yīng)用程序上的文檔目錄以及何時使用它?以下是我目前的看法:對我來說,它似乎是一個中央文件夾,用戶可以存儲該應(yīng)用程序所需的任何文件。這與Core Data存儲數(shù)據(jù)的位置不同?似乎每個應(yīng)用程序都有自己的文檔目錄。我可以自由創(chuàng)建文件目錄的子目錄,如文件目錄/圖像,或文件目錄/視頻?
查看完整描述

3 回答

?
www說

TA貢獻1775條經(jīng)驗 獲得超8個贊

您的應(yīng)用程序(在非越獄設(shè)備上)在“沙盒”環(huán)境中運行。這意味著它只能訪問自己內(nèi)容中的文件和目錄。例如文檔

請參閱iOS應(yīng)用程序編程指南。

要訪問應(yīng)用程序沙箱的Documents目錄,可以使用以下命令:

iOS 8及更新版本,這是推薦的方法

+ (NSURL *)applicationDocumentsDirectory{
     return [[[NSFileManager defaultManager] URLsForDirectory:NSDocumentDirectory inDomains:NSUserDomainMask] lastObject];}

如果您需要支持iOS 7或更早版本

+ (NSString *) applicationDocumentsDirectory 
{    
    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
    NSString *basePath = paths.firstObject;
    return basePath;}

文檔目錄允許您存儲應(yīng)用程序創(chuàng)建或可能需要的文件和子目錄。

要訪問應(yīng)用程序沙箱的目錄中的文件,請使用(代替paths上述):

[NSSearchPathForDirectoriesInDomains(NSLibraryDirectory, NSUserDomainMask, YES) objectAtIndex:0]


查看完整回答
反對 回復(fù) 2019-08-16
?
慕碼人2483693

TA貢獻1860條經(jīng)驗 獲得超9個贊

我無法在接受的答案建議的文檔中找到代碼,但我在此處找到了更新的等效內(nèi)容:


文件系統(tǒng)編程指南::訪問文件和目錄?


- (NSURL*)applicationDataDirectory {

    NSFileManager* sharedFM = [NSFileManager defaultManager];

    NSArray* possibleURLs = [sharedFM URLsForDirectory:NSApplicationSupportDirectory

                                 inDomains:NSUserDomainMask];

    NSURL* appSupportDir = nil;

    NSURL* appDirectory = nil;


    if ([possibleURLs count] >= 1) {

        // Use the first directory (if multiple are returned)

        appSupportDir = [possibleURLs objectAtIndex:0];

    }


    // If a valid app support directory exists, add the

    // app's bundle ID to it to specify the final directory.

    if (appSupportDir) {

        NSString* appBundleID = [[NSBundle mainBundle] bundleIdentifier];

        appDirectory = [appSupportDir URLByAppendingPathComponent:appBundleID];

    }


    return appDirectory;

}

它不鼓勵使用NSSearchPathForDirectoriesInDomain:


NSSearchPathForDirectoriesInDomains函數(shù)的行為類似于URLForDirectory:inDomains:方法,但將目錄的位置作為基于字符串的路徑返回。您應(yīng)該使用URLForDirectory:inDomains:方法。


以下是一些其他有用的目錄常量。毫無疑問,iOS中并不支持所有這些功能。您還可以使用NSHomeDirectory()函數(shù):


在iOS中,主目錄是應(yīng)用程序的沙箱目錄。在OS X中,它是應(yīng)用程序的沙箱目錄或當(dāng)前用戶的主目錄(如果應(yīng)用程序不在沙箱中)


來自NSPathUtilities.h


NSApplicationDirectory = 1,             // supported applications (Applications)

    NSDemoApplicationDirectory,             // unsupported applications, demonstration versions (Demos)

    NSDeveloperApplicationDirectory,        // developer applications (Developer/Applications). DEPRECATED - there is no one single Developer directory.

    NSAdminApplicationDirectory,            // system and network administration applications (Administration)

    NSLibraryDirectory,                     // various documentation, support, and configuration files, resources (Library)

    NSDeveloperDirectory,                   // developer resources (Developer) DEPRECATED - there is no one single Developer directory.

    NSUserDirectory,                        // user home directories (Users)

    NSDocumentationDirectory,               // documentation (Documentation)

    NSDocumentDirectory,                    // documents (Documents)

    NSCoreServiceDirectory,                 // location of CoreServices directory (System/Library/CoreServices)

    NSAutosavedInformationDirectory NS_ENUM_AVAILABLE(10_6, 4_0) = 11,   // location of autosaved documents (Documents/Autosaved)

    NSDesktopDirectory = 12,                // location of user's desktop

    NSCachesDirectory = 13,                 // location of discardable cache files (Library/Caches)

    NSApplicationSupportDirectory = 14,     // location of application support files (plug-ins, etc) (Library/Application Support)

    NSDownloadsDirectory NS_ENUM_AVAILABLE(10_5, 2_0) = 15,              // location of the user's "Downloads" directory

    NSInputMethodsDirectory NS_ENUM_AVAILABLE(10_6, 4_0) = 16,           // input methods (Library/Input Methods)

    NSMoviesDirectory NS_ENUM_AVAILABLE(10_6, 4_0) = 17,                 // location of user's Movies directory (~/Movies)

    NSMusicDirectory NS_ENUM_AVAILABLE(10_6, 4_0) = 18,                  // location of user's Music directory (~/Music)

    NSPicturesDirectory NS_ENUM_AVAILABLE(10_6, 4_0) = 19,               // location of user's Pictures directory (~/Pictures)

    NSPrinterDescriptionDirectory NS_ENUM_AVAILABLE(10_6, 4_0) = 20,     // location of system's PPDs directory (Library/Printers/PPDs)

    NSSharedPublicDirectory NS_ENUM_AVAILABLE(10_6, 4_0) = 21,           // location of user's Public sharing directory (~/Public)

    NSPreferencePanesDirectory NS_ENUM_AVAILABLE(10_6, 4_0) = 22,        // location of the PreferencePanes directory for use with System Preferences (Library/PreferencePanes)

    NSApplicationScriptsDirectory NS_ENUM_AVAILABLE(10_8, NA) = 23,      // location of the user scripts folder for the calling application (~/Library/Application Scripts/code-signing-id)

    NSItemReplacementDirectory NS_ENUM_AVAILABLE(10_6, 4_0) = 99,       // For use with NSFileManager's URLForDirectory:inDomain:appropriateForURL:create:error:

    NSAllApplicationsDirectory = 100,       // all directories where applications can occur

    NSAllLibrariesDirectory = 101,          // all directories where resources can occur

    NSTrashDirectory NS_ENUM_AVAILABLE(10_8, NA) = 102                   // location of Trash directory

最后,NSURL類別中的一些便捷方法 http://club15cc.com/code/ios/easy-ios-file-directory-paths-with-this-handy-nsurl-category


查看完整回答
反對 回復(fù) 2019-08-16
  • 3 回答
  • 0 關(guān)注
  • 1552 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學(xué)習(xí)伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號