Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iOS extensions with multiple targets

In iOS 8, when we create an app extension, we have to decide which target it is attached to. The extension will have the same bundle ID's prefix as the target.

  1. Is there any way to change the target afterward?
  2. If my project contains 2 (or more) targets (for example one for debug/simulator, one for production/device), what's the best way to work with extensions? Do I need to create another extension and duplicate the code (very bothersome to keep the same code for both targets)?
like image 207
Enzo Tran Avatar asked Aug 20 '14 07:08

Enzo Tran


People also ask

How do I set up target membership Xcode?

You can access Target Membership by selecting file and opening the right menu in Xcode (the menu is called Inspectors ). Then, in File Inspector at the bottom of the menu, find Target Membership . It's very important to check all files in your project because without this you won't be able to build a new app target.

What is iOS development target?

iOS Deployment Target(IPHONEOS_DEPLOYMENT_TARGET) Deployment Target is a minimum version of iOS which is supported by your target. It means that: as a developer you support this version and you are able to support all next compatibility. as a user you should have at least this version of iOS.

What is target in iOS Xcode?

A Target specifies a product to build and contains the instructions for building the product from a set of files in a project or workspace. An Xcode scheme defines a collection of targets to build, a configuration to use when building, and a collection of tests to execute.


2 Answers

To share one widget with others targets, you only need to add widget.appex target to Embedded Binaries for every parent target in General configuration tab

enter image description here

Then you'll get Embed App Extensions area at Build Phases automatically

enter image description here

like image 149
malex Avatar answered Sep 23 '22 22:09

malex


This is my setup: I have 3 targets (production, staging, local) and an extension target that I don't want to duplicate 3 times.

Just to clarify Neo Chen's answer, edit each of your parent targets' schemes:

Build > Pre-actions > New Run Script Action > Provide build settings from (parent scheme).

Paste this for each extension:

#!/bin/bash  buildID=${PRODUCT_BUNDLE_IDENTIFIER} extId="notification-service"  /usr/libexec/PlistBuddy -c "Set :CFBundleIdentifier $buildID.$extId" "${SRCROOT}/${extId}/Info.plist" 

Seems to work on first build.

like image 45
apparition47 Avatar answered Sep 23 '22 22:09

apparition47