iOS Question Can save external file but can't get data

Discussion in 'iOS Questions' started by Andris, Jan 29, 2018.

  1. Andris

    Andris Active Member Licensed User

    I've been able to successfully do all the steps needed to access external files like CSV as well as my own custom extension types. All end up triggering Application_OpenUrl as they should, and I can successfully extract the file name. But for some reason, the byte length of Data ends up as 9 no matter what I do.

    For example, I receive a CSV file via email and send it to my app, triggering Application_OpenUrl. The file name is fine, but I see no data. The CSV file attached to the email is perfectly OK and I can open it with a spreadsheet, so the file itself is not a problem.

    Here's my code:
    Code:
    Private Sub Application_OpenUrl (Url As String, Data As Object) As Boolean
        
    'extract filename from Url
        Dim fname As String
        fname=Url.SubString(Url.LastIndexOf(
    "/"))
     
        
    'convert data object
        Dim ser As B4XSerializator
        
    Dim fbytes() As Byte
        fbytes=ser.ConvertObjectToBytes(Data)
     
        
    Log(fbytes.Length)   '(ALWAYS RESULTS IN "9")
     
        
    'write data into file in /Download folder
        Dim out As OutputStream = File.OpenOutput(SafeDir & "/" & ImportDir, fname, False)
        out.WriteBytes(fbytes, 
    0, fbytes.Length)
        out.Close 
     
        
    Return True
    End Sub
    What am I doing wrong?
     
    Last edited: Jan 29, 2018
  2. Erel

    Erel Administrator Staff Member Licensed User

    What is the output of Log(Data) and Log(GetType(Data)) ?
     
  3. Andris

    Andris Active Member Licensed User

    Adding Log(Data) and Log(Get(Data)) before Log(fbytes.Length), the entire Log output is:
    Code:
    Application_Start
    Application_Active
    Application_Inactive
    Application_Background
    +[CATransaction synchronize] called within transaction
    +[CATransaction synchronize] called within transaction
    openURL: 
    file:///private/var/mobile/Containers/Data/Application/665787F5-5982-4C88-80ED-ACBD35C0EFFF/Documents/Inbox/180129093314_Budapest-10.csv, com.apple.mobilemail, (null)
    Application_Openurl
    null
    (
    null)
    9
    Application_Foreground
    Application_Active
    The three output values are null, (null), and 9 respectively.

    If I grab a CSV file from the iOS File app instead, outputs are the same, though the openURL line is:
    Code:
    openURL: file:///private/var/mobile/Containers/Data/Application/665787F5-5982-4C88-80ED-ACBD35C0EFFF/tmp/com.xxxxx.xxxxxxx-Inbox/180122072220_TestFolder1%202.csv, com.apple.DocumentsApp, (null)
    So I guess it looks like data is not being passed along?
     
    Last edited: Jan 30, 2018
  4. Erel

    Erel Administrator Staff Member Licensed User

    Andris likes this.
  5. Andris

    Andris Active Member Licensed User

Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice