通过安装mobileconfig文件 ( Installing a configuration profile on iPhone - programmatically ) 在 iPhone 桌面上。
如何查看是否安装了这个配置文件?
在 iPhone Settings->General->provision file
中,我可以找到列表。
最佳答案
我遇到了以下方法来识别是否安装了移动配置,但到目前为止我还没有测试过。
There is no direct API available to do this.But there is a workaround to achieve this by the means of certificate trust verification.
If we attach a self-signed trust ca with mobile config and install it on the device we can check if the mobile config is installed by checking the trust level of the leaf certificate that is signed by the self-signed root ca.That is ,If leaf certificate's trust verification is failed in the app means the mobile config is not installed or else installed
步骤:
创建一个自签名根 CA,您可以在终端中使用Certificate Assistant 或 openssl 来完成。
创建另一个证书并使用自签名根 CA 为其签名
将在上一步中创建的签名证书附加到 xcode
将自签名根 CA 作为移动配置的一部分附加
代码片段:
-(BOOL)IsMobileConfigInstalled {
NSString* certPath = [[NSBundle mainBundle] pathForResource:@"LeafCertificate" ofType:@"cer"];
NSData* certData = [NSData dataWithContentsOfFile:certPath];
SecCertificateRef cert = SecCertificateCreateWithData(NULL, (__bridge CFDataRef) certData);
SecPolicyRef policy = SecPolicyCreateBasicX509();
SecTrustRef trust;
OSStatus err = SecTrustCreateWithCertificates((__bridge CFArrayRef) [NSArray arrayWithObject:(__bridge id)cert], policy, &trust);
SecTrustResultType trustResult = -1;
err = SecTrustEvaluate(trust, &trustResult);
CFRelease(trust);
CFRelease(policy);
CFRelease(cert);
if(trustResult == kSecTrustResultUnspecified)
return YES;
else
return NO;
}
引用资料:
这是 link在 Apple 开发者论坛中围绕该主题进行技术讨论
这是 link转到一篇逐步指导您的博客文章。
关于ios - 检查 iOS 上是否安装了 mobileconfig 配置文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27580428/