Xcode5打包静态库

来源:互联网 发布:淘宝商城百度 编辑:程序博客网 时间:2024/05/16 07:00

今天研究了一下怎么打包静态库,从网上查了很多资料,但目前大多数都是说在Xcode4上怎么打包静态库的,所以今天我用Xcode5打包了静态库,其实都差不多呢。

打包的步骤如下:

1、创建一个静态库项目,如下图:


2、在这个项目中我创建了一个UIViewController类,上面就一个UIWebView,加载百度的地址,代码如下:

WebViewController.h文件

#import <UIKit/UIKit.h>@interface WebViewController : UIViewController<UIWebViewDelegate>@end

WebViewController.m文件 

#import "WebViewController.h"#define CURRENT_DEVICE_SYSTEMVERSION [[UIDevice currentDevice] systemVersion]#define iOS7_VERSIONS_LATTER ([CURRENT_DEVICE_SYSTEMVERSION floatValue] >= 7.0)@interface WebViewController ()    @property (nonatomic, retain) UIWebView *webView;    @end@implementation WebViewController- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil{    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];    if (self) {        // Custom initialization    }    return self;}- (void)viewDidLoad{    [super viewDidLoad];    if (iOS7_VERSIONS_LATTER) {        [self setNeedsStatusBarAppearanceUpdate];        self.edgesForExtendedLayout = UIRectEdgeBottom;        self.extendedLayoutIncludesOpaqueBars = NO;        self.automaticallyAdjustsScrollViewInsets = NO;    }        self.webView = [[[UIWebView alloc] initWithFrame:self.view.frame] autorelease];    self.webView.delegate = self;    [self.view addSubview:self.webView];    [self loadWebPageWithString:@"http://www.baidu.com"];}- (void)didReceiveMemoryWarning{    [super didReceiveMemoryWarning];    // Dispose of any resources that can be recreated.}    - (void)dealloc{    self.webView = nil;    [super dealloc];}    - (void)loadWebPageWithString:(NSString*)urlString{    NSURL *url =[NSURL URLWithString:urlString];    NSLog(@"%@",urlString);    NSURLRequest *request =[NSURLRequest requestWithURL:url];    [self.webView loadRequest: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 *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions{    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];    // Override point for customization after application launch.    WebViewController *webVC = [[WebViewController alloc] init];    self.window.rootViewController = webVC;    [webVC release];    self.window.backgroundColor = [UIColor whiteColor];    [self.window makeKeyAndVisible];    return YES;}
在ios7模拟器上运行的效果图如下:





这个效果图好像太白了点啊。。。。



原创粉丝点击