What configuration supports iOS bundle id auto-generation? - ios

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}

Related

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.

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

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.

How to configure Bundle ID for iOS Framework targets for App and Appex

There is a KeyboardKit (Swift 3) iOS Framework which I recently decided to separate into two targets KeyboardKit and KeyboardKitAppex. The former will be used within the Application target, the latter within Application Extension target respectively.
To do so, I just duplicated KeyboardKit target, renamed the duppy to KeyboardKitAppex and changed these build settings:
Require Only App-Extension-Safe API set to Yes;
Other Swift Flags is set to -D APP_EXTENSION.
Basically, I have copied this setup from mixpanel-swift. However, mixpanel managed to have the same Bundle ID in the build configuration for all targets. It is somehow replaced with unique Bundle ID during the build stage, and I'd like to know, "how?".
In my framework targets, I had to manually edit the Bundle ID to be unique per target. Otherwise, the app cannot be installed on device, complaining about Bundle ID not being unique among embedded bundles.
How to properly separate an iOS Framework into two targets with less hardcoded configuration (specifically, Bundle ID)?
My current Setup is the following:
KeyboardKit
KeyboardKitAppex
...comparing this with mixpanel-siwft setup:
Mixpanel
MixpanelAppex

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!

Can't change bundle ID in project, greyed out

I'm having a problem with bundle identifiers. In the Summary section of my project in Xcode and under 'Identifiers', I can't seem to change the name of my bundle ID as it is greyed out. For example, my project name is 'My App'. In the identifier text box in Summary, it says this 'My-App' and is greyed out. However, my bundle id in my provisioning profile is this, 'com.mycompany.myapp'. I would like to change my bundle ID in my project to that but I can't seem to be able to. Any ideas why it is greyed out? Thanks!
If anybody else runs into this, it is likely because you have a product name variable, something like .${PRODUCT_NAME:rfc1034identifier}, appended to the end of your bundle identifier under Target (your application) > Info (info.plist). Try removing that.
Not sure why this is happening to you, but try to change in the info.plist file.
Go to info.plist file
Go to Bundle Identifier key-value pair
Remove .${PRODUCT_NAME:rfc1034identifier} from the value and save the file
Your bundle identifier has been modified as required.
If you want to edit the Product Name, rather than remove it; you can set it in your target, using the following steps:
Open the Target in XCode
Go to the Build Settings tab
Scroll down to Packaging->Product Name
The name set in Product Name is added to the Bundle Identifier (spaces are changed to dashes e.g "Test App" becomes "Test-App").
You may want to consider changing the value of PRODUCT_NAME instead of directly changing the bundle identifier. This can be done thru the XCODE interface (and should have the added benefit of not possibly causing problems with certificates and code signing later on...which can be a real bear to resolve):
Click here to see stackoverflow thread for detailed instructions on how to do this thru XCode interface
With Xcode 14.x
Just press the arrow beside the bundle identifier field, it will jump to Signing & Capabilities, here you can edit bundle id.
Steps:
Select Project and then click Target
Under General scroll to Identity section
Click arrow beside bundle id
Edit the bundle id (it will be reflected in Identity section)
It may be that it's set in a .xcconfig file instead. For example, one Parse sample project has a 'debug.xcconfig' with:
BUNDLE_IDENTIFIER = com.parse.Anypic
If so, this is the place to change it.
I saw this also happen when the iOS Deployment Target is higher than your version of Xcode supports. Between World Wide Developers Christmas when they release the betas and when the new version is finalized.
So say you have a project with a min deployment for the current iOS beta version, but you are using the release version of Xcode. Just open the project in the current Xcode beta version.
This can also be related to user defined variables under [Target] > Build Settings > User-Defined

Resources