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

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:
B4X:
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:

Andris

Active Member
Licensed User
What is the output of Log(Data) and Log(GetType(Data)) ?
Adding Log(Data) and Log(Get(Data)) before Log(fbytes.Length), the entire Log output is:
B4X:
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:
B4X:
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:
Top