Speed up iOS tests using an alternative application delegate

Screen Shot 2016-06-08 at 11.04.57 Why skipping the regular launch sequence when testing using an alternative application delegate can be useful ? You can find your own answer, in my case: speed! and because i want to be able to test host application APIs (to run tests in iPhone environment and test Xib loading and other things) but without all the usual launch sequence.


Adopting Fastlane for automating our daily iOS developements tasks


For those who don't know:  Fastlane is the Holy Grail (the one that Indiana Jones was really looking for, if only he had been an iOS programmer) Fastlane helps you automate every aspect of your release to the App Store. It allows coders to deploy app updates from any computer, set up and submit apps more easily, and automate the use of the standard commands required for app revision and testing. We can even add components on top of Fastlane itself — the tools support customized, user-built actions to extend their functionality. But what exactly are the usual steps around iOS development and releases to the App Store ? Current steps (of course can vary):
  • Pull changes from remote repository
  • Run tests (including UI testing) (if got lucky there is nothing to fix)
  • Increment build number (and version number if required)
  • Check provisioning profiles and certificates for code signing (Freddy Krueger was the creator of all this process for sure!)
  • Build new binary version
  • Generate release notes for every supported localisation
  • Take screenshots for every device and every supported localisation
  • Prepare new version on iTunes Connect (and TestFlight)
  • Upload binary to iTunes Connect
  • Share with testers
  • Upload binary to Crashlytics Beta
  • Share with testers
  • Push changes to remote repository
