ios开发之NSBundle

来源:互联网 发布:java游戏吧 编辑:程序博客网 时间:2024/06/04 17:55

初始化和构造

- (nullable instancetype)initWithPath:(NSString *)path

根据路径初始化NSBundle对象

 + (nullable instancetype)bundleWithPath:(NSString *)path;

根据路径构造NSBundle对象

- (nullable instancetype)initWithURL:(NSURL *)url

根据URL初始化NSBundle对象。URL由路径构成。

 + (nullable instancetype)bundleWithURL:(NSURL *)url

根据URL构造NSBundle对象。URL由路径构成。

@property (class, readonly, strong) NSBundle *mainBundle;

返回应用程序的资源目录

@property (class, readonly, copy) NSArray<NSBundle *> *allBundles;

返回所有构建的NSBundle对象(类型不是Frameworks)

@property (class, readonly, copy) NSArray<NSBundle *> *allFrameworks;

返回所有构建的NSBundle对象(类型是Frameworks)

获取资源路径

+ (nullable NSString *)pathForResource:(nullable NSString *)name ofType:(nullable NSString *)ext inDirectory:(NSString *)bundlePath;

获取资源文件路径。参数name为资源文件名。参数ext为资源文件扩展名。参数bundlePath为资源文件的目录路径。

+ (NSArray<NSString *> *)pathsForResourcesOfType:(nullable NSString *)ext inDirectory:(NSString *)bundlePath;

获取所有相同文件类型的资源文件路径。参数ext为资源文件类型。参数bundlePath为资源文件的目录路径。

- (nullable NSString *)pathForResource:(nullable NSString *)name ofType:(nullable NSString *)ext;

获取资源文件路径。参数name为资源文件名。参数ext为资源文件扩展名。

- (nullable NSString *)pathForResource:(nullable NSString *)name ofType:(nullable NSString *)ext inDirectory:(nullable NSString *)subpath;

获取资源文件路径。参数name为资源文件名。参数ext为资源文件扩展名。参数subpath为资源文件目录下子目录名。因为资源目录文件下可以创建不同的目录来存放文件,所以需要subpath来区分不同的子目录。

- (nullable NSString *)pathForResource:(nullable NSString *)name ofType:(nullable NSString *)ext inDirectory:(nullable NSString *)subpath forLocalization:(nullable NSString *)localizationName;

获取资源文件路径。参数name为资源文件名。参数ext为资源文件扩展名。参数subpath为资源文件目录下子目录名。参数localizationName为本地名,该参数用于多语言环境。

- (NSArray<NSString *> *)pathsForResourcesOfType:(nullable NSString *)ext inDirectory:(nullable NSString *)subpath;

获取所有相同扩展名的资源文件的路径。参数ext为资源文件扩展名。参数subpath为资源文件目录下子目录名。

- (NSArray<NSString *> *)pathsForResourcesOfType:(nullable NSString *)ext inDirectory:(nullable NSString *)subpath forLocalization:(nullable NSString *)localizationName;

获取所有相同扩展名的资源文件的路径。参数ext为资源文件扩展名。参数subpath为资源文件目录下子目录名。参数localizationName为本地名,该参数用于多语言环境。

+ (nullable NSURL *)URLForResource:(nullable NSString *)name withExtension:(nullable NSString *)ext subdirectory:(nullable NSString *)subpath inBundleWithURL:(NSURL *)bundleURL

获取资源文件URL。参数name为资源文件名。参数ext为资源文件扩展名。参数subpath为资源文件目录下子目录名。参数bundleURL为bundle目录路径的URL,用于指定bundle。

- (nullable NSURL *)URLForResource:(nullable NSString *)name withExtension:(nullable NSString *)ext

获取资源文件URL。参数功能等同于pathForResource,只是返回类型为NSURL。NSURL由文件路径构造。
[NSURL fileURLWithPath: path];

