Check If a configuration profile was installed on IOS

Source: Internet
Author: User

Configuration profiles can downloaded to IOS device through Safari to configure the device in a certain the. You can does 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 profiles is installed and you can check indirectly. You basically embed a certificate authority in the configuration profile. When the profiles is installed it also installs the certificate authority. You create a certificate signed by the certificate authority and embed it in the app. Then on the app you check if the embedded certificate are trusted which indirectly tells you whether the profiles is install Ed. I got most of the information from this blog post but it took me a little when to work out what certificates to create so This version was 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 your ' 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 proper Ly. You'll 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 Credentials and press the "Configure" button on the right and select the certificate you just exported.

Now export your configuration profiles. You'll 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 BES set to Application/x-apple-aspen-config on your Web server.

You'll 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 is added to login keychains. Export the certificate as a. cer file and add it to XCode and make sure it's part of the Your app's package.

Use the following code to check if the 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 was installed on IOS

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.