I am trying to check if a configuration profile exists on the iPhone , I found the following tutorial on how to do it : http://alex.tapmania.org/2011/09/check_conf_prof_is_installed_ios.html
which , for me , translates into the following code :
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";
}
else{
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?
Thanks!