- (nullable NSURL *)URLForResource:(nullable NSString *)name withExtension:(nullable NSString *)ext subdirectory:(nullable NSString *)subpath

获取资源文件URL。参数功能等同于pathForResource,只是返回类型为NSURL。NSURL由文件路径构造。
[NSURL fileURLWithPath: path];

- (nullable NSURL *)URLForResource:(nullable NSString *)name withExtension:(nullable NSString *)ext subdirectory:(nullable NSString *)subpath localization:(nullable NSString *)localizationName

获取资源文件URL。参数功能等同于pathForResource,只是返回类型为NSURL。NSURL由文件路径构造。
[NSURL fileURLWithPath: path];

- (nullable NSArray<NSURL *> *)URLsForResourcesWithExtension:(nullable NSString *)ext subdirectory:(nullable NSString *)subpath

获取所有相同扩展名的资源文件的URL。参数功能等同于pathsForResourcesOfType,只是返回类型为NSURL。

- (nullable NSArray<NSURL *> *)URLsForResourcesWithExtension:(nullable NSString *)ext subdirectory:(nullable NSString *)subpath localization:(nullable NSString *)localizationName

获取所有相同扩展名的资源文件的URL。参数功能等同于pathsForResourcesOfType,只是返回类型为NSURL。

+ (nullable NSArray<NSURL *> *)URLsForResourcesWithExtension:(nullable NSString *)ext subdirectory:(nullable NSString *)subpath inBundleWithURL:(NSURL *)bundleURL

获取所有相同扩展名的资源文件的URL。参数ext为资源文件扩展名。参数subpath为资源文件目录下子目录名。参数bundleURL为bundle目录路径的URL,用于指定bundle。

返回路径

@property (readonly, copy) NSString *bundlePath;

返回bundle的路径

@property (nullable, readonly, copy) NSString *resourcePath;

返回资源文件的路径

@property (nullable, readonly, copy) NSString *executablePath;

返回可执行文件的路径

@property (readonly, copy) NSURL *bundleURL

返回bundle的URL

@property (nullable, readonly, copy) NSURL *resourceURL

返回资源文件的URL

@property (nullable, readonly, copy) NSURL *executableURL

返回可执行文件的URL

- (nullable NSString *)pathForAuxiliaryExecutable:(NSString *)executableName;

辅助的可执行文件路径

- (nullable NSURL *)URLForAuxiliaryExecutable:(NSString *)executableName

辅助的可执行文件URL

@property (nullable, readonly, copy) NSString *privateFrameworksPath;

私有的框架路径

@property (nullable, readonly, copy) NSString *sharedFrameworksPath;

公共的框架路径

@property (nullable, readonly, copy) NSString *sharedSupportPath;

公共的支持路径

@property (nullable, readonly, copy) NSString *builtInPlugInsPath;

内置的插件路径

@property (nullable, readonly, copy) NSURL *privateFrameworksURL

私有的框架URL

@property (nullable, readonly, copy) NSURL *sharedFrameworksURL

公共的框架URL

@property (nullable, readonly, copy) NSURL *sharedSupportURL

公共的支持URL

@property (nullable, readonly, copy) NSURL *builtInPlugInsURL

内置的插件URL

@property (nullable, readonly, copy) NSURL *appStoreReceiptURL

应用商店收据URL

相关信息

@property (nullable, readonly, copy) NSDictionary<NSString *, id> *infoDictionary;

读取info.plist文件相关信息

@property (nullable, readonly, copy) NSString *bundleIdentifier;

返回标识符

@property (nullable, readonly, copy) NSDictionary<NSString *, id> *localizedInfoDictionary;

读取本地的info.plist文件相关信息

- (nullable id)objectForInfoDictionaryKey:(NSString *)key;

返回info.plist文件相关信息键对应的值

@property (readonly, copy) NSArray<NSString *> *localizations;

返回本地化文件名列表

@property (readonly, copy) NSArray<NSString *> *preferredLocalizations;

返回优先本地化文件名列表