😩 That is a lot to handle in one day! Because just taking into account the binary build time plus iTunes related stuff time.... got and get your bag to sleep at the office. Of course, the duration can be different depending on some miracles (cof cof #iosprocessingtime).   So publishing a new version to iTunes App Store is very awkward and time consuming. But, no more! Now with a single command: I do all these steps:
  • Increment project build number
  • Download up-to date provisioning profiles for code signing
  • Build/Archive the app using the correct scheme (QuitNow or QuitNow Pro)
  • Notify to channels (cli, slack, mac os x notification center)
  • Upload a perfectly signed binary to TestFlight/Crashlytics for Beta testers to try

  And i just need to use my time in another task while Fastlane save me 30 minutes.

Screen Shot 2016-04-27 at 14.57.21 

The last step: "notification" , puts a message at the console and also at the notification center.... a reminder like:

Screen Shot 2016-04-28 at 10.27.45 

Fastlane pilot_free task looks like this:

You can improve the process to fit your needs, including running test, syncing changes from remote repositories and much more.

You can even make it to work only on specific git branches and only if they are not dirty. And you can commit changes at the end, like committing the new build number bump and push it to the remote repository.

Lets see our lane for releasing a new version to iTunes:

Another automation example: Generate APNS Certificates containers for your server (PUSH notifications related)

Btw, this post is approved by Felipe



Authentication Challenge with multiple in-house certificate authorities in iOS with Swift

In one of my recent projects there was a requirement for a certificate and public key pinning. The API performs its operation from servers with certificates signed by an in-house certificate authority (self-signed too of course).
But there are multiple CA, and clients servers can have different CA, so a hard-coding approach was not the best. So the idea is to validate the certificate to ensure that is was signed by any of the provided trusted CA.
In this example we are going to implement the protocol NSURLSessionDelegate specifically the function which handles server certificate validation
So lets see the code

public func URLSession(session: NSURLSession, didReceiveChallenge challenge: NSURLAuthenticationChallenge, completionHandler: (NSURLSessionAuthChallengeDisposition, NSURLCredential?) -> Void) {
        if challenge.protectionSpace.authenticationMethod == NSURLAuthenticationMethodServerTrust {

            let trust = challenge.protectionSpace.serverTrust
            let rootCaCerts = self.rootCACertificatesData.map() {
                (data) -> CFData? in
                return CFDataCreate(kCFAllocatorDefault, UnsafePointer(data.bytes), data.length)
                }.filter({$0 != nil}).map() { ref -> CFTypeRef in
                    return SecCertificateCreateWithData(kCFAllocatorDefault, ref!)!
            let certArrayRef : CFArrayRef = CFBridgingRetain(rootCaCerts as NSArray) as! CFArrayRef
            SecTrustSetAnchorCertificates(trust!, certArrayRef)
            SecTrustSetAnchorCertificatesOnly(trust!, true) // if "true" then also allows certificates signed with one of the system available root certificates.
            var trustResult: SecTrustResultType = 0
            SecTrustEvaluate(trust!, &trustResult)
            if (Int(trustResult) == kSecTrustResultUnspecified ||
                Int(trustResult) == kSecTrustResultProceed) {
                    //Trust the server certificate cause its signed with one of the allowed in-house CA
                    let credential = NSURLCredential(forTrust: challenge.protectionSpace.serverTrust!)
                    challenge.sender!.useCredential(credential, forAuthenticationChallenge: challenge)
                    completionHandler(NSURLSessionAuthChallengeDisposition.UseCredential, credential)
            } else {
                print("Invalid server certificate.") //this also happens with expired certificates
                completionHandler(NSURLSessionAuthChallengeDisposition.CancelAuthenticationChallenge, nil)

        } else {
            print("Unexpected authentication method");
            completionHandler(NSURLSessionAuthChallengeDisposition.CancelAuthenticationChallenge, nil)


So, trust or die xD
rootCACertificatesData its an NSData array with the CA certificates file content …. DER encoded certificates added to the project.
So instead of a list with files names, let's find all the “DER” files and load them into an array:

let enumerator = NSFileManager.defaultManager().enumeratorAtPath(NSBundle.mainBundle().bundlePath)
    while let filePath = enumerator?.nextObject() as? String {
     if NSURL(fileURLWithPath: filePath).pathExtension == "der" {
         if let data = NSData(contentsOfURL:(NSBundle.mainBundle().bundleURL.URLByAppendingPathComponent(filePath))) {


New Job and a time for a career reinvention

Hello everyone,
I know this is not usual post but i want to let you know something very exiting (for me):
I got a new job!
With more than 8 years working in the Hospitality Industry and in the same company as a Software Engineer i thought it was the time for a career change. 
Time for new projects and new challenges. 
I have been involved in numerous large-scale software releases providing me with a good hands-on experience creating and implementing software achitectures, also the ability to troubleshoot and solve problems in a timely and accurate manner.
As a software engineer, and more recently, 
I have:
  • Build enterprise backend services/architecture for high load, high traffic, high availability processes for the Hospitality-Tourism industry, to help Individual and Chains of Properties(Hotels,Restaurants,SPAs,etc) to sell their inventory almost in "real time", including their rates, enhancements,services, packages, promotions and deals through existing channels. 
  • Build a distributed client-server architecture for an Auto-Trade, a Trading system on top of the Award Winning Platform Ninja Trader.
  • Build mobile software for the majors platforms: Android, IOs, Window Phone and HTML5 webapps.
I think that i'm well-seasoned about services/architecture for high load, high traffic, high availability processes (that's my main area of interest).
So, i have a lot of confidence about my skills on this industry(Hospitality), 
But after that long time, and with the job change desicion in mind, some "fears" appeared.
You might not call it fear. But let’s face it. That’s what stops us from making the move out of a "miserable" job, or starting over in a new field no matter how right the time is to do just that. 
It’s paralyzing
Some of those fears are:
  • Fear of the unknown
  • Fear of failure
  • Fear of not complying with other people's expectations
  • Fear of making a bad career change choice
  • Fear of economic stability (having a family to maintain puts more preasure ¬¬)
To be honest. 
Right now, i'm a full time Java Enterprise Application Developer.
My job, almost all consist in developing backend services, and
I'm switching to a Mobile career.
Yes, i will continue as a Software Engineer, but on the Mobile side mainly, developing apps and mobile services for Android, iOS, Windows Phone and others.
Rigth time
I don't know about the future, but i think is and they got me in the rigth time.
Yes, i'm switching, i'm giving my career and oportunity.
I'm really excited about this new job i think is a great opportunity. 
I am going into a new adventure with the guys at http://fewlaps.com/
They convinced me with : "Come with us and you will be happy".
The guys at Fewlaps are Master Craftsmen in the development of mobile applications.
I am very happy to become a part of the company and i will work for a great development with my complete knowledge and skills.

Creative Commons License This page is powered by Blogger. Isn't yours?