iOS開発でファイルパスを見つける方法



How Find File Paths Ios Development



NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES) //Get the path to the cache folder in the user's home directory NSSearchPathForDirectoriesInDomains(NSDesktopDirectory, NSUserDomainMask, YES)//Get the desktop path in the user's home directory NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSLocalDomainMask, YES) // Get the cache folder path in the local directory of the current machine NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES)//Get the Document folder path in the user's home directory NSSearchPathForDirectoriesInDomains(NSDocumentationDirectory, NSUserDomainMask, YES) // Get the path to the Documentation folder in the user's home directory NSSearchPathForDirectoriesInDomains(NSLibraryDirectory, NSUserDomainMask, YES) // Get the path to the Library folder in the user's home directory NSSearchPathForDirectoriesInDomains(NSAllLibrariesDirectory, NSUserDomainMask, YES) // Get the path to the AllLibraries folder in the user's home directory NSHomeDirectory()//Get the address of the sandbox main path NSHomeDirectoryForUser() //Get the sandbox main path of the specified username

結論:

NSSearchPathForDirectoriesInDomains('Folder directory you want to find', 'Which path area do you want to find from?') Searched area: typedef NS_OPTIONS(NSUInteger, NSSearchPathDomainMask) { NSUserDomainMask = 1, // user's home directory NSLocalDomainMask = 2, // local directory of the current machine NSNetworkDomainMask = 4, // publicly available location on the network NSSystemDomainMask = 8, // Unavailable location provided by Apple system (/System) NSAllDomainsMask = 0x0ffff // All and future locations above } The directory you want to find: NSApplicationDirectory = 1, // to the applications (Applications) directory NSDemoApplicationDirectory, // to the Applications/Demos directory NSDeveloperApplicationDirectory, // Go to the Developer/Applications directory. NSAdminApplicationDirectory, // to the Applications/Utilities directory NSLibraryDirectory, // to the Library directory NSDeveloperDirectory, // Go to the Developer directory. NSUserDirectory, // to the user's home directory NSDocumentationDirectory, // to the documentation (Documentation) directory NSDocumentDirectory, // to the documents (Documents) directory NSCoreServiceDirectory, // Location of the CoreServices directory (System/Library/CoreServices) NSAutosavedInformationDirectory NS_ENUM_AVAILABLE(10_6, 4_0) = 11, // Automatically saved document location (Documents/Autosaved) NSDesktopDirectory = 12, // local user's desktop NSCachesDirectory = 13, // local buffer directory (Library/Caches) NSApplicationSupportDirectory = 14, // local application support file directory (plug-ins, etc) (Library/Application Support) NSDownloadsDirectory NS_ENUM_AVAILABLE(10_5, 2_0) = 15, // Download the downloads directory locally NSInputMethodsDirectory NS_ENUM_AVAILABLE(10_6, 4_0) = 16, // Input method directory (Library/Input Methods) NSMoviesDirectory NS_ENUM_AVAILABLE(10_6, 4_0) = 17, // Movie Directory (~/Movies) NSMusicDirectory NS_ENUM_AVAILABLE(10_6, 4_0) = 18, // music directory (~/Music) NSPicturesDirectory NS_ENUM_AVAILABLE(10_6, 4_0) = 19, // Image Directory (~/Pictures) NSPrinterDescriptionDirectory NS_ENUM_AVAILABLE(10_6, 4_0) = 20, // PPDs directory (Library/Printers/PPDs) NSSharedPublicDirectory NS_ENUM_AVAILABLE(10_6, 4_0) = 21, // Local User Share Directory (~/Public) NSPreferencePanesDirectory NS_ENUM_AVAILABLE(10_6, 4_0) = 22, // The location of the PreferencePanes directory uses the system's preferences (Library/PreferencePanes) NSApplicationScriptsDirectory NS_ENUM_AVAILABLE(10_8, NA) = 23, // local user scripts folder, for the desired 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 paths that the app can take NSAllLibrariesDirectory = 101, //All directories where resources can occur NSTrashDirectory NS_ENUM_AVAILABLE(10_8, NA) = 102 // garbage storage directory } NSHomeDirectory() can only reach the user's home directory Print Results: /Users/zhangkai/Library/Developer/CoreSimulator/Devices/5B6F7171-5A09-4C6B-8B8F-933063ABE88C/data/Containers/Data/Application/A00149FA-66A6-42CE-92CB-A8C86258BACC NSString *tempPath = NSTemporaryDirectory() /Users/zhangkai/Library/Developer/CoreSimulator/Devices/5B6F7171-5A09-4C6B-8B8F-933063ABE88C/data/Containers/Data/Application/A00149FA-66A6-42CE-92CB-A8C86258BACC/tmp/ NSString *fullName=NSFullUserName() A full user name of the current user can be inserted in the desired path. NSString *userName=NSUserName() Returns the current user's login username NSString * NSHomeDirectoryForUser ( NSString *userName ) Returns the user root of the specified username (home) NSString * NSOpenStepRootDirectory (void) Returns the current user's system root directory