I believe that these are two different issues (although I may be incorrect). The one that I have tackled is the inability to load images from disk when passing in HTML code (it works with a HTML file on the volume).
htmlViewer1.grantAccessToFolder( <folderContainingImages> )
htmlViewer1.loadPage( <htmlCodeAsString>, <folderContainingImages> )
For users of the Ohanaware App Kit, this code is already included, for everyone else copy and paste the following code into a shared module.
Public Sub grantAccessToFolder(extends h as HTMLViewer, inFolder as folderItem)
#if targetMacOS and xojoVersion >= 2020.01 then
// --- Originally created in July 2020. <--- Leave this info here so it's easier to track which version of the code.
// Published Sep 1st 2020.
// written by Sam Rowlands of Ohanaware.com
// Apple documentation for this API: https://developer.apple.com/documentation/webkit/wkwebview/1414973-loadfileurl?language=objc
declare function NSClassFromString lib "Foundation" ( inClassName as CFStringRef ) as integer
declare Function NSURLfileURLWithPathIsDirectory lib "Foundation" selector "fileURLWithPath:isDirectory:" ( NSURLClass as integer, path as CFStringRef, directory as boolean) as integer
declare function WKWebViewloadFileURL lib "WebKit" selector "loadFileURL:allowingReadAccessToURL:" ( HTMLViewer as integer, URL as integer, readAccessURL as integer ) as integer
// --- Create a NSURL object from a Xojo Folderitem.
dim folderURL as integer = NSURLfileURLWithPathIsDirectory( NSClassFromString( "NSURL" ), inFolder.nativePath, inFolder.directory )
// --- This bit is not technically correct. The first parameter after the instance should actually be the page that you're trying to load.
// But as we're not loading a page per say... For the purpose of just setting access rights, we ignore the return
// value as we don't need to display progress.
call WKWebViewloadFileURL( h.handle, folderURL, folderURL )
#EndIf
End Sub
Of course I would love to get paid for my work, “bills to pay, mouths to feed, etc…”
Thank you @TimStreater for requesting permission before sharing this code (or an earlier draft of it). I really do appreciate that you did that.