5
我需要使用RubyMotion下載和解壓縮文件。我試着尋找例子,但找不到這個過程。Rubymotion:在iOS中下載和解壓ZIP文件
我有一個變量(@file),它是請求中的所有數據。我需要將這些數據寫入文件,然後解壓縮,保留未壓縮的數據並刪除tmp壓縮文件。
這是我到目前爲止有:
class LoadResourcesViewController < UIViewController
def viewDidAppear(animated)
@loading_bar = retrieve_subview_with_tag(self, 1)
req=NSURLRequest.requestWithURL(NSURL.URLWithString("#{someurl}"))
@connection = NSURLConnection.alloc.initWithRequest req, delegate: self, startImmediately: true
end
def connection(connection, didFailWithError:error)
p error
end
def connection(connection, didReceiveResponse:response)
@file = NSMutableData.data
@response = response
@download_size = response.expectedContentLength
end
def connection(connection, didReceiveData:data)
@file.appendData data
@loading_bar.setProgress(@file.length.to_f/@download_size.to_f)
end
def connectionDidFinishLoading(connection)
#create tmp file
#uncompress .tar, .tar.gz or .zip
#presist uncompresssed files and delete original tmp file
puts @file.inspect
@connection.release
solutionStoryboard = UIStoryboard.storyboardWithName("Master", bundle:nil)
myVC = solutionStoryboard.instantiateViewControllerWithIdentifier("Main3")
self.presentModalViewController(myVC, animated:true)
end
end
任何幫助或例子將是巨大的!
幫我解決了相關的問題,感謝張貼您的解決方案! – sbauch