Search code examples
objective-ciosxcodexcodebuild

XCode: Change xcarchive folder and file name


I'm generating the .xcarchive file from the command line, using:

xcodebuild -scheme fullxsTest archive CODE_SIGN_IDENTITY="" CODE_SIGNING_REQUIRED=NO

This puts the file in...

/Users/name/Library/Developer/Xcode/Archives/2012-09-12/App 10-09-12 13.45.xcarchive

... which is unfortunate since I would like to upload the file to a server and would like to specify a custom directory and file name for the .xcarchive file.

I tried the Locations in XCode Preferences, but it still places the file in a time stamped folder with a time stamped file name.

Is there a way to achieve this?


Solution

  • I've managed to extract the path and name of the file even if they are auto-generated with the following few lines:

    NSFileManager *fileManager = [NSFileManager defaultManager];
    NSArray *dirContents = [fileManager contentsOfDirectoryAtPath:BUILD_DIR_ROOT error:nil];
    NSString *archiveDir = [NSString stringWithFormat:@"%@/%@",BUILD_DIR_ROOT,[dirContents lastObject]];
    NSArray *arcContents = [fileManager contentsOfDirectoryAtPath:archiveDir error:nil];
    return [NSString stringWithFormat:@"%@/%@/%@",BUILD_DIR_ROOT,[dirContents lastObject],[arcContents lastObject]];
    

    After this I check that the returned value is not the automatically created hidden .DS_Store file and if it's not, then I'm good to go.