How do I make an iOS app's Build Identifier dynamic? - ios

I am working on some Swift code with my children. We would like to work from a shared codebase, so that we can each grab the code, then build and install the app onto our phones.
When I grab the source code my daughter wrote, I get the errors:
The app ID "com.example.OurApp" cannot be registered to your development team. Change your bundle identifier to a unique string to try again.
and:
Xcode couldn't find a provisioning profile matching 'com.example.OurApp'.
If I change the Bundle Identifier value in XCode to something globally unique, everything works. But I don't want to do that because then it is confusing what changes should be committed and/or shared.
The Bundle Identifier value seems to be statically attached to the project files, and those project files need to be checked into to source control, which means that we have to manually muck with that value before we can build and sign our app so that we can run it on our phone.
We each have a developer account that gives us the ability to sign an ipa with our certs, which allows us to install builds on our phone.
I think I want to make the Bundle Identifier dynamic based on the machine or user that is building it.
I think I want to type com.myfamily.$(SOME_ENV_VARIABLE).OurApp into the Bundle Identifier box in XCode, and then commit that file so that any of us can just grab the code, mess with the code, then install the signed ipa on our phone without changing any of the XCode project file values.
No matter what I type into the "Bundle Identifier" box in XCode, the resulting value in the plist within Build/Products/.../Info.plist is garbage. Even changing some .swift files causes this plist to change to some junk value.
How do I make it so that I can share an XCode project with my family such that we can each sign and run the app, without changing or git-ignoring any of the project files/plists?
We are using XCode 8.3.x and running iOS 10.

Related

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
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.
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}

Renaming an Xcode project for an existing AppStore app

I'm in the process of "rebranding" an existing app of mine, which has been on the App Store for 3 years.
This includes a new app name which should be reflected in the whole Xcode project as well.
The rebranded app should roll out as an update for all existing installations.
I've successfully followed the instructions given here:
How do I completely rename an Xcode project (i.e. inclusive of folders)?
(Additionally, I've changed the bundle name in the info.plist.)
with one exception: Changing the product bundle identifier in the build settings. I guess that's the only place I have to keep the old name so that AppStoreConnect realises this actually is the old app?
Is that so, if not, which is the setting that is needed to identify this as the old app?
Your app is identified using the Bundle Identifier only. You should not modify it. You can change almost everything else.
Note that you cannot reset the Version and Build numbers back to 1 and their values should be greater than the last numbers you used to submit your app.

How to make an extension work for several app targets?

I have an iOS App target, open to everyone for the public store, all fine.
And I have 2 extensions with it in the project, including the bundle identifier in their identifier of that iOS App target.
Now I duplicated the first App target, added some changes, etc for B2B & MDM usage, but I want to use the same extensions, without having to change their bundle identifiers each time I change the build target, and I don't want to duplicate them as well with different bundle identifiers as well, if that is avoidable.
Visual example:
Basically I want to avoid delivering the code of the second target to the users of the first target, because after all, it is the minority who needs those changes.
I tried it with App groups, but that doesn't seem to help in any way.
Is there a way to make the extensions work for both App targets?
There are these option to you:
1.
You can duplicate the extensions, provide id from your developer portal, or let Xcode add them itself, and change the target identifiers to your new target.
2.
The other way is, to change the extensions bundle ids on build actions of the scheme to your currently required ones.
This could look somewhat like this, if you want to use PlistBuddy:
/usr/libexec/PlistBuddy -c "Set :CFBundleIdentifier fullBundleIdOfExtension" $PROJECT_DIR/Extension\ Directory/Info.plist
fullBundleIdOfExtension is something like com.company.application.extension
This way could cause errors sometimes on the build after a target switch, showing a dialog that the App could not be installed. This requires you to perform a clean build and rebuild.

Xcode: sharing the same Bundle ID among multiple people

I'm developing an iOS app with a friend. We both enrolled for the Apple development program as a Single person (we don't have an organization).
We're using git and we'd like to be both able to build the app from our Mac, but I can't compile sinche the Bundle ID is already used by my friend. Is it even possible to be both able to work on the same project without being an organization? What we should do?
Thanks
The problem is that only one developer account can register the bundle ID. What Xcode is trying to do is register the bundle ID to your development account (as you can do manually at https://developer.apple.com). Since your friend already did this, you cannot do this as well.
What you can do is either change the value of your bundle ID to a development one (in the end, only one of you can release the app on the App Store) however, this is kind of messy since it'll change the .xcodeproj and can be a real conflict mess when using versioning (as I guess you are using).
Another option is to use .xcconfig files, and define the bundle ID dynamically in your project. This way you can change your config file locally and just don't push that change. What you do is:
Add a new file to your project. Select Other under iOS and then select Configuration Settings File. Save the file and call it Debug.xcconfig (or whatever you want).
Add the following row to the file: BUNDLE_ID = io.example.app.
Select your project in the Project Navigator and then select the project itself under PROJECT.
Select the Info tab and expand both Debug and Release. For both Debug and Release select the Debug option.
Now open your Info.plist file and change the value of Bundle Identifier (CFBundleIdentifier) to $(BUNDLE_ID).
Now you can change the bundle ID (and a shitload of other Xcode project properties) using the configuration file. You could add one for yourself and your friend as well, each with their own bundle ID.
One problem though when changing the BundleID is that services such as APNS won't work. Keep that in mind. If that is important that both should be able to test, then make sure to get an organisation account.
Hope this helped you a little bit!

How to deal with App ids when contributing to iOS open source projects

I want to make some changes to an open source iOS project. The problem is when I try to use my provisioning profile to build and run the app on my device, Xcode 7 complains: An App ID with Identifier 'com.whoisryannystrom.hackernews' is not available. Please enter a different string.
The app is published and the bundle identifier is reserved by another team that is clear. I see the only way to solve this is to change the identifier, commit that change, and later before making pull request revert that commit.
Is there any better way of dealing with the bundle identifier for open source projects?

Resources