iOS - Share a Today Extension with multiple app targets? - ios

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

Related

Pass build settings from app target to dependency

In my project, I have two apps and one share extension. The share extension should be embedded in both apps, but with slight differences between the apps (different bundle ID and some settings in the Info.plist).
Is there a way to tell which app is being build during the build of the extension (so I can change those values accordingly)? Or maybe a way to "pass" build settings from the app target to the extension target during build?
I was already trying to change those plist values after the extension has been built and before embedding it into the app, but that messes with code signing...

Apple Watch for Multiple target

I have multiple target in my App like QA,Release,Develop and i want to create watch app for all targets I have already added watch app for QA target and my question is How can i use same classes and storyboard for other targets e.g Release and Develop.
Thanks
You should create a Framework, in which you include all classes and files that you need to access from each target and then include the framework in your targets. Embedding Frameworks in an app
I think a watch app target can only have one companion iOS application. Different target (QA, Release, Develop) means different bundle ID. Watch target bundle ID has to match companion app's bundle ID as its prefix.
For example, com.xxx.yyy.watchkitapp has to have an iOS companion with com.xxx.yyy. Therefore I think it's impossible.
However, if your code base for all targets are roughly the same you can have single target with multiple build Configurations.
Inside Build Settings for the single target, you can set different flags for Preprocessor Macros.
In code, you can do something like this to differentiate each build configuration.
#if QA
// enable QA feature
#elseif RELESE
// disable beta features
#else
// enable everything
#endif

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

Error: WatchKit Extension doesn't contain any WatchKit apps.

Verify that the value of WKWatchKitApp in your WatchKit App's Info.plist is set to YES.
After weeks and weeks of investigations i finally found out the problem.
The product name of the Iphone App was the same as the product name of the Watch App.
Once i changed the Product Name of the WatchApp it worked.
go to your targets. Select the watch app target
go to build settings. Search for Product Name
Edit your Product name to be different than the App Target!
Clean and Build. Should Work. Thanks
It seems like this is the default error msg for random stuff on Xcode 7.
All of a sudden I got that error constantly when trying to Archive.
After retracing my steps I've learned that changing the Build Location to Custom - > Relative to WorkSpace is responsible for that error: WatchKit Extension doesn't contain any WatchKit apps..
Setting the Build Location back to Shared Folder -> Build fixed it completely.

User-Defined settings for WatchKit

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

Resources