Unzip on iOS?

Strongly suspect the answer is no, but is there a library that will unzip on iOS?

Short answer: no.

Long answer:
There is an open source Xcode project that can unzip files: https://github.com/ZipArchive/ZipArchive

I have been able to unzip a file in an Xojo made iOS app.

  1. Build the ZipArchive framework

  2. In Xojo create a Copy files build step and drag the framework into Xojo.
    Make sure the files are copied in Ressources > Frameworks subdirectory

  3. In Xojo you must first load the framework

[code]Public Shared Function LoadFramework() as Boolean

Declare Function dlopen Lib “/usr/lib/libSystem.dylib” (path As CString, mode As Int32) As Ptr
Declare Function dlerror Lib “/usr/lib/libSystem.dylib” As CString

Const RTLD_LAZY = 1
Const RTLD_GLOBAL = 8

Dim path As Text

path = “@executable_path/Frameworks/ZipArchive.framework/ZipArchive”
'path = “@executable_path/Frameworks/Applanga.framework”

Dim result As Ptr = dlopen(path.ToCString(Xojo.Core.TextEncoding.UTF8), RTLD_LAZY Or RTLD_GLOBAL)

If result = Nil Then
Dim reason As Text
reason = Text.FromCString(dlerror, Xojo.Core.TextEncoding.UTF8)
'sLastError = reason
’ Dim exc As New Xojo.Core.InvalidArgumentException
’ exc.Reason = reason
’ Raise exc
Return False
End If

System.DebugLog “ZipArchive framework opened.”
Return True
End Function
[/code]

  1. Then Unzip a Xojo.IO.FolderItem

[code]Public Shared Function unzipFile(file As Xojo.IO.FolderItem, destination As Xojo.IO.FolderItem) as Boolean

If destination Is Nil Then
Dim err As New NilObjectException
Raise err
Return False
End If
If destination.Exists = False Then
Dim err As New Xojo.IO.IOException
err.Reason = “destination doesn’t exist”
Raise err
Return False
End If

// + (BOOL)unzipFileAtPath : (NSString *)path toDestination : (NSString *)destination ;

Soft Declare Function unzipFileAtPath_ Lib “Foundation” Selector “unzipFileAtPath:toDestination:” (ref As Ptr, path As CFStringRef, toDestination As CFStringRef) As Boolean

If unzipFileAtPath_(ClassRef, file.Path, destination.path) Then
Return True

End If
End Function
[/code]

  1. Next step is to understand how to code sign the framework in Xcode, make sure that the entire app is correctly code signed and that the framework is built for 64bit

Thats very thorough and useful information Jeremie.
Thank you.
I think this is beyond my skills at the moment (especially for an app I intend to ship free of charge), but I will come back to this.

@Jeremie Leroy I’m trying to implement the unzip functionality as you described. What do I need to provide as “ClassRef” to the “unzipFileAtPath_” function? Could you maybe set up a class with this?

Sorry I missed this part of the code.

Declare Function NSClassFromString Lib "Foundation" (clsName As CFStringRef) As Ptr Static ClassRef As Ptr = NSClassFromString("SSZipArchive")

Hey Jeremie - I am using this ZipArchive framework in iOS. It works fine in the simulator, but when I have it actually copied in for the build of the app, the app will not install. Something appears to be off with the code signing. How is this fixed?

I actually never needed Zip capabilities in a built app so I do not have a solution right now, sorry.

See this:


It works on the simulator, modified ZipArchive to function.

It’s always worked in the simulator for me. But never in the build. I’ve eliminated using this from my app. I was transferring two files to the app. Now I am building the app with one of the files inserted into the Resources folder as a build step. Better way to do it anyhow as this is a file the user isn’t modifying. The other file is a database file that does contain user settings and is transferred from my desktop app. But zipping it doesn’t save anything really as the database file doesn’t compress.