我想,以检查是否在iPhone上存在一个配置文件,我发现了如何做到这一点下面的教程: http://alex.tapmania.org/2011/09/check_conf_prof_is_installed_ios.html
这对我来说,翻译成下面的代码:
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";
}
应用程序崩溃在该行:
OSStatus err = SecTrustCreateWithCertificates((__bridge CFArrayRef) [NSArray arrayWithObject:(__bridge id)cert],policy, &trust);
我还注意到,在这个阶段cert
没有按吨有任何内存分配它。
怎么了? 这是正确的程序? 如果没有,是否有另一个教程,更有利?
谢谢!