swift开发之--获取当前应用的配置信息
希望能把开发做的更细一点,知其然也知其所以然。
// 获取当前程序可执行文件所在目录 let mainBundle = Bundle.main // 获取程序包的识别标识符。 // 该标识符是应用程序的唯一标识,应用于标识符之间是一一对应关系。 // 请注意:应用新建成功后,该标识符将不可修改 let identifier = mainBundle.bundleIdentifier // 获取应用程序包的所有配置信息,并存储在字典对象中 let info = mainBundle.infoDictionary // 获取当前应用程序的名称 let bundleId = mainBundle.object(forInfoDictionaryKey: "CFBundleName") // 获取当前应用的版本号 let version = mainBundle.object(forInfoDictionaryKey: "CFBundleShortVersionString") // 控制台打印 print("[identifier]:\(identifier!)") print("[info]:\(info!)") print("[bundleId]:\(bundleId!)") print("[version]:\(version!)")
控制台打印如下:
[identifier]:com.yaosecu.DemoApp01 [info]:["DTPlatformVersion": 14.2, "UIStatusBarStyle": UIStatusBarStyleDarkContent, "CFBundleDevelopmentRegion": en, "CFBundlePackageType": APPL, "UILaunchStoryboardName": LaunchScreen, "LSRequiresIPhoneOS": 1, "MinimumOSVersion": 13.0, "DTXcodeBuild": 12B45b, "UIApplicationSceneManifest": { UIApplicationSupportsMultipleScenes = 1; UISceneConfigurations = { UIWindowSceneSessionRoleApplication = ( { UISceneConfigurationName = "Default Configuration"; UISceneDelegateClassName = "DemoApp01.SceneDelegate"; UISceneStoryboardFile = Main; } ); }; }, "DTSDKBuild": 18B79, "CFBundleInfoDictionaryVersion": 6.0, "CFBundleExecutable": DemoApp01, "UIStatusBarHidden": 1, "CFBundleVersion": 1, "CFBundleNumericVersion": 16809984, "CFBundleShortVersionString": 1.0, "CFBundleIdentifier": com.yaosecu.DemoApp01, "CFBundleName": 测试01, "UIDeviceFamily": <__NSArrayM 0x60000284a5e0>( 1, 2 ) , "UIMainStoryboardFile": Main, "UISupportedInterfaceOrientations": <__NSArrayM 0x60000284a6a0>( UIInterfaceOrientationPortrait, UIInterfaceOrientationLandscapeLeft, UIInterfaceOrientationLandscapeRight ) , "DTCompiler": com.apple.compilers.llvm.clang.1_0, "CFBundleSupportedPlatforms": <__NSArrayM 0x60000284a370>( iPhoneSimulator ) , "BuildMachineOSBuild": 19F101, "DTSDKName": iphonesimulator14.2, "DTPlatformBuild": 18B79, "UIRequiresFullScreen": 1, "DTXcode": 1220, "UIRequiredDeviceCapabilities": <__NSArrayM 0x60000284a610>( armv7 ) , "DTPlatformName": iphonesimulator] [bundleId]:测试01 [version]:1.0
仅做记录!
本文来自博客园,作者:稻草人11223,转载请注明原文链接:https://www.cnblogs.com/hero11223/p/14097428.html