Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
347 views
in Technique[技术] by (71.8m points)

ios - Get Bundle ID from a different target

In my Xcode project, I have 4 different schemes (prod, dev, staging, staging2) which changes the bundle identifier of the app that gets installed to the phone. That way I can have all 4 versions installed side by side, similar to this technique.

Now I'm building a Today Extension for iOS 8. It's a new Target requiring its own bundle identifier.

The Extension's Bundle Identifier must be prefixed with the Parent App's Bundle Identifier, or a warning is thrown:

error: Embedded binary's bundle identifier is not prefixed with the parent app's bundle identifier.

    Embedded Binary Bundle Identifier:  com.company.app.TodayExtension
    Parent App Bundle Identifier:       com.company.app.staging

In this case, the Embedded Binary Bundle Identifier must be com.company.app.staging.TodayExtension.

Is there a way I can configure my Today Extension target to set its bundle identifier by first looking at the Parent target's bundle identifier? Perhaps through a custom Run Script Build Phase?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

The build settings of the targets are not available for the other targets. However the build settings of the PROJECT are available.

You can thus add a user-defined build setting in your project and call it PARENT_APP_BUNDLE_IDENTIFIER and set the correct bundle id for all your schemes.

Then in the info tab of the app extension target set the bundle id to

$(PARENT_APP_BUNDLE_IDENTIFIER).$(PRODUCT_NAME:rfc1034identifier)

It worked perfectly fine for me.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...