Unzip on iOS?

  1. 2 months ago

    Jeff T

    Aug 9 Midlands of England, Europe

    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

    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

    4. Then Unzip a Xojo.IO.FolderItem

    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

    5. 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

  2. Jeremie L

    Aug 9 Pre-Release Testers, XDC Speakers Answer Europe (France) - getpackr.io

    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

    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

    4. Then Unzip a Xojo.IO.FolderItem

    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

    5. 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

  3. Jeff T

    Aug 10 Midlands of England, Europe

    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.

or Sign Up to reply!