Question

I have problem to write data to file. What I'm doing wrong?

SecTrustRef trust = [protectionSpace serverTrust];
SecCertificateRef certificate = SecTrustGetCertificateAtIndex(trust, 0);
NSData* ServerCertificateData = (__bridge NSData *)(certificate);
NSError* error;
[ServerCertificateData writeToFile:ServerCertPath options:NSDataWritingAtomic error:&error];
if(error != nil)
     NSLog(@"%@", error);
Was it helpful?

Solution

You can't convert the SecCertificateRef into a NSData * with a cast as you did. You need to use SecCertificateCopyData() on your certificate to get the data out of it.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top