SecTrustCreateWithCertificates在iPad上崩溃

我正在尝试使用iOS安全框架来安全地与我的服务器通信。我有一个证书文件,我可以从中获得公钥引用。这就是我在做的事情。
 NSString *certPath    = [[NSBundle mainBundle] pathForResource:@"supportwarriors.com" ofType:@"cer"];
 SecCertificateRef myCertificate = nil;

 NSData *certificateData   = [[NSData alloc] initWithContentsOfFile:certPath]; 
 myCertificate     = SecCertificateCreateWithData(kCFAllocatorDefault, (CFDataRef)certificateData);

 //got certificate ref..Now get public key secKeyRef reference from certificate..
 SecPolicyRef myPolicy   = SecPolicyCreateBasicX509();
 SecTrustRef myTrust;
 OSStatus status     = SecTrustCreateWithCertificates(myCertificate,myPolicy,&myTrust);  

    SecTrustResultType trustResult;
    if (status == noErr) {
        status = SecTrustEvaluate(myTrust, &trustResult);  
    }
 publicKey      = SecTrustCopyPublicKey(myTrust);
上面的代码完全适用于iPhone,我测试过。我能够安全地与我的服务器通信。但是当我尝试在iPad上运行我的应用程序时(在2x模式下)上面的代码崩溃了。调试之后,我发现secTrustCreateWithCertificate崩溃并且崩溃日志在下面给出。我使用的证书对于iPad和iPhone都是相同的...上面的函数secCertificateCreateWithData返回证书引用并且不是nil ...所以这是不是崩溃的原因。我做错了什么。
*** -[NSCFType count]: unrecognized selector sent to instance 0x14af24
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '***      -[NSCFType count]: unrecognized selector sent to instance 0x14af24'
    
已邀请:
SecTrustCreateWithCertificates
的文档声称您可以传递单个证书或数组。你收到的例外情况是
-[NSCFType count]: unrecognized selector sent to instance
。在iOS 3.2中发生的事情是
SecTrustCreateWithCertificates
将输入值视为CFArray,而不先检查它是否是单数
SecCertificateRef
。 要解决此问题,您可以执行类似于以下代码的操作:
    SecCertificateRef certs[1] = { certificate };
    CFArrayRef array = CFArrayCreate(NULL, (const void **) certs, 1, NULL);
    if(SecTrustCreateWithCertificates(array, x509Policy, &trustChain) == errSecSuccess)
只记得在适当的范围内
CFRelease(array)
。     

要回复问题请先登录注册