浅析SuperMap iMobile 8C for iOS打包静态库

来源:互联网 发布:淘宝50字万能好评 编辑:程序博客网 时间:2024/06/03 00:48

作者:为梦齐舞

      近段时间,有客户咨询如何将超图的库打包成静态库,然后到项目中进行使用,在这里小编做一个简单的介绍,本文中将介绍如何打包静态库,并在也使用超图的库进行调用静态库。
      一、新建静态库工程Cocoa Touch Static Library
这里写图片描述
      二、命名工程为supermapLib
这里写图片描述
      三、设置Search Paths路径
        1、设置头文件路径Header Search Paths:安装目录/SDKs/iPhoneOS.sdk/SuperMap.framework/Versions/A/Headers
        2、设置动态库路径Library Search Paths:安装目录/SDKs/iPhoneOS.sdk/SuperMap.framework/Versions/A

      四、在静态库工程中编写代码
            1、supermapLib.h文件中

#import <Foundation/Foundation.h>@class Workspace;@interface supermapLib : NSObject{    Workspace *workspace;}-(Workspace*)openWorkspace;@end

            2、supermapLib.m文件中

#import "supermapLib.h"#import "SuperMap.h"@implementation supermapLib-(Workspace*)openWorkspace{    @try    {        workspace=[[Workspace alloc]init];        DatasourceConnectionInfo *info=[[DatasourceConnectionInfo alloc]init];        info.engineType=ET_BAIDU;        info.server=@"http://map.baidu.com";        [workspace.datasources open:info];        return workspace;    }    @catch (NSException *exception) {    }}@end

      五、编译工程,会生成一个libsupermaplib.a的静态库包和include头文件。
这里写图片描述
      六、新建一个Single View Application工程来测试静态库,命名为SmLibTest,按照SuperMap要求的工程配置进行配置,添加libstdc++.6.0.9.tbd库;其中SuperMap.framework不需要再添加到工程中,SuperMap.bundle资源依然需要放置到工程中。
      七、将libsupermaplib静态库include头文件以及SuperMap的头文件加入到工程中。
这里写图片描述
      八、将生成的libsupermaplib.a的静态库加入到工程中,并拖拽到工程中。
这里写图片描述
      九、在SmLibTest中添加如下代码
            1、ViewController.h文件中

#import <UIKit/UIKit.h>#import <SuperMap.h>@interface ViewController : UIViewController@property (strong, nonatomic) IBOutlet MapControl *mapControl;@end 

            2、ViewController.m文件中

#import "ViewController.h"#import "supermapLib.h"@implementation ViewController@synthesize mapControl;- (void)viewDidLoad {    [super viewDidLoad];    [self openMap];    // Do any additional setup after loading the view, typically from a nib.}-(void)openMap{    mapControl=[[MapControl alloc]initWithFrame:[[UIScreen mainScreen]bounds]];    [self.view addSubview:mapControl];    [mapControl mapControlInit];    supermapLib *superlib=[[supermapLib alloc]init];    Workspace *workspace=[superlib openWorkspace];    [mapControl.map setWorkspace:workspace];    Datasource* baiduDatasource=[workspace.datasources get:0];    [mapControl.map.layers addDataset:[baiduDatasource.datasets get:0] ToHead:NO];  }

      十、编译运行程序,效果如下图所示
这里写图片描述

1 0
原创粉丝点击