ios - 检查 iOS 上是否安装了 mobileconfig 配置文件

标签 ios iphone ipad

通过安装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 Assistantopenssl 来完成。

  • 创建另一个证书并使用自签名根 CA 为其签名

  • 将在上一步中创建的签名证书附加到 xcode

  • 自签名根 CA 作为移动配置的一部分附加

    • 在 IPCU 中打开您的移动配置

    • 向下滚动到Credentials

    • 按右侧的配置

    • 选择自签名根 CA(确保其为 .cer 格式)

      iPCU

    • 现在导出移动配置并使用全局可信 CA 对其进行签名,例如 GoDaddy。此步骤是可选的,如果完成,设备将显示移动配置作为已验证,否则在安装移动配置时将显示为未验证


代码片段:

-(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转到一篇逐步指导您的博客文章。

这里是有关此主题的堆栈溢出讨论的链接 Ref1 , Ref22

关于ios - 检查 iOS 上是否安装了 mobileconfig 配置文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27580428/

相关文章:

ios - 如何在越狱的 iPhone 中使用命令 shell 卸载 iOS 应用程序

iphone - NSMutableArray 排序问题

ios - 在 iOS 8.1 之后,在所有设备上,当点击 alertview 取消按钮时,ScrollView 会向上移动并且不会滚动

iphone - 将标签数据从一个 View Controller 传递到另一个 View Controller

ios - UICollectionView 的 UILabel 中的奇怪文本问题

iphone - 使用适用于 iOS 的 Dropbox Chooser SDK 时无法生成链接错误

iphone - 使用自定义格式将字符串转换为NSDate

iPad 可滑动面板控制,如推特

objective-c - 警告 : iPad: Icon-72. png:图标尺寸 (0 x 0)

ios - 如何检查数组中连续的工作日