Xcode5打包静态库
今天研究了一下怎么打包静态库,从网上查了很多资料,但目前大多数都是说在Xcode4上怎么打包静态库的,所以今天我用Xcode5打包了静态库,其实都差不多呢。
打包的步骤如下:
1、创建一个静态库项目,如下图:
2、在这个项目中我创建了一个UIViewController类,上面就一个UIWebView,加载百度的地址,代码如下:
WebViewController.h文件
- #import<UIKit/UIKit.h>
- @interfaceWebViewController:UIViewController<UIWebViewDelegate>
- @end
WebViewController.m文件
- #import"WebViewController.h"
- #defineCURRENT_DEVICE_SYSTEMVERSION[[UIDevicecurrentDevice]systemVersion]
- #defineiOS7_VERSIONS_LATTER([CURRENT_DEVICE_SYSTEMVERSIONfloatValue]>=7.0)
- @interfaceWebViewController()
- @property(nonatomic,retain)UIWebView*webView;
- @end
- @implementationWebViewController
- -(id)initWithNibName:(NSString*)nibNameOrNilbundle:(NSBundle*)nibBundleOrNil
- {
- self=[superinitWithNibName:nibNameOrNilbundle:nibBundleOrNil];
- if(self){
- //Custominitialization
- }
- returnself;
- }
- -(void)viewDidLoad
- {
- [superviewDidLoad];
- if(iOS7_VERSIONS_LATTER){
- [selfsetNeedsStatusBarAppearanceUpdate];
- self.edgesForExtendedLayout=UIRectEdgeBottom;
- self.extendedLayoutIncludesOpaqueBars=NO;
- self.automaticallyAdjustsScrollViewInsets=NO;
- }
- self.webView=[[[UIWebViewalloc]initWithFrame:self.view.frame]autorelease];
- self.webView.delegate=self;
- [self.viewaddSubview:self.webView];
- [selfloadWebPageWithString:@"http://www.baidu.com"];
- }
- -(void)didReceiveMemoryWarning
- {
- [superdidReceiveMemoryWarning];
- //Disposeofanyresourcesthatcanberecreated.
- }
- -(void)dealloc
- {
- self.webView=nil;
- [superdealloc];
- }
- -(void)loadWebPageWithString:(NSString*)urlString
- {
- NSURL*url=[NSURLURLWithString:urlString];
- NSLog(@"%@",urlString);
- NSURLRequest*request=[NSURLRequestrequestWithURL:url];
- [self.webViewloadRequest:request];
- }
3、如果你的这个静态库是给其他developer用,你就给他们Release版本的,在Edit Scheme中设置,如下图:
4、静态库的制作方法可分为两种:第一种为在真机上使用的静态库,第二种为在模拟器中使用的静态库。他们的区别如下:
当制作在真机上使用的静态库时,选择iOS Device,编译,你会得到一个支持真机的静态库。
右击Products目录下的libWebViewSDK.a文件open in finder,找到这个文件所在的目录,选择Release-iphoneos目录下的libWebViewSDK.a文件。
当制作在模拟器上运行的静态库时,选择iPhone Simulator,编译,你会得到一个支持模拟器的静态库。
右击Products目录下的libWebViewSDK.a文件open
in finder,找到这个文件所在的目录,选择Release-iphoneosimulator目录下的libWebViewSDK.a文件。
5、静态库的使用
把此静态库和此库中必要的头文件加到你要使用此库的项目中,如我建立了一个WebImageTest的项目,然后我把相应的静态库libWebViewSDK.a(真机版或模拟器版的)和前面写的WebViewController.h文件加入到此项目中
调用此静态库的代码如下:
- -(BOOL)application:(UIApplication*)applicationdidFinishLaunchingWithOptions:(NSDictionary*)launchOptions
- {
- self.window=[[UIWindowalloc]initWithFrame:[[UIScreenmainScreen]bounds]];
- //Overridepointforcustomizationafterapplicationlaunch.
- WebViewController*webVC=[[WebViewControlleralloc]init];
- self.window.rootViewController=webVC;
- [webVCrelease];
- self.window.backgroundColor=[UIColorwhiteColor];
- [self.windowmakeKeyAndVisible];
- returnYES;
- }