1. 程式人生 > 實用技巧 >swift開發之--獲取當前應用的配置資訊

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

僅做記錄!