iosxcodebundle-identifier

What configuration supports iOS bundle id auto-generation?


I downloaded the app's source code from here:

https://developer.apple.com/documentation/swiftui/fruta_building_a_feature-rich_app_with_swiftui

I opened it with Xcode 13.4.1 and select the Fruta iOS target, I found the bundle id is com.example.apple-samplecode.fruta

enter image description here

After switching the Team config to my Person Team (signed in with Apple ID), the bundle id is automatically switched to com.example.apple-samplecode.frutaBxxxxxxxxA (suddenly a suffix BxxxxxxxxA is added)

I would like to know what it is and how to achieve that for other projects.

I want to share the source code with my friends so they are able to sign with their own Personal Team and test the project on an actual device.


Solution

  • The build setting for PROJECT_BUNDLE_IDENTIFIER in this project looks like this:

    PRODUCT_BUNDLE_IDENTIFIER = "com.example.apple-samplecode.fruta${SAMPLE_CODE_DISAMBIGUATOR}";
    

    That variable is in turn defined in SampleCode.xcconfig:

    // The `SAMPLE_CODE_DISAMBIGUATOR` configuration is to make it easier to build
    // and run a sample code project. Once you set your project's development team,
    // you'll have a unique bundle identifier. This is because the bundle identifier
    // is derived based on the 'SAMPLE_CODE_DISAMBIGUATOR' value. Do not use this
    // approach in your own projects—it's only useful for sample code projects because
    // they are frequently downloaded and don't have a development team set.
    SAMPLE_CODE_DISAMBIGUATOR=${DEVELOPMENT_TEAM}
    

    You can get a similar behavior simply by editing a project and setting the PROJECT_BUNDLE_IDENTIFIER setting to something like com.example.my-example-app${DEVELOPMENT_TEAM}