g0thX g0thX - 1 year ago 98
Objective-C Question

Log Cocoapod dependancies and version in iOS

I'd like to log which Cocoapods and their related versions I'm using in a project but not sure how to do this. Is there a method available that I can use to write these values to a log file? I'm using Objective-C for this project but I can port from Swift if needed.

Answer Source

Here's how I did this. First, go to Build Phases -> Copy Bundle Resources and add the Podfile.lock (add other..)

Then I use this method to return the contents of the file:

-(NSString *)getPodfileLockContent  

        NSString* podfileLockContent = nil;

        NSError* error;
        NSURL* podfileLockURL = [[NSBundle mainBundle] URLForResource:@"Podfile" withExtension:@"lock"];

        _podfileLockContent = [[NSString alloc] initWithContentsOfURL:podfileLockURL encoding:NSUTF8StringEncoding error:&error];
        if (podfileLockContent) {

            [NSLog(@"ERROR: failed to read Podfile.lock, make sure you have added it to the target in your project (this needs to be done manually at the moment). %@", error];

            return nil;

    return podfileLockContent;

This returns the full contents of the podfile.lock. You can just print this out or parse it for the values your require.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download