在app运行的时候,需要读取info.plist中的信息,用以下代码可获取整个info.plist的信息
[[NSBundle mainBundle] infoDictionary]
以下为根据 key 值去取 URLTypes 里面对应的值:
+ (NSString *)URLSchemesForkey:(NSString *)key { NSDictionary *dict = [[NSBundle mainBundle] infoDictionary]; NSArray *urlTypes = dict[@"CFBundleURLTypes"]; NSString *urlSchemes = nil; for (NSDictionary *scheme in urlTypes) { NSString *schemeKey = scheme[@"CFBundleURLName"]; if ([schemeKey isEqualToString:key]) { urlSchemes = scheme[@"CFBundleURLSchemes"][0]; break; } } return urlSchemes; }
info.plist所有的信息,示例如下:
{ "" = ""; BuildMachineOSBuild = 16G1114; CFBundleDevelopmentRegion = "zh_CN"; CFBundleDisplayName = "xxxx"; CFBundleExecutable = Ronghemt; CFBundleIcons = { CFBundlePrimaryIcon = { CFBundleIconFiles = ( AppIcon20x20, AppIcon29x29, AppIcon40x40, AppIcon60x60 ); CFBundleIconName = AppIcon; }; }; CFBundleIdentifier = "xxxx"; CFBundleInfoDictionaryVersion = "6.0"; CFBundleName = xxx; CFBundleNumericVersion = 0; CFBundlePackageType = APPL; CFBundleShortVersionString = "2.xxx"; CFBundleSupportedPlatforms = ( iPhoneOS ); CFBundleURLTypes = ( { CFBundleTypeRole = Editor; CFBundleURLName = WX; CFBundleURLSchemes = ( xxx ); }, { CFBundleTypeRole = Editor; CFBundleURLName = xxx; CFBundleURLSchemes = ( "xxx" ); }, { CFBundleTypeRole = Editor; CFBundleURLName = tencent; CFBundleURLSchemes = ( xxx ); }, { CFBundleTypeRole = Editor; CFBundleURLName = QQ; CFBundleURLSchemes = ( xxx ); }, { CFBundleTypeRole = Editor; CFBundleURLName = xxxx; CFBundleURLSchemes = ( xxxxxx ); } ); CFBundleVersion = "180119.001"; DTCompiler = "com.apple.compilers.llvm.clang.1_0"; DTPlatformBuild = 15C107; DTPlatformName = iphoneos; DTPlatformVersion = "11.2"; DTSDKBuild = 15C107; DTSDKName = "iphoneos11.2"; DTXcode = 0920; DTXcodeBuild = 9C40b; LSApplicationQueriesSchemes = ( wechat, weixin, sinaweibohd, sinaweibo, sinaweibosso, weibosdk, "weibosdk2.5", mqqapi, mqq ); LSRequiresIPhoneOS = 1; MinimumOSVersion = "8.0"; NSAppTransportSecurity = { NSAllowsArbitraryLoads = 1; NSAllowsArbitraryLoadsInWebContent = 1; }; NSCameraUsageDescription = "U9700U8981U8bbfU95eeU60a8U7684U76f8U673aU8fdbU884cU62cdU6444"; NSPhotoLibraryUsageDescription = "U9700U8981U8bbfU95eeU60a8U7684U76f8U518cU83b7U53d6U56feU7247"; UIDeviceFamily = ( 1 ); UILaunchImages = ( { UILaunchImageMinimumOSVersion = "8.0"; UILaunchImageName = "LaunchImage-800-Portrait-736h"; UILaunchImageOrientation = Portrait; UILaunchImageSize = "{414, 736}"; }, { UILaunchImageMinimumOSVersion = "8.0"; UILaunchImageName = "LaunchImage-800-667h"; UILaunchImageOrientation = Portrait; UILaunchImageSize = "{375, 667}"; }, { UILaunchImageMinimumOSVersion = "7.0"; UILaunchImageName = "LaunchImage-700"; UILaunchImageOrientation = Portrait; UILaunchImageSize = "{320, 480}"; }, { UILaunchImageMinimumOSVersion = "7.0"; UILaunchImageName = "LaunchImage-700-568h"; UILaunchImageOrientation = Portrait; UILaunchImageSize = "{320, 568}"; } ); UIRequiredDeviceCapabilities = ( arm64 ); UIStatusBarStyle = UIStatusBarStyleLightContent; UISupportedInterfaceOrientations = ( UIInterfaceOrientationPortrait, UIInterfaceOrientationLandscapeLeft, UIInterfaceOrientationLandscapeRight ); }