SuperMap iMobile for iOS 入门&数据部署

xiaoxiao2021-02-27  509

      数据是GIS 应用的基础,与所有GIS 应用一样,使用SuperMap iMobile for iOS 开发的应用也离不开数 据。而且iOS 应用是在移动终端上运行,数据需要通过数据线连接,通过iTunes 拷贝,操作比较繁琐。 其实可以将数据打包添加到工程中,在程序启动时将其一同部署。       本文在iMobile for iOS 的产品入门工程的基础上,介绍在代码工程中添加数据并部署到移动终端的方法 ——借助bundle,将数据打成bundle 包,添加到工程。若应用中不编辑数据,则代码中直接使用bundle 中的数据即可;若要编辑数据,则在应用启动时将bundle 中的数据拷贝至应用的Document 目录。通过代 码部署数据的方式,使得应用部署的同时数据也一同部署,不需要再单独拷贝。 新建工程       按SuperMap iMobile for iOS 帮助文档中开发入门的操作步骤,以二维移动GIS 应用程序开发为例,基于模 板的工程完成前两步,如图 1,完成新建工程及代码编写。完成后工程目录如图 2 所示。 准备数据       入门工程用到的示范数据位于【SuperMap iMobile 7C for iOS 解压目录】\SampleData\World 目录,入门示范 中,传入数据到真机需要借助iTunes,本文将跳过此步骤,利用捆绑包将数据添加到工程中,并在程序启 动时部署到移动设备上。       首先,在Mac 系统中,新建一个文件夹Data,将SampleData\World 目录下的World.smuw、World.udb 和 World.udb 文件拷贝至Data 目录中,许可文件也可以拷贝至Data 目录,如图 3 所示。       重命名Data 目录,添加后缀.bundle,会弹出消息框,确认添加bundle 后缀,单击“添加”,添加后Data.bundle 就显示为了一个单文件,如图 6 所示。       按住Data.bundle 拖拽,将其添加到工程中,见图 7。在Finder 中看,Data.bundle 是一个单独的文件,在 Xcode 中,则可以展开它看到其内容,见图 8。 拷贝数据       代码中将Data.bundle 中的文件拷贝至应用的Document 目录:在ViewController.m 中增加copyDataFile 方 法,在viewDidLoad 方法中增加调用。

-(void)viewDidLoad { [super viewDidLoad]; [self copyDataFile:@"World.smwu"]; [self copyDataFile:@"World.udb"]; [self copyDataFile:@"World.udd"]; [self copyDataFile:@"SuperMap iMobile Trial.slm"]; [self openData]; } -(void)copyDataFile:(NSString*)fileName { NSString * bundlePath = [[[NSBundle mainBundle]resourcePath]stringByAppendingPathComponent:@"Data.bundle"]; NSString *srcPath = [bundlePath stringByAppendingFormat:@" /%@",fileName]; NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); NSString *docDirectory = [paths objectAtIndex:0]; NSString *dstPath = [docDirectory stringByAppendingPathComponent:fileName]; NSFileManager *fileManager = [NSFileManager defaultManager]; BOOL bExist = [fileManager fileExistsAtPath:dstPath]; if (!bExist) { [fileManager copyItemAtPath:srcPathtoPath:dstPath error:nil]; } } ……
转载请注明原文地址: https://www.6miu.com/read-905.html

最新回复(0)