This guide is based on Tom Gersic’s guide. I chose to rewrite it since Tom’s original contains some formatting errors.
If you’re ever in a situation where you’re developing an iOS app for a company who wants it to be uploaded using their own developer account, this guide is for you. Following the steps below you can switch out your own provisioning profile with your client’s. This is also useful for testing your final App Store distribution build by re-signing the build with an Ad-Hoc profile of your own.
If you’re following this guide to send an .ipa to a client, make sure to sign it with an Ad-Hoc provisioning profile, not an in-house one, since that violates Apple’s license agreement (more details in the original article).
Bundle ID
Re-signing only works if the Bundle ID is the same for both profiles. If the client is using a Bundle ID called com.somecompany.greatapp, you would create a Bundle ID called com.somecompany.* and use that for your provisioning profile.
Re-Signing the App
Now you can go ahead and re-sign the app. However, you would need your client’s provisioning profile, so this would be done by someone on their end.
- Open Terminal.app and go to the location of your .ipa file.
- Unzip the IPA file (they’re just zip files renamed to .ipa). This will leave you with a folder named “Payload”.
unzip AwesomeApp.ipa - Delete the
_CodeSignaturefrom within the .app bundle
rm -rf Payload/AwesomeApp.app/_CodeSignature - Replace the embedded.mobileprovision file with your own .mobileprovision profile
cp ~/Documents/MyOwn.mobileprovision Payload/AwesomeApp.app/embedded.mobileprovision - Use codesign to replace the existing signature using a certificate in your keychain to sign the app. In this example, I would need to have a certificate named “iPhone Distribution: Marcus Mattsson” under “My Certificates” in Keychain Access. When you run this command, you’ll be asked to allow codesign to access this certificate. Choose to “Allow” or “Always Allow”
/usr/bin/codesign -f -s "iPhone Distribution: Marcus Mattsson" --resource-rules Payload/AwesomeApp.app/ResourceRules.plist Payload/AwesomeApp.app
Note: You may get this error here: “object file format unrecognized, invalid, or unsuitable”. To fix this, run this in Terminalexport CODESIGN_ALLOCATE=/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/codesign_allocateand retry step 5. (The reason for this is that Mac OS X’s built-in codesign_allocate is out-dated) - The last thing you need to do is to zip that Payload folder back into an .ipa file. Do do that, just use the zip command
zip -r AwesomeApp_inhouse.ipa Payload
And there you go!