Page 1 of 1
Browser Widget not working in iOS
Posted: Tue May 25, 2021 9:44 pm
by rcmills
I am trying to load pdfs into the browser widget for an iOS app. It works fine in the Mac IDE.
I have included the browser inclusion, and have upgraded to LC 9.6.2 The documentation seems straightforward, but I'm having no luck.
Here is my loader code:
Code: Select all
on mouseUp
local tFile
set the URL of widget "browser" to empty
wait 2 ticks
if the environment is "mobile"
then
put getPDFs() into tFile
answer tFile with "OK" // check to see if the syntax looks correct:)
else
answer file "Please choose the file you would like to display" with type "PDF document|pdf|PDF" as sheet
if it is not empty
then
put it into tFile
else
put getPDFs() into tFile
end if
end if
// Allow for spaces in filenames
replace " " with "%20" in tFile
set the url of widget "browser" to tFile
end mouseUp
function getPDFs
get "The-Bible-Atlas.pdf"
put specialfolderpath("resources") into sFolder
put (sFolder & "/" & it) into tFileName
return tFileName
end getPDFs
Re: Browser Widget not working in iOS
Posted: Wed May 26, 2021 6:52 pm
by jacque
The "answer file" command doesn't work on mobile, it's only for desktop. You can, however, "get the files" and display a list in the app for the user to choose from.
Re: Browser Widget not working in iOS
Posted: Wed May 26, 2021 9:47 pm
by rcmills
Thank you, jacque.
I only used the "answer file" for testing in the MacOS IDE. When the app runs on iOS, it bypasses that routine, and gets the filename in the "getPDFs" function (the pdf file is copied into the app using the Copy Files tab of the Standalone Application Settings). My problem is that the pdf doesn't load into the browser in iOS.
Re: Browser Widget not working in iOS
Posted: Wed May 26, 2021 10:41 pm
by jacque
My bad, I didn't read the script far enough. It may be similar to databases, where for some reason the file has to be moved to the documents folder before it can be retrieved. You might get some info if you add "answer the result" after trying to set the url of the widget.
Re: Browser Widget not working in iOS
Posted: Thu Jun 03, 2021 10:40 pm
by rcmills
I got an empty result when I tried "answer the result". Isn't that supposed to mean that the "set URL" command was successful?
So, how do I move the pdf into the documents folder?
Re: Browser Widget not working in iOS
Posted: Mon Jun 07, 2021 1:03 pm
by rcmills
I have tried the following routine to move the pdf file from the "resources" folder to the "documents" folder. It puts a file there, but it has zero bytes.
What am I missing?
Code: Select all
on movePDF
put "The-Atlas.pdf" into pdfName
put specialfolderpath("engine") into eFolder
put (eFolder & "/" & pdfName) into eFileName
put "file:/" & specialFolderPath("documents") into dFolder
put (dFolder & "/" & pdfName) into dFileName
answer "Moving:" & eFileName && "to URL" && dFileName as sheet
put URL eFileName into URL dFileName
end movePDF
Re: Browser Widget not working in iOS
Posted: Mon Jun 07, 2021 5:22 pm
by jmburnod
Hi rcmills,
You probably need to use "binfile" instead "file"
Best regards
Jean-Marc
Re: Browser Widget not working in iOS
Posted: Mon Jun 07, 2021 5:55 pm
by SparkOut
One path doesn't include "file:" even (though it should be "binfile:").
Also it is preferable to use "resources" rather than "engine" for consistency's sake, more than anything. With the specialFolderPath reference, you dont need the leading slash after the colon in the "binfile:" url descriptor.
Re: Browser Widget not working in iOS
Posted: Mon Jun 07, 2021 9:39 pm
by rcmills
Thanks for the advice.
My code now reads as below, but I'm still getting a zero bytes file. I checked that the pdf file in the resources folder is the expected size (21.4 MB).
Code: Select all
on movePDF
put "The-Atlas.pdf" into pdfName
put "binfile:" & specialfolderpath("resources") into eFolder
put (eFolder & "/" & pdfName) into eFileName
put "binfile:" & specialFolderPath("documents") into dFolder
put (dFolder & "/" & pdfName) into dFileName
answer "Moving:" &cr&cr& eFileName &cr&cr& "to URL" &cr&cr& dFileName as sheet
put URL eFileName into URL dFileName
end movePDF
Re: Browser Widget not working in iOS
Posted: Tue Jun 08, 2021 9:05 pm
by rcmills
I have finally succeeded in moving the pdf file to the documents folder in iOS, and verified it's size.
Unfortunately, loading it from there into the Browser Widget still does not work.
When checking for error, the result is empty, and I get "No error" in my dialog box, but the pdf does not load into the widget window in iOS, though it loads just fine in the development environment on my Mac.
Code: Select all
on mouseUp
local tFile
set the URL of widget "browser" to empty
wait 2 ticks
if the environment is "mobile" or the optionKey is down
then
put getPDFs() into tFile
else
answer file "Please choose the file you would like to display" with type "PDF document|pdf|PDF" as sheet
if it is not empty
then
put it into tFile
else
put getPDFs() into tFile
end if
end if
// Allow for spaces in filenames
replace " " with "%20" in tFile
set the url of widget "browser" to tFile
## Check for success and maybe get a hint why it failed if it did:
if the result = empty
then
answer "No error" as sheet -- comment
else
answer "Error:" & CR & the result as sheet
end if
end mouseUp
function getPDFs
answer "Which pdf?" with "Atlas.pdf" or "Timeline.pdf" as sheet
put it into pdfName
put specialFolderPath("documents") into dFolder
put (dFolder & "/" & pdfName) into dFileName
return dFileName
end getPDFs
Re: Browser Widget not working in iOS
Posted: Thu Jun 10, 2021 11:11 pm
by rcmills
After noticing the URL displayed in the widget via the Inspector in the IDE, I had the iOS app show me what that property was after loading. Turns out that in the iOS environmen, "set the URL to <filename>" code does not include the "file://" at the start, as the development environment does.
So, after adding that to the filename when in the iOS environment, the widget finally displays my pdf files