User-Defined settings for WatchKit - ios

I am using User-Defined settings (for example CustomAppBundleId) to change bundle identifier for different configurations. In the app’s plist file I set CFBundleIdentifier to ${CustomAppBundleId}. For Release configuration I use bundle:
com.yourcompany.${PRODUCT_NAME:rfc1034identifier}
and for AdHoc I use:
com.yourcompany.adhoc.${PRODUCT_NAME:rfc1034identifier}
Now I added WatchKit Extension and WatchKit App. For WatchKit Extension bundle identifier I can use the same approach. I also have to change WKAppBundleIdentifier to match the bundle identifier in the WatchKit App. Again, I could use User-Defined settings. Now the last bit is WatchKit App. Unfortunately WatchKit App doesn’t have an option to add User-Defined settings but I need to set the right values for CFBundleIdentifier and WKCompanionAppBundleIdentifier (that is equal to CustomAppBundleId in the app). Is there any way I can do it? Or should I use different approach?

Define your "User-Defined" variables in project's Build Settings rather than in target's. That way you will have the same user defined variables automatically available (inherited) in WatchKit Extension and App target.
Btw make sure you have the latest Xcode 6.3 from the App Store. This version (and most recent Xcode 6.3 beta 4) already allow you to define custom "User-Defined" in Build Settings).
Previous versions were simply missing "Build Settings" tab in WatchKit App target, but if you were brave enough, you could have modify those manually in plain text editor :-)

Update to Xcode 6.3.
In 6.3 you will have additional tabs for target configuration that should provide what you need.
But I'm almost sure you will face issues with the WatchKit App Storyboard.
In the Scenes > Identity Inspector > Custom Class you have to set the correct module - that is not possible if you have more than 1 (if you do not have more than one I would be more than interested in your setup)
I solved that issue with a pre-action script that updates the storyboard XML accordingly

Related

No complication configuration in xcode for watchOS 9

I added a new watch app for an existing iOS App that is build with react native. I never developed a watch app before. I read everywhere that this should create two targets, the watch App and the App extension. But only a watch app gets created.
Now I want to add a complication for this watch app. I tried to follow the steps here and here. It says that on the general tab of the extension (which is not present in my project) I should configure the Complication Configuration. But this option is just not present.
Was this changed with watchOS 9 or am I missing something else?
I’m having a similar issue after creating a watchOS app in Xcode 13 without an initial complication. Fortunately, I was able to work around the missing configuration UI by manually setting the values.
Assuming you’ve followed these steps of creating the ComplicationController class and “Complication” placeholder in Assets,
Go to Project -> watch app target -> Build Settings
Set “Complication Principal Class” to $(PRODUCT_MODULE_NAME).ComplicationController under Info.plist Values
Set “Watch Complication Name” to Complication under Asset Catalog Compiler - Options

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.

iOS PRODUCT_NAME not the display and wrapper name

For my iOS app I am trying to have multiple build configurations so I can create development and production builds that target different servers, configurations etc.
In Xcode I have created another build configuration and scheme to target this configuration. So I have the separate configuration/schemes as:
Dev version
PRODUCT_NAME=MyApp-dev
BUNDLE_IDENTIFIER=com.organisation.myapp-dev
Original Version
PRODUCT_NAME=MyApp
BUNDLE_IDENTIFIER=com.organisation.myapp
Both configurations can be built with the different schemes. Both will run on the same device because of the different identifier, but the dev version still shows MyApp on the home screen. When looking in the build products, it produces a MyApp.app bundle with a target inside it of MyApp-dev.
Is there another setting to change the wrapper name from MyApp.app to MyApp-dev.app? And any other setting that may be preventing PRODUCT_NAME setting to be used in the app display name?
edit: In the info.plist file, both the CFBundleName and CFBundleDisplayName are set to $(PRODUCT_NAME)
n.b. I have done this before with another app and all is working fine there, hence the query if another developer has changed a more targeted setting that overrides this change.
There was a InfoPlist.strings file in the project that was overriding CFBundleDisplayName. I removed this definition from this file and all worked as desired.
The project is not localised and so I never considered this override! Hopefully if someone else comes across this, remember settings in Info.plist can be overriden with localised strings in this file.

Watch kit CFBundleVersion

Planning for watch kit integration
error: The value of CFBundleVersion in your WatchKit app's Info.plist (1) does not match the value in your companion app's Info.plist (2.0). These values are required to match.
Struck with above error.
- changed the deployment targets of both notification & watchkit app. But build failed
Thanks.
You need to make sure that the CFBundleVersion in the Info.plist of your WatchKit App is identical to the CFBundleVersion in your parent app’s Info.plist.
For those of you who struggling with adapting your build autonumbering scripts (like this one) to WatchKit and getting the same dreaded The value of CFBundleVersion in your WatchKit app's Info.plist ... does not match the value in your companion app's Info.plist ... error, here is the solution: set Strip Debug Symbols During Copy to No for the project, remove same option overrides for all targets, make clean (Cmd+Shift+K) and build (Cmd+B).
Disclaimer: this is more hack than a solution, I don't know why it works, but it's the only way I got my autonumbering script working with WatchKit and I think this information would be useful for someone. If you have better ideas, please share.
Update: finally found a real solution. Turns out even without UI one could easily add a run script to WatchKit App target by manually editing project.pbxproj. Thank you, Curtis Herbert!
error: The value of CFBundleVersion in your WatchKit app's Info.plist (14) does not match the value in your companion app's Info.plist (13). These values are required to match.
I finally figured out the problem is the value of my companion app 's Info.plist which equals to 13, is not equal to that value in WatchKit App.
So you have to make sure that the Bundle version panel 's value in each Info.plist is matched.
After installing WatchKit application extension.There was conflict in
Bundle versions string, short && Bundle version .
So Update both of Keys to values which are equals in both the Extension and main app targets in info.plist file .
&&
When ever you get such problems after updating build number or version. Please follow the steps, which worked for me :
Clean the project
Try to run the project in any one of the simulators
Build or Archive
welcome to the party. I was able to work through this by editing the Info.plist ion both Watchkit App and Watchkit Extension, and then editing the marketing version in the AppName(root level)/Targets/AppName/Versioning/Marketing Version.
Hope this helps anyone else that comes across this issue.
I got this error when I create new target watch kit with different team selected by default while creating the watch app for ios app so i just deleted the targets and again add with same team as my project.

iOS - Share a Today Extension with multiple app targets?

I have a project with multiple app targets (about 25).
I'm going to make a Today Extension for those apps but I don't want to create about 25 extensions with the same code and configuration.
Is it possible to create only one Today Extension that I assign to the 25 apps ?
It is possible, but with some manipulations. To connect extension with a target you need:
Add your extension to target's embedded binaries ("General" tab of project's settings)
Add extension's target to target dependencies ("Build Phases" tab of project's settings)
Prefix your extension's bundle identifier with the parent app's (your current target) bundle identifier or you will get an error:
So when you will build or distribute your target make this manipulations and fix provisioning profile's issues with Xcode (it can do this automatically).

Resources