Rubymotion:在iOS中下载和解压ZIP文件 您所在的位置:网站首页 文件然后解压 Rubymotion:在iOS中下载和解压ZIP文件

Rubymotion:在iOS中下载和解压ZIP文件

2023-03-18 17:29| 来源: 网络整理| 查看: 265

所以我解决了这个解压缩和untaring。

解压:

#UNZIP given you have a var data that contains the zipped up data. tmpFilePath = "#{NSTemporaryDirectory()}temp.zip" #Get a temp dir and suggest the filename temp.zip @fileManager = NSFileManager.defaultManager() #Get a filemanager instance @fileManager.createFileAtPath(tmpFilePath, contents: data, attributes:nil) #Create the file in a temp directory with the data from the "data" var. destinationPath = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMask, true).objectAtIndex(0) //get the target home for the unzipped files. This MUST be within your domain in order to persist. SSZipArchive.unzipFileAtPath(tmpFilePath, toDestination: destinationPath) #Use the SSZipArchive to unzip the file. @fileManager.removeItemAtPath(tmpFilePath, error: nil) #Cleanup the tmp dir/files

请记住,您必须包含SSZipArchive库。我使用了obj-c库而不是cocoapod。要做到这一点添加以下行您的Rake文件(假设你把OBJ-C文件中的供应商/ SSZipArchive文件夹):

app.libs += ['/usr/lib/libz.dylib'] app.vendor_project('vendor/SSZipArchive', :static)

要解压:

dir = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMask, true) #get target dir for untar'd files error_ptr = Pointer.new(:object) NSFileManager.defaultManager.createFilesAndDirectoriesAtPath(dir[0], withTarData: data, error: error_ptr) #Create and untar te data (assumes you have collected some tar'd data in the data var)

在这种情况下,你需要Light Untar lib(https://github.com/mhausherr/Light-Untar-for-iOS/)。包括此LIB中添加以下到您的Rake文件(假设文件在供应商/解压缩):

app.vendor_project('vendor', :static, :headers_dir=>"unTar")


【本文地址】

公司简介

联系我们

今日新闻

    推荐新闻

      专题文章
        CopyRight 2018-2019 实验室设备网 版权所有