Check if a configuration profile is installed on iOS
Configuration profiles can be downloaded to an iOS device through Safari to configure the device in a certain way. You can do things like force the user to set a passcode or set restrictions like not allowing them to install apps or not allowing access to Safari. They’re created using iPhone Configuration Utility. There’s no API to check if a profile is installed but you can check indirectly. You basically embed a certificate authority in the configuration profile. When the profile is installed it also installs the certificate authority. You create a certificate signed by the certificate authority and embed it in the app. Then in the app you check if the embedded certificate is trusted which indirectly tells you whether the profile is installed. I got most of the information from this blog post but it took me a little while to work out what certificates to create so this version is a bit more comprehensive.
In Keychain Access goto Keychain Access > Certificate Assistant > Create a Certificate Authority…
Check “Let me override defaults” and keep the defaults in the subsequent steps apart from the one’s shown below:
Uncheck “Sign your invitation”.
You might need to change the email address.
You can set capabilities to “Any”, though I’m not sure if it makes much difference.
When you’re finished creating the certificate authority it should show up in the login certificates. From there export the certificate authority as a .cer file. Don’t set any password on the exported certificate. If you want to delete the certificate authority and create it again deleting it in Kechain Access doesn’t remove it properly. You will need to go to ~/Library/Application Support/Certificate Authority and delete the relevant folder there.
Next open iPhone Configuration Utility. Select “Configuration Profiles” on the left and create a new configuration profile. Scroll down to Credentials and press the “Configure” button on the right and select the certificate you just exported.
Now export your configuration profile. You will probably need to sign it before you upload it to a web server so it shows up as “Verified” on the device. The mime type of the .mobileconfig files needs to be set to application/x-apple-aspen-config on your web server.
You will now need to create a certificate signed by the certificate authority. Go back to Keychain Access and goto Keychain Access > Certificate Assistant > Create a Certificate…
Set the identity type to “Leaf” and check “Let me override defaults”. Keep the defaults in the subsequent steps apart from the screens shown below:
You might want to change the email address.
You can set capabilities to “Any”, though I’m not sure if it makes much difference.
Again this certificate will be added to login keychains. Export the certificate as a .cer file and add it to XCode and make sure it’s part of your app’s package.
Use the following code to check if the profile is installed:
NSString* certPath = [[NSBundle mainBundle] pathForResource:@
"certificate"
ofType:@
"cer"
];
02.
if
(certPath==nil)
03.
return
TernaryIndefinite;
04.
NSData* certData = [NSData dataWithContentsOfFile:certPath];
05.
SecCertificateRef cert = SecCertificateCreateWithData(NULL, (__bridge CFDataRef) certData);
06.
SecPolicyRef policy = SecPolicyCreateBasicX509();
07.
SecTrustRef trust;
08.
OSStatus err = SecTrustCreateWithCertificates((__bridge CFArrayRef) [NSArray arrayWithObject:(__bridge id)cert], policy, &trust);
09.
SecTrustResultType trustResult = -1;
10.
err = SecTrustEvaluate(trust, &trustResult);
11.
CFRelease(trust);
12.
CFRelease(policy);
13.
CFRelease(cert);
14.
15.
if
(trustResult == kSecTrustResultUnspecified)
16.
// Profile is installed
17.
else
18.
// Profile not installed
Check if a configuration profile is installed on iOS的更多相关文章
- php学习日志(4)-The mbstring extension is missing. Please check your PHP configuration错误及解决方法
在安装好wampServer后,一直没有使用phpMyAdmin,今天用了一下,phpMyAdmin显示错误:The mbstring extension is missing. Please che ...
- Spring Configuration Check Unmapped Spring configuration files found
Spring Configuration Check Unmapped Spring configuration files found 项目中有xml文件,但没有被用IntelliJ 导入现有工程时 ...
- springbooot2 thymeleaf 配置以及加载资源文件。Cannot find template location: classpath:/templates/ (please add some templates or check your Thymeleaf configuration)
最近在学习springbooot2 和 thymeleaf 程序文件 application.properties文件配置: #thymeleaf spring.thymeleaf.prefix=cl ...
- Check which .NET Framework version is installed
his article will help you to know which .NET Framework version is installed from command line. Check ...
- ERROR 3077 (HY000): To have multiple channels, repository cannot be of type FILE; Please check the repository configuration and convert them to TABLE.
在5.7.16搭建多源复制时,出现如下错误: mysql> change master to master_host='192.168.56.156',master_user='repl', ...
- configure: error: off_t undefined; check your library configuration
configure: error: off_t undefined; check your library configuration 发生背景: 编译PHP时出现的提示,报错信息为: configu ...
- php源码安装执行configure报错error: off_t undefined; check your library configuration
php安装执行configure报错error: off_t undefined; check your library configuration vim /etc/ld.so.conf 添加如下几 ...
- phpMyAdmin-Error:The mbstring extension is missing. Please check your PHP configuration.
1.打开php.ini 2.找到 ; extension_dir = "./",把前面的分号去掉.引号里改成extension_dir = "D:php/ext" ...
- ios开发过程中描述文件(provisioning profile)过期导致ios无法正常安装的处理办法
1.登录开发者中心,重新编辑描述文件,获得最新的描述文件.(如果对应的P12文件也过期,需要同时下载最新的p12文件).----该步骤需要有权限的人才能操作. 2.下载最新的描述文件和p12文件(如果 ...
随机推荐
- jQuery学习笔记(五)jQuery中的表单
目录 单行文本框的应用 表单验证 上次我们说完jQuery中的动画之后,我们再来看一种jQuery在Web网页应用最为广泛的一种形式,这就是jQuery对表单的操作,通过jQuery对表单的操作,可以 ...
- 【前端】stopPropagation, preventDefault, return false的区别
e.stopPropagation()阻止事件冒泡或者捕获 因为事件可以在各层级的节点中传递, 不管是冒泡还是捕获, 有时我们希望事件在特定节点执行完之后不再传递, 可以使用事件对象的 stopPro ...
- slide效果
html和js部分 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://w ...
- Java开发中经典的小实例-(二分法)
public int binarySearch(int[] data,int aim){//以int数组为例,aim为需要查找的数 int start = 0; int end = data.leng ...
- kali/centos 更新 java
kali 转自:http://blog.sina.com.cn/s/blog_5736d8870102w15u.html 墙内的论坛上和博客上有很多这样的文章了,不过一般过程都很复杂,让人看的头晕眼花 ...
- FUNCTION
1,FUNCTION-1 CREATE FUNCTION `vendor_area_child_ids`(rootId INT) ) BEGIN ); ); SET pTemp = '$'; SET ...
- 封装的ajax请求
在做登录注册这类提交表单数据时,我们经常需要局部刷新网页来验证用户输入的信息,这就需要用到ajax请求,我们通常需要获取表单中的数据,发起ajax请求,通过服务程序,与数据库的数据进行比对,判断信息的 ...
- App的启动过程
App的启动过程 所有的app都是通过launcher去启动的 launcher自己也是一个app,一个系统级别的app,放在asystem/app/下,使用系统签名. 对代码进行分析
- Openfire用户密码加密解密
需求要求审核过程中都用匿名进行用户注册登录,注册用户审核通过后才使用openfire内置表 如何做到用户密码统一 Openfire是通过org.jivesoftware.util.Blowfish.j ...
- (原创)Windows系统后安装ubuntu,无法选择启动ubuntu。
继Window系统之后,安装Ubuntu系统. 问题:启动没有Grub的ubuntu启动项. 查看:/boot/grub/中只有txt和env,内容空白,grub没有设置好. 修复: sudo fdi ...