在ios 8中取消归档.tar文件

时间:2015-04-10 07:15:02

标签: ios swift

如何在iOS 8中解压缩文件?

我已经按照以下示例: NVHTarGzip,Light-Untar,ZipArchive 但是我无法让它们发挥作用。

1 个答案:

答案 0 :(得分:1)

对于我的团队,我们使用了Light-Untar-for-iOS  https://github.com/mhausherr/Light-Untar-for-iOS

我们这样做的实际代码行是:

if let path = NSBundle.mainBundle().pathForResource("es_ES", ofType:"tar") {
        let documentDirectory:NSArray = NSSearchPathForDirectoriesInDomains(NSSearchPathDirectory.DocumentDirectory, .UserDomainMask, true)
        let documentDirectoryPath:String = documentDirectory[0] as! String
        var fileManager = NSFileManager.defaultManager()
        var isDirectory: ObjCBool = ObjCBool(true)
        if !fileManager.fileExistsAtPath(documentDirectoryPath + "/\(toLocale)", isDirectory: &isDirectory){
            fileManager.createDirectoryAtPath(documentDirectoryPath + "/\(toLocale)", withIntermediateDirectories: true, attributes: nil, error: &error)
        }
        var destinationPath = documentDirectoryPath + "/\(toLocale)"
        NSFileManager.defaultManager().createFilesAndDirectoriesAtPath(destinationPath, withTarPath: path, error: &error, progress: { (progress) -> Void in
            println("Progress \(progress)")
            self.tarTimer?.invalidate()
            self.tarTimer = NSTimer.scheduledTimerWithTimeInterval(1.0, target: self, selector: "untarDone:", userInfo: [fromLocale, toLocale], repeats: false)
        })
    }