Building for the simulator is easy. Building for the device, however, can be troublesome, especially when using version control to share your code with other developers.
Often times, the project.pbxproj file ends up with settings that disable Xcode from building your application for the device. Here is a common and frustrating error:
CodeSign error: a valid provisioning profile is required for product type ‘Application’ in SDK ‘Device – iPhone OS 2.1′
That is not a helpful error message. In my experience, I can change the settings in the “Get Info” window to exactly what they should be without it fixing the problem. Here’s how I hack my project.pbxproj to avoid that problem:
Opening the project.pbxproj file in vim (vim – oh, how I’ve missed you!), I search for “Debug” and find:
1D6012340D05DD3E126BFB12 /* Debug */ = {
isa = XCBuildConfiguration;
buildSettings = {
ALWAYS_SEARCH_USER_PATHS = NO;
CODE_SIGN_IDENTITY = "iPhone Developer: Josh Stephenson";
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer: Josh Stephenson";
COPY_PHASE_STRIP = NO;
GCC_DYNAMIC_NO_PIC = NO;
GCC_OPTIMIZATION_LEVEL = 0;
GCC_PRECOMPILE_PREFIX_HEADER = YES;
GCC_PREFIX_HEADER = Sample_Prefix.pch;
INFOPLIST_FILE = Info.plist;
PRODUCT_NAME = Sample;
PROVISIONING_PROFILE = BIG LONG GUID HERE;
};
name = Debug;
};
Delete the PROVISIONING_PROFILE line completely.
Searching for Debug again, I found:
C01FCF4F08A954540054247B /* Debug */ = {
isa = XCBuildConfiguration;
buildSettings = {
ARCHS = "$(ARCHS_STANDARD_32_BIT)";
CODE_SIGN_IDENTITY = "iPhone Developer: Josh Stephenson";
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer: Josh Stephenson";
GCC_C_LANGUAGE_STANDARD = c99;
GCC_WARN_ABOUT_RETURN_TYPE = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
HEADER_SEARCH_PATHS = /usr/include/libxml2;
ONLY_ACTIVE_ARCH = YES;
OTHER_LDFLAGS = "-lxml2";
PREBINDING = NO;
PROVISIONING_PROFILE = BIG LONG GUID HERE;
"PROVISIONING_PROFILE[sdk=iphoneos*]" = BIG LONG GUID HERE;
SDKROOT = iphoneos2.0;
};
name = Debug;
};
Delete both of the lines.
Now, save the file and go back to Xcode. Click “Read from Disk”:
At this point, everything in your “Get Info” window looks the same, but everything behind the interface is right:
That should do it.