Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

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

objective c - CocoaPods/Podspec and *.framework

CocoaPods question:

I have created a framework bundled with a static library inside, depending on AFNetworking and a resource bundle (based on those two tutorials to create FWKs http://www.blackjaguarstudios.com/blog/programming/2012/11/22/xcode-45-creating-ios-framework-and-hold-my-hand-im-3-years-old and https://github.com/bclubb/iOS-Framework)

I'd love to create a podspec so that people just add a line in their Podfile, which would, on pod install, add my framework and the AFNetworking, if needed.

Is this possible?

See Question&Answers more detail:os

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

1 Answer

0 votes
by (71.8m points)

I have actually done this a lot at my office. We have tons of private source code that is re-used quite a bit. CocoaPods has helped get new projects started much quicker and makes them a whole lot easier to update.

While it is possible to add your framework to the podspec, I have found it much easier to just pass the static library and headers over via CocoaPods rather than worry about the framework.

You will have to update your podspec based on your project, but here are the important parts:

s.source_files = 'StaticLib/Headers/*.h'
s.preserve_paths = 'StaticLib/libYourLibrary.a'
s.library = 'YourLibrary'
s.xcconfig = { 'LIBRARY_SEARCH_PATHS' => '$(PODS_ROOT)/ProjectFolder/LibraryFolder' }    

s.dependency = 'AFNetworking'

This will copy your static library over as well as bring over AFNetworking with your pod too. This will make your static lib much smaller (not having to build it in) and speed up how quickly the user can import your pod.

If you must use framework, the same stuff from above still applies, but you might have some slight tweaking to do. All a framework is is a pretty folder structure for a static lib and headers anyway, so why bother with the extra stuff. The source is all still built into the lPods.a static lib anyway. Hope this helps you out.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

2.1m questions

2.1m answers

60 comments

56.8k users

...