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
381 views
in Technique[技术] by (71.8m points)

ios - How to add a framework inside another framework (Umbrella Framework)

I have build a framework using the following tutorial.

And I also got this framework.

I am trying to implement the second Framework inside mine, from what I read in the Apple docs the resulting framework is called "Umbrella Framework".

I added the second framework in framework using drag and drop and the verify that it is in the "Link Binary With Libraries".

And after I tried to make the next import in one of the classes of the my framework:

#import <CrashReporter/CrashReporter.h>

I received an error as the imported framework is not visible.

Also I have seen the stackoverflow post: How to create an umbrella framework in iOS SDK?

Update

Have anyone tried to extract the PLCrashReporter classes for iOS and integrate the in a project?

You can find my attempt here.

See Question&Answers more detail:os

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

1 Reply

0 votes
by (71.8m points)

The temptation to distribute another framework is understandable, but highly discouraged. I'll try to explain why that is (with arguments), and also provide some great alternatives that will help in your case.

Umbrella framework are intended for use, only when you are the distributor of both frameworks, you have full control over them, and they will be distributed together.

There is a popular quote on the topic from Apple, where they say that they discourage umbrella frameworks.

Don't Create Umbrella Frameworks

While it is possible to create umbrella frameworks using Xcode, doing so is unnecessary for most developers and is not recommended. Apple uses umbrella frameworks to mask some of the interdependencies between libraries in the operating system. In nearly all cases, you should be able to include your code in a single, standard framework bundle. Alternatively, if your code was sufficiently modular, you could create multiple frameworks, but in that case, the dependencies between modules would be minimal or nonexistent and should not warrant the creation of an umbrella for them.

First, here is what most developers do in this situation, since there are many frameworks out there that rely on others.

Inform the user that your framework requires the use of another third party framework. This is completely standard and expected in most cases. Then link to it at the system level. It's as simple as that. Your framework will find the third party and function seemlesly, just like using a native framework. Take UIKit for example. To link to the third party, follow the steps in the next section. It can certainly be done the standard way, but using a tool like CocoaPods will make your project easier to maintain.

To completely answer your question, instead of adding the third party framework the usual way, since you could run into problems and complications, use CocoaPods to add it for you. This way, you eliminate possible issues and also get the added benefit of CocoaPods getting you the exact version of the third party you will need.

Here is the CocoaPods Podfile for an app called "CrashTest"

target 'CrashTest' do
pod 'PLCrashReporter', '~> 1.2.0'
end

Just to clarify, when you are developing the framework, it will still be added to your project and visible. The big difference here is that it will be distributed separately from your framework, and end users will have to add both to their projects in order to make things work.

Here are the reasons why this is done this way.

For example, you would like to include PLCrashReporter in your framework. Say another framework vendor wants to include it in theirs as well. The application using both frameworks will have PLCrashReporter included twice (as part of each umbrella framework). Possible even different versions of it. This could lead to serious issues inside of the user application. If both umbrella frameworks are linking to PLCrashReporter, as described in the previous section, this issue would be avoided completely.

Another point, which I touched on above is versioning. When distributing an umbrella framework, you need to be able to control the versions of all frameworks involved, and you have no control over the third party framework. Which would again lead to a similar problem as the one described above.

I know that this approach does not provide a direct answer to the question, but it's trying to discourage a bad practice instead, while pointing the industry standard way of doing things.


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

...