之前工程中的Provisioning Profile文件过期,配置证书时入了不少坑,回过头来总结下配置证书步骤和注意事项
对于iOS开发者来说,apple开发者账号肯定不会陌生。在开发中我们离不开它。下面分享一下关于iOS开发中所用的证书相关知识。
第一部分:成员介绍
1.Certification(证书)
证书是对电脑开发资格的认证,每个开发者帐号有一套,分为两种:
1)Developer Certification(开发证书)
安装在电脑上提供权限:开发人员通过设备进行真机测试。
可以生成副本供多台电脑安装;
2)Distribution Certification(发布证书)
安装在电脑上提供发布iOS程序的权限:开发人员可以制做测试版和发布版的程序。不可生成副本,仅有配置该证书的电脑才可使用;
2.Provisioning Profile(授权文件)
授权文件是对设备如iPod Touch、iPad、iPhone的授权,文件内记录的是设备的UDID和程序的App Id,即:使被授权的设备可以安装或调试Bundle identifier与授权文件中记录的App Id对应的程序。
开发者帐号在创建授权文件时候会选择App Id,(开发者帐号下App Id中添加,单选)和UDID(开发者帐号下Devices中添加最多100个,多选)。
授权文件分为两种,对应相应的证书使用:
1)Developer Provisioning Profile(开发授权文件)
在装有开发证书或副本的电脑上使用,开发人员选择该授权文件通过电脑将程序安装到授权文件记录的设备中,即可进行真机测试。
注意:确保电脑有权限真机调试,即安装了开发证书或副本;在开发工具中程序的Bundle identifier和选中使用的授权文件的App Id要一致;连接调试的设备的UDID在选中的授权文件中有记录。
2)Distribution Provisioning Profile(发布授权文件)
在装有发布证书的电脑上(即配置证书的电脑,只有一台)制做测试版和发布版的程序。
发布版就是发布到App Store上的程序文件,开发者帐号创建授权文件时选择store选项,选择App Id,无需选择UDID;
测试版就是在发布之前交给测试人员可同步到设备上的程序文件,开发者帐号创建授权文件时选择AdHoc,选择App Id和UDID;只有选中的UDID对应的设备才可能安装上通过该授权文件制做的程序。
3. Keychain(开发密钥)
安装证书成功的情况下证书下都会生成Keychain,上面提到的证书副本(导出证书重新命名)就是通过配置证书的电脑导出Keychain(就是.p12文件)安装到其他机子上,让其他机子得到证书对应的权限。Developer Certification就可以制做副本Keychain分发到其他电脑上安装,使其可以进行真机测试。
注意:Distribution Certification只有配置证书的电脑才可使用,因此即使导出导出Keychain安装到其他电脑上,其他电脑也不可能具有证书的权限。
第二部分:证书申请流程
登陆iOS Dev Center选择进入iOS Provisioning Portal。

在iOS Provisioning Portal中,点击App IDs进入App ID列表。

创建 App ID,如果 ID 已经存在可以直接跳过此步骤

为 App 开启 Push Notification 功能。如果是已经创建的 App ID 也可以通过设置开启 Push Notification 功能。

根据实际情况完善 App ID 信息并提交,注意此处需要指定具体的 Bundle ID 不要使用通配符。

配置和下载证书
如果你之前没有创建过 Push 证书或者是要重新创建一个新的,请在证书列表下面新建。

新建证书需要注意选择证书种类(开发证书用于开发和调试使用,生产证书用于 App Store 发布)

点击 Continue 后选择证书对应的应用ID,然后继续会出现“About Creating a Certificate Signing Request (CSR)”。

根据它的说明创建打开KeychainAccess 创建 Certificate Signing Request。

填写“User Email Address”和“Common Name” 后选择 Saved to disk 进行保存 。

继续返回Apple developer 网站点击 Continue ,上传刚刚生成的 .certSigningRequest 文件生成 APNs Push Certificate。
下载并双击打开证书,证书打开时会启动“钥匙串访问”工具。
在“钥匙串访问”中你的证书会显示在“我的证书”中,注意选择“My Certificates” 和"login"

导出 .p12 证书文件
注意要选“login”和“My Certificates” 导出证书时要选中证书文件,不要展开private key。

将文件保存为Personal Information Exchange (.p12)格式。

将文件保存为Personal Information Exchange (.p12)格式。
上传证书
在JPush 管理 Portal 上,针对某应用程序,上传上面步骤得到 .p12 证书文件。这是 iOS SDK 能够接收到 JPush 推送消息的必要步骤。
Provisioning Profile的创建
创建Provisioning Profile的前提,已在Apple Developer网站创建待发布应用所使用的Bundle ID的App ID,且为该App ID创建了APNs证书,如下图:

创建App ID、APN证书和p12证书的导出的具体步骤请看 :iOS 证书 设置指南
在苹果开发者账号的Provisioning Profile页面点击下图按钮,创建Provisioning Profile

选择此Provisioning Profile的环境后点击[Continue]:

选择要创建Provisioning Profile的App ID后点击[Continue]:

选择所属的开发者证书,(这里创建了多个开发者证书,建议只创建一个,方便管理)为了方便,选择了[Select All],再点击[Continue]进入下一步:

为该Provisioning Profile选择将要安装的设备(一般选择[Select All]),点击[Continue]:

给该Provisioning Profile填写Profile Name,点击[generate]完成创建。

填写完Profile Name后点击[generate]完成创建,之后点击[DownLoad]下载Provisioning Profile

双击下载下来的Provisioning Profile,添加到xcode。
XCode的证书配置教程
参照iOS SDK 集成指南集成JPush SDK 和上传了推送用到的p12证书后在编译运行前需要先配置一下证书,步骤如下:
打开xxx-info.plist的Bundle identifier项把上传到JPush 控制台的bundle id填写进去:

点击项目,选择目标TARGETS后进入Build Setting 界面,搜索“Code signing”,按照下图配置
网友评论