zoukankan      html  css  js  c++  java
  • iOS中Info.plist文件的常见配置


    .

    • 在创建一个新的Xcode工程后,会 在Supporting Files文件夹下自动生成一个工程名-Info.plist的文件,这个是对工程做一些运行期配置的文件(很重要,必须有该文件)。
    • 如果使用文本编辑器打开这个文件,会发现这是一个XML格式的文本文件,使用Xcode的Open As->Source Code或者Property List可以进行编辑,本文会重点介绍一些在iOS开发中常见的的Info.plist的配置项。

    1、设置启动图标(CFBundleIcons)

    	<key>CFBundleIcons</key>
    	<dict>
    	    <key>CFBundlePrimaryIcon</key>
    	    <dict>
    		<key>CFBundleIconFiles</key>
    		<array>
    		    <string>Icon</string>
    		    <string>Icon@2x</string>
    		    <string>Icon_120@2x</string>
    		</array>
    	    </dict>
    	</dict>
    

    2、设置启动闪屏图片(UILaunchImages)

    	<key>UILaunchImages</key>
    	<array>
    	    <dict>
    		<key>UILaunchImageMinimumOSVersion</key>
    		<string>7.0</string>
    		<key>UILaunchImageName</key>
    		<string>Default</string>
    		<key>UILaunchImageOrientation</key>
    		<string>Portrait</string>
    		<key>UILaunchImageSize</key>
    		<string>{320, 568}</string>
    	    </dict>
    	    <dict>
    		<key>UILaunchImageMinimumOSVersion</key>
    		<string>7.0</string>
    		<key>UILaunchImageName</key>
    		<string>Default</string>
    		<key>UILaunchImageOrientation</key>
    		<string>Portrait</string>
    		<key>UILaunchImageSize</key>
    		<string>{320, 480}</string>
    	    </dict>
    	</array>
    

    3、设置版本号相关

    • (1)设置Bundle的版本号(Bundle versions string, short)。

      • 一般包含该束的主、次版本号,这个字符串的格式通常是“n.n.n”(n表示某个数字,如1.1.1)。第一个数字是束的主要版本号,另两个是次要版本号。该关键字的值会被显示在Cocoa应用程序的关于对话框中。该关键字不同于CFBundleVersion,它指定了一个特殊的创建号。而CFBundleShortVersionString的值描述了一种更加正式的并且不随每一次创建而改变的版本号。
      	<key>CFBundleShortVersionString</key>
      	<string>1.0</string>
      
    • (2)设置应用程序版本号(Bundle version)。

      • 每次部署应用程序的一个新版本时,将会增加这个编号,用于标识不同的版本。
      	<key>CFBundleVersion</key>
      	<string>1.0</string>
      

    4、设置字体相关(Fonts provided by application)

    - 在iOS应用中需要使用系统提供的字体之外的字体,可以将字体文件(.ttf/.odf)复制到项目文件中,另外需要在Info.plist中添加Fonts provided by application的项,对应的源码文件如下:
    ``` Objective-C
    	<key>UIAppFonts</key>
    	<array>
    	    <string>华文行楷.ttf</string>
    	    <string>华文新魏.ttf</string>
    	    <string>黑体_GB2312.ttf</string>
    	</array>
    ```
    
    • P.S关于如何使用系统支持的字体信息:

      • (1)在调用字体的时候,要使用字体名。字体名不是文件名,而是字体的Family Name。Family Name可以在Font Book中查看。
      	label.font = [UIFont fontWithName:@"字体名称" size:16.0];
      
      • (2)遍历出系统支持的全部字体
      	NSArray *familyNames = [[NSArray alloc] initWithArray:[UIFont familyNames]];
      	for(int indFamily = 0; indFamily < familyNames.count; ++indFamily)
      	{
      	    NSLog(@"Family Name: %@", [familyNames objectAtIndex:indFamily]);
      	    NSString *fontFamilyName = [familyNames objectAtIndex:indFamily];
      	    NSArray *fontNames = [[NSArray alloc] initWithArray:[UIFont fontNamesForFamilyName:fontFamilyName]];
      	    for(int indFont = 0; indFont < fontNames.count; ++indFont)
      	    {
      		NSLog(@"   Font Name: %@", [fontNames objectAtIndex:indFont]);
      	    }
      	}
      

    5、设置应用名称(Bundle display name)

    	<key>CFBundleDisplayName</key>
    	<string>应用程序名称</string>
    
    • 可以通过在InfoPlist.strings中使用配置让应用在不同的语言环境下显示不同的应用名称,如在English中使用CFBundleDisplayName="Hello World";配置应用程序的名称为Hello World,在Chinese的环境下使用CFBundleDisplayName="你好世界";配置应用程序的名称为你好世界。

    6、设置应用标识号(Bundle identifier)

    	<key>CFBundleIdentifier</key>
    	<string>com.devzeng.demo</string>
    

    7、设置应用支持的屏幕方向(Supported interface orientations)

    - iOS应用程序支持以下四个方向的设置:UIInterfaceOrientationPortrait(默认竖直方向,HOME键向下)、UIInterfaceOrientationLandscapeLeft(横屏靠左)、UIInterfaceOrientationLandscapeRight(横屏向右)和UIInterfaceOrientationPortraitUpsideDown(竖直方向倒置,HOME键向上)
    - 对应的配置源码如下:
    ``` Objective-C
    	<key>UISupportedInterfaceOrientations</key>
    	<array>
    	    <string>UIInterfaceOrientationPortrait</string>
    	    <string>UIInterfaceOrientationLandscapeLeft</string>
    	    <string>UIInterfaceOrientationLandscapeRight</string>
    	    <string>UIInterfaceOrientationPortraitUpsideDown</string>
    	</array>
    ```
    

    8、设置应用程序是否支持后台运行(Application does not run in background)

    • 通过UIApplicationExitsOnSuspend可以设置iOS的应用程序进入到挂起状态下是否立即退出,设置为YES表示不支持后台运行退出到后台立即退出,设置为NO表示支持后台运行。
    • (1)设置支持后台运行

    	<key>UIApplicationExitsOnSuspend</key>
    	<false/>
    
    • (2)设置不支持后台运行

    	<key>UIApplicationExitsOnSuspend</key>
    	<true/>
    

    9、相机,通讯录,麦克风等权限设置

    • 在开发使用真机权限过程中,有时候忘记配置,会出现程序崩溃的问题
    	[access] This app has crashed because it attempted to access privacy-sensitive data without a usage description. 
    	The app's Info.plist must contain an NSPhotoLibraryUsageDescription key with a string value explaining to the user how the app uses this data.
    
    • 这个是拍照动作引起的崩溃,在升Xcode+iOS10之前都是好的,升级之后,需要在plist文件中添加相册权限。相应的麦克风,通讯录,如果项目中涉及到了,也需要添加相应的权限。报错的相应key值:
      • 通信录:NSContactsUsageDescription
      • 麦克风:NSMicrophoneUsageDescription
      • 相册:NSPhotoLibraryUsageDescription
    • 这里仅以相册的为例:
    • plist文件里面添加,Privacy - Photo Library Usage Description,Value值为描述,弹出的提示框会显示出来。
    • 升到iOS10之后,需要设置权限的有:
      • 麦克风权限:Privacy - Microphone Usage Description 是否允许此App使用你的麦克风?
      • 相机权限: Privacy - Camera Usage Description 是否允许此App使用你的相机?
      • 相册权限: Privacy - Photo Library Usage Description 是否允许此App访问你的媒体资料库?
      • 通讯录权限: Privacy - Contacts Usage Description 是否允许此App访问你的通讯录?
      • 蓝牙权限:Privacy - Bluetooth Peripheral Usage Description 是否许允此App使用蓝牙?
      • 语音转文字权限:Privacy - Speech Recognition Usage Description 是否允许此App使用语音识别?
      • 日历权限:Privacy - Calendars Usage Description
      • 定位权限:Privacy - Location When In Use Usage Description
      • 定位权限: Privacy - Location Always Usage Description
      • 位置权限:Privacy - Location Usage Description
      • 媒体库权限:Privacy - Media Library Usage Description
      • 健康分享权限:Privacy - Health Share Usage Description
      • 健康更新权限:Privacy - Health Update Usage Description
      • 运动使用权限:Privacy - Motion Usage Description
      • 音乐权限:Privacy - Music Usage Description
      • 提醒使用权限:Privacy - Reminders Usage Description
      • Siri使用权限:Privacy - Siri Usage Description
      • 电视供应商使用权限:Privacy - TV Provider Usage Description
      • 视频用户账号使用权限:Privacy - Video Subscriber Account Usage Description

    10、通用解释

    • 10.1

    • Localiztion native development region --- CFBundleDevelopmentRegion 本地化相关,如果⽤户所在地没有相应的语言资源,则用这个key的value来作为默认
    • Bundle display name --- CFBundleDisplayName 设置程序安装后显示的名称。应⽤程序名称限制在10-12个字符,如果超出,将被显示缩写名称。
    • Executaule dile -- CFBundleExecutable 程序安装包的名称
    • Bundle identidier --- CFBundleIdentidier 该束的唯一标识字符串,该字符串的格式类似 com.yourcompany.yourapp,
      • 如果使⽤用模拟器跑你的应用,这个字段没有用处,
      • 如果你需要把你的应⽤部署到设备上,你必须⽣成一个证书,
      • ⽽而在⽣生成证书的时候,在apple的⽹网站上需要增加相应的app IDs.
      • 这⾥有一个字段Bundle identidier,如果这个Bundle identidier是一个完整字符串,
      • 那么文件中的这个字段必须和后者完全相同,如果app IDs中的字段含有通配符*,那么文件中的字符串必须符合后者的描述。
    • InfoDictionary version --- CFBundleInfoDictionaryVersion Info.plist 格式的版本信息。

    • 10.2

    • Bundle name --- CFBundleName 产品名称
    • Bundle OS Type code -- CFBundlePackageType ⽤来标识束类型的四个字母长的代码
    • Bundle versions string, short --- CFBundleShortVersionString ⾯向用户市场的束的版本字符串
    • Bundle creator OS Type code --- CFBundleSignature 用来标识创建者的四个字母长的代码
    • Bundle version --- CFBundleVersion 应⽤程序版本号,每次部署应用程序的一个新版本时, 将会增加这个编号,在app store上用的。

    • 10.3

    • Application require iPhone environment -- LSRequiresIPhoneOS 用于指示程序包是否只能运行在iPhone OS 系统上。Xcode自动加入这个键,并将它的值设置为true。您不应该改变这个键的值。
    • Main storybard dile base name -- UIMainStoryboardFile 这是一个字符串,指定应用程序主nib文件的名称。
    • supported interface orientations -- UISupportedInterfaceOrientations 程序默认支持的设备方向。
  • 相关阅读:
    多线程
    序列化
    IO流
    递归
    JAVA异常处理
    java常用类-StringBuffer,Integer,Character
    系统测试过程
    备份,健壮,文档,在线帮助,网络,稳定性测试
    异常测试/恢复性测试(可靠)
    配置测试
  • 原文地址:https://www.cnblogs.com/CH520/p/9375243.html
Copyright © 2011-2022 走看看