Xcode5打包静态库

今天研究了一下怎么打包静态库,从网上查了很多资料,但目前大多数都是说在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模拟器上运行的效果图如下:





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



  • 1
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值