Using a website API to return an image

I’m working on an iOS app that sends requests to a site’s API to return an image and display it in an iOSHTMLViewer. This is a port of an old Mac app that worked fine using HTMLViewer.

Everything works great in the simulator, but testing on an iPad doesn’t display anything. I’m using multiple views with different iOSHTMLViewers and its the same problem with all of them.

Here’s a sample of a file that I’m using with the LoadURL method:

[code]

Hex Name UWP Remarks {Ix} (Ex) [Cx] N B Z PBG W A Stellar ---- -------------------- --------- --------------------------- ------ ------- ------ ----- -- - --- -- -- -------------- <?xml version="1.0"?> Unnamed [/code]

I’m using https so I don’t think it’s an NSAppTransportSecurity issue that requires a plist.

Anybody have any suggestions?

If that’s the full HTML, there’s nothing there to display an image. Do you have an example URL you can share?
The base website uses a lot of Javascript to display the map, so it could be any number of hiccups along the way.

If I export that file from the simulator, where it works, to iCloud Drive, and then open it on the iPad, Safari correctly loads the map.

In the app on the iPad, if I put in the code:

  SectorHTMLViewer.LoadURL("https://www.macintouch.com")

it correctly loads the webpage. But if I use:

[code] Dim htmlFile As Xojo.IO.FolderItem = Xojo.IO.SpecialFolder.Documents.Child(“sector.html”)
Dim output As TextOutputStream
output = TextOutputStream.Create(htmlFile, TextEncoding.UTF8)
output.Write(t)
output.Close

SectorHTMLViewer.LoadURL(htmlFile.URLPath)
[/code]

then I get nothing.

This might work better

HTMLViewer1.LoadURL( "data:text/html," + urlencode(htmlString) )

[code]Public Function urlencode(url As Text) as Text
// Remove newline characters.
url = url.ReplaceAll ( &u0A, “” )

Declare Function CFURLCreateStringByAddingPercentEscapes lib “Foundation” (allocator as Ptr, origString as CFStringRef , charactersToLeaveUnescaped as CFStringRef , legalURLCharactersToBeEscaped as cfStringRef,encoding as uint32) as CFStringRef

url = CFURLCreateStringByAddingPercentEscapes(nil, url, nil, nil, &h08000100)
//Extra substitutions
url = url.ReplaceAll ( “’”, “%27” )

Return url

End Function
[/code]

EDIT
Or this is even easier:

Declare Sub loadHTML Lib "UIKit.framework" selector "loadHTMLString:baseURL:" (obj_id As ptr, html As CFStringRef, url As ptr) loadHTML(HTMLviewer.handle, htmlString, Nil)

Thanks. What I have works great in the simulator.

So I’m thinking it must have to do with something that’s different between the simulator and the development app on the iPad. Like an entitlement or something. Hmmmm.

Possibly security settings? That’s why I’d asked for a URL to look at, so we can check into the Safari debugger to see what dependencies they may be needing. Frequently a local file is unable to access remote resources as a measure of security.

I wasn’t sure how to give you a URL for this API call, but when I open files in Safari, I do get a URL. Reopening that URL in a new tab doesn’t give me my own custom data image back, but something from the site’s data.

This one returns random data from the site’s database:
https://travellermap.com/api/jumpmap?hex=0000&jump=4&scale=56&options=24818

This one returns an error message because the URL is not correct:
https://travellermap.com/api/poster?subsector=A&scale=72&style=poster&options=25595&sscords=1

So I’ve pretty much given up on doing this with an HTMLViewer, even though it works in the simulator.

Replacing the HTMLViewer with an ImageWell and using HTTPSocket I’m not totally there, but I do get a map returned and displayed on the iPad. Sigh.