unable to check if a configuration profile exists on the iPhone

I am trying to check if a configuration profile exists on the iPhone , I found the following tutorial on how to do it :

which , for me , translates into the following code :

  • xcode copy files build phase - what do the destination options mean exactly?
  • Autolayout and Constraints for iPad
  • can i change my iOS deployment target to 5.0 on xcode 4.5?
  • Twitter Post iOS6 'Cancel' button issue
  • How to convert .xcarchive to .ipa for client to submit app to app store using Application Loader
  • ERROR data argument not used by format string on mySLComposerSheet
  • NSString * certPath = [[NSBundle mainBundle] pathForResource:@"certificate" ofType:@"mobileconfig"];
        SecTrustRef trust;
        NSData * certData = [NSData dataWithContentsOfFile:certPath];
        SecCertificateRef cert = SecCertificateCreateWithData(NULL, (__bridge CFDataRef) certData);
        SecPolicyRef policy = SecPolicyCreateBasicX509();
        OSStatus err = SecTrustCreateWithCertificates((__bridge CFArrayRef) [NSArray arrayWithObject:(__bridge id)cert],policy, &trust);
        SecTrustResultType  trustResult = -1;
        err = SecTrustEvaluate(trust, &trustResult);
        if (trustResult ==4) {
            label.text=@"Profile installed";
            label.text=@"Profile not installed";

    the application crashes at the line :

    OSStatus err = SecTrustCreateWithCertificates((__bridge CFArrayRef) [NSArray arrayWithObject:(__bridge id)cert],policy, &trust);

    I also noticed that at this stage cert doesn t have any memory allocated in it .

    What is wrong? is this the correct procedure? if not, is there another tutorial that is more beneficial?


    2 Solutions Collect From Internet About “unable to check if a configuration profile exists on the iPhone”

    I am not sure as to why you’d want to do this through code. There are Mac OSx apps that already do this for you. If what you’re intending to do doesn’t have to involve code, you can download this Mac app called iPhone Configuration Utility from this Apple link. Has many features including configuring/view/etc profiles installed on an iPhone.

    I have recently solved the same problem that you are having. The code that you have posted and the advice from your link can indeed be used to check for the existence of a configuration profile. The snag that you have hit is undoubtedly a problem with your certificate.

    I created my pair of certificates using openSSL for win32 by ShiningLight. Full instructions on how to do it can be found here: http://www.dylanbeattie.net/docs/openssl_iis_ssl_howto.html

    note however, that there are a couple of gotchas:

    1. when creating your root certificate, the basicconstraints=CA setting in the config file must be set to TRUE (FALSE is needed for the other certificate).

    2. For IOs to be able to read them, both certificates must be encoded using DER. To do this using openssl you need to run a command similar to openssl x509 -in certs/cert.cer -out certs/certDER.cer -outform DER on both certificates. I strongly suspect it is the wrong encoding that is crashing your code.