Using UIWebView to display documents other than HTML is possible with the UIWebView.
The such files types are as follow: Excel (.xls), Keynote(.key.zip), numbers (.numbers.zip), pages (.pages.zip), PDF(.pdf), Powerpoint (.ppt), Word (.doc), Rich text format (.rtf), Rich text format Directory (.rtf.zip), Keynote '09(.key), numbers '09 (.numbers) and pages '09(.pages)
While there an ton of examples how to do this in objective-c, how can we get an local file to display in the UIWebView with Livecode?
(Image: Example of an pdf booklet stored as an local file. on iPad iOS 4.3)
We should be able to use file:// path2File / filename.Extension
And this works but what does not work is the urlEncode() function, why? not sure. What does work is the following instead.
replace space with "%20"
To make this an lot easier we can make an custom function to format our local file string for use with iOS UIWebView control in Livecode iOS.
# format local file for viewing in UIWebView for iOS
function rpFormatLocalFileWebView pFolderType, pFileName
put "file://" & specialFolderPath(pFolderType) & slash & pFileName\
into tLocalFileGet
replace space with "%20" in tLocalFileGet
return tLocalFileGet
end rpFormatLocalFileWebView
The parameters are:
pFolderType is one of: documents, cache, temporary or engine
pFileName is as such MyDocumentName.pdf, MyDocumentName.html, MyDocumentName.doc etc, etc.
Example of Use of create browser with local file in Livecode.
command createMyBrowser
put rpFormatLocalFileWebView("documents","Cool.pdf") into\
tMyLocalContent
iphoneControlCreate "browser"
put the result into sBrowserId
iphoneControlSet sBrowserId, "rect", the rect of graphic "BrowserLoc"
iphoneControlSet sBrowserId, "visible", "true"
iphoneControlSet sBrowserId, "autoFit", "true"
-- here where we set our content returned by the format local file for\
-- viewing in UIWebView for iOS function
iphoneControlSet sBrowserId, "url", tMyLocalContent
end createMyBrowser
hope this helps working with and viewing files in UIWebView an little more less confusing.
More info on Livecode for iOS development, with the Livecode v4.6 @ Link