Swift setAnchorCert example?


#1

Does anyone have an example of using the CBLReplication setAnchorCert method in Swift they could share?

Swift + setAnchorCert example?


Basic usage of Public REST API (sync gateway)
#2

Is that a no?

No - examples?
No - not in Swift?

Anyone? Anyone?


#3

Okay. So I’m answering my own question so as to help others.

Tricks.

  • Your certificate needs to be in der format, and stored in your project bundle.
  • You need to ensure you include the certificate file as part of your project Copy Bundle Resources options.

This code is “base code” - you’ll need to add error checking etc.

let certificateFileName = "data" let certificatePath = NSBundle.mainBundle().pathForResource(certificateFileName, ofType: "der") let certificateData = NSData(contentsOfFile: certificatePath!) let certificate = SecCertificateCreateWithData(nil, certificateData!) CBLReplication.setAnchorCerts([certificate as! AnyObject], onlyThese: true)