Browser Widget not working in iOS

Getting into LiveCode for iOS? Ask your questions here.

Moderators: Klaus, FourthWorld, heatherlaine, kevinmiller, robinmiller

Post Reply
rcmills
Posts: 38
Joined: Wed Nov 21, 2018 8:27 pm

Browser Widget not working in iOS

Post by rcmills » Tue May 25, 2021 9:44 pm

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


jacque
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 6036
Joined: Sat Apr 08, 2006 8:31 pm
Location: Minneapolis MN
Contact:

Re: Browser Widget not working in iOS

Post by jacque » Wed May 26, 2021 6:52 pm

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.
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com

rcmills
Posts: 38
Joined: Wed Nov 21, 2018 8:27 pm

Re: Browser Widget not working in iOS

Post by rcmills » Wed May 26, 2021 9:47 pm

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.

jacque
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 6036
Joined: Sat Apr 08, 2006 8:31 pm
Location: Minneapolis MN
Contact:

Re: Browser Widget not working in iOS

Post by jacque » Wed May 26, 2021 10:41 pm

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.
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com

rcmills
Posts: 38
Joined: Wed Nov 21, 2018 8:27 pm

Re: Browser Widget not working in iOS

Post by rcmills » Thu Jun 03, 2021 10:40 pm

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?

rcmills
Posts: 38
Joined: Wed Nov 21, 2018 8:27 pm

Re: Browser Widget not working in iOS

Post by rcmills » Mon Jun 07, 2021 1:03 pm

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

jmburnod
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 2614
Joined: Sat Dec 22, 2007 5:35 pm
Location: Genève
Contact:

Re: Browser Widget not working in iOS

Post by jmburnod » Mon Jun 07, 2021 5:22 pm

Hi rcmills,
You probably need to use "binfile" instead "file"
Best regards
Jean-Marc

SparkOut
Posts: 2491
Joined: Sun Sep 23, 2007 4:58 pm

Re: Browser Widget not working in iOS

Post by SparkOut » Mon Jun 07, 2021 5:55 pm

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.

rcmills
Posts: 38
Joined: Wed Nov 21, 2018 8:27 pm

Re: Browser Widget not working in iOS

Post by rcmills » Mon Jun 07, 2021 9:39 pm

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

rcmills
Posts: 38
Joined: Wed Nov 21, 2018 8:27 pm

Re: Browser Widget not working in iOS

Post by rcmills » Tue Jun 08, 2021 9:05 pm

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

rcmills
Posts: 38
Joined: Wed Nov 21, 2018 8:27 pm

Re: Browser Widget not working in iOS

Post by rcmills » Thu Jun 10, 2021 11:11 pm

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

Post Reply

Return to “iOS Deployment”