StageWebView, iOS, local files - ios

I'm building a mobile app for IOS using Flash Builder, Flex 4.6 and AIR 3.5. I'm investigating using StageWebView to render some HTML5 content.
What I want to do is to build the content into the app, as opposed to putting it on a server. It's relatively static. But I read (and confirmed) that in-app files can't be used directly by StageWebView. But following a suggestion, I'm have the app copy the content to a temp folder, then create a file:// URL for StageWebView, which seems to work:
// create the view
var webView:StageWebView = new StageWebView();
webView.stage = this.stage;
webView.viewPort = new Rectangle( 0, 0, stage.stageWidth, stage.stageHeight);
// copy the HTML5 content to a temp directory
var src:File = File.applicationDirectory.resolvePath("myFolder");
var temp:File = File.createTempDirectory().resolvePath("myFolder");
copyFolderContentsToAnotherFolder(src,temp);
// what's the URL
var newPath:String = "file://" + temp.nativePath + "/index.html";
// load it
webView.loadURL(newPath);
Is this a bad idea? Will temporary files pile up in my device with no way to delete them?
I also thought of having the app implement an minimal HTTP server by listening on a port and supplying the data for requested files as they come. This would allow us to serve the files to StageWebView from their in-app locations, without copying. We do this in a desktop air app and it works very nicely. But, that approach uses ServerSocket, which I discover is not supported on mobile. Is there an alternative way to do this?
Finally, StageWebView does not work well in the Flash Builder iOS simulator, making debugging difficult. Is it best to just go and get FB 4.7, which (should) allow me to use it with XCode's iOS simulator?
thanks

Well, it seems I CAN directly address the in-app content, I just have to construct a file:// URL for it:
var src:File = File.applicationDirectory.resolvePath("myFolder/index.html");
var newPath:String = "file://" + src.nativePath;
webView.loadURL(newPath);

It's been too long since I thought about this. But as I recall I was able to use in app content without making copies, for iOS. But I am reading today where this might not be possible on Android.

It seems that StageWebView, when used with iOS, works best with remote files. So, I am using some Actionscript code that implements a simple HTTP server, serving up local files. Then, I give StageWebView http urls that use localhost, and a port number. Works swell.

After Adobe updated the SDK - the #Jesse Crosen method does not work for android but only on iOS.
To make it work on Android you have to copy the packaged file like this:
var htmlFile:File = File.applicationDirectory.resolvePath("html/index.html");
var fileDest:File = File.applicationStorageDirectory.resolvePath("html/index.html");
htmlFile.copyTo(fileDest, true);
webView.loadURL("file://" + htmlFile.nativePath);

For anyone looking for a current solution to this problem that's simpler than writing an HTTP server, this is what worked for me (on iOS only):
webView.loadURL(new File(new File("app:/myFolder/index.html").nativePath).url);
But there is a caveat, which is that it seems you can't pass in a query string or hash at the end of the URL. Data can be passed to the HTML content by loading a javascript: URL once the main content is loaded.
There's a page with broader information covering iOS and Android here.

Related

Webpack url-loader PDF data URI link for Vue site stops working in iOS 14

I have a Vue.js website with a PDF file which is included in my ultimate javascript bundle via webpack. (It's my CV.) The following build and delivery process has worked perfectly fine for me since 2017, but suddenly stopped working in iOS 14:
Build the PDF with LaTeX.
Use webpack's url-loader to include the PDF in my webpack bundle as a base64 data URI.
Load that URL into a vuex data store, and then just deliver it as a link when clicked.
For the last three years, this has worked fine: I've been able to click on the link and get a working PDF. It's been kind of random and platform-specific whether the PDF opens in-browser or shows up in a download folder, and whether it gets the filename I've asked it to get or not, but, well, that doesn't matter to me. And the core functionality of click the link and get the PDF has worked on every browser and every platform I've ever tried it on.
All of a sudden, with iOS 14, it's stopped working. Now, when I try to activate the PDF link in iOS Safari, nothing happens at all. When I do it in iOS Chrome, it produces a little popup claiming it downloaded a document, but nothing seems to actually be able to open the document. And when I do it in iOS DuckDuckGo, it just displays the base64 data URI in the address bar.
Interestingly, if I take the dataURI that DDG displays in the address bar and copy and paste it into Safari or Chrome on iOS, it actually displays my pdf. So the browsers still have the capacity to display a PDF from a data URI. It just doesn't want to do so from my link.
And my site still works as expected on the desktop. Including in Safari on the desktop. Also, it still works on my wife's phone (she's still on iOS 13). So this is clearly something Apple changed in iOS 14. But what? And how to get my site working again?
I'm guessing that Apple has changed the behavior of the renderer in iOS in some fashion to cause it to break across browsers but nowhere else (since browsers in iOS are all still required to rely on webkit, right?)
This is a pretty important feature to me. I made this decision deliberately for perceived performance---combined with pre-rendering, everything on my site, including the PDF, loads very close to instantly from the user perspective. So I'd really like to keep it.
I'm using Webpack 2.6.1 and Vue 2.3.3. This is a stable build that has been working flawlessly for three years, so I haven't felt the need to update anything except for security updates.
After searching around, I did find this Apple dev discussion which suggests that in iOS 14, Apple newly blocks redirects to data URIs. But I'm not doing a redirect, I'm actually navigating directly to the URI through a link. And the linked discussion suggests that the newly banned behavior just brings Apple in line with what other browsers already ban---but my code works in every other browser, so that can't be it.
Relevant code, to the extent it matters (though it's so basic and obvious that I doubt a simple code fix will be the answer here):
from my webpack.base.js:
{
test: /\.(pdf)$/,
loader: 'url-loader'
},
from my vuex store, in state.js
import cvURL from './assets/pdf/gowdercv.pdf';
from the component containing the link that points to PDF:
<p><a :href="cvURL" download="gowdercv.pdf"><img src="../../assets/icons/file-pdf.svg" class="cvicon"> Download in PDF</a></p>
which is loaded as a computed property to the component, i.e.,
computed: {
cvURL: function(){return this.$store.state.cvURL;},
Does anyone know how to get functionality back in iOS? Is there a workaround built in recent versions of webpack or vue for this? Thanks!
Update: after some help off SO, an acquaintance turned up this similar problem, which also came up with a solution: turning the base64 URI into a blob and passing that data url. Which also solves my problem. Though that SO doesn't have an accepted answer, so I can't vote to close my own question as a duplicate, alas.

Displaying an image from an external site in an iOS/Phonegap app

We're trying to display a graph (.gif) from another site inside our phonegap app. Just adding the img tag with the src set causes a timeout for the entire app. Trying to add the image on page load...
var img = new Image();
var source = <site address based on graphSwitch>;
$(img).attr('src',source).load(
function () {
$('#div' + graphSwitch).empty();
$('#div' + graphSwitch).append(img);
alert("Image Added");
});
has only resulted in nothing being displayed. The only help I've been able to find has been to make sure the site is added to externalHosts (for phonegap 0.9.3) which I've already done and change the timeout, which I also tried but didn't help.
What would be an acceptable way to load images from another website in phonegap?
Well, it seems that with a few more variations I was able to locate the problem. Neither the android simulator for eclipse or the iphone simulator in xcode worked... but actually putting it on an ipod did.
If someone knows how to get it to work all the time and not just on a device I'll switch the answer over to them.
EDIT: It does look like it was our network. Although it still isn't working on eclipse that isn't on the network that was blocked.

open and display a pdf file using actionscript for mobiles (iOS)

Currently I am working with Adobe AIR and getting practice with ActionScript. My aim is to display a PDF file in a view (iPad view in specific). To do so, I was using URLRequest to specify the location of the PDF and HTMLLoader for load the PDF. However is not working, I read in the documentation the following:
HTMLLoader class. AIR profile support: This feature is supported on
all desktop operating systems, but is not supported on mobile devices
or on AIR for TV devices.
For this reason I would like to ask you folks if you have done something similar, or do you know a workaround for it?
Thanks in advance!
I think StageWebView is what you need.
I've just done a similar thing like this...
var _file:String = "nameOfPdf.pdf";
var webView = new StageWebView();
webView.stage = stage;
webView.viewPort = new Rectangle(20,103,960,640);//specify the clipping mask(x,y,w,h)
//NB I have my pdf file as an included file here (added in the publish panel.
var fPath:String = new File(new File("app:/includes/"+_file).nativePath).url;
webView.loadURL( fPath );
//Alternatively you should be able to navigate to a URL
webView.loadURL("http://www.google.com");
There's an external tool called pdf2swf that will transform a pdf into a working swf that you can add just as any other swf. If all you want is a fixed pdf, you can transform it previously and load the transformed swf directly. But if you want any pdf, you would need a external web server to perform the transformation step.

How to display local HTML text in blackberry using sdk 4.6

Till now i was using SDK 5.0 and was able to dispaly local html text using net.rim.device.api.browser.field2.BrowserField but now my requirement has changed and have to use SDK 4.6. The problem is that now i'm getting compiler error for the BrowserField. Can anyone help me in displaying HTML text in SDK 4.6
As there is no BrowserField class supported in earlier versions of RIM SDK, you can launch local browser session for a html file, embedded in your cod-application.
Let say your application cod name is mymodule.cod
And you have attached a document.html file to your project, and this file is located in your source code folder, not outside.
You can launch browser session via this code:
BrowserSession session = Browser.getDefaultSession();
session.displayPage("cod://mymodule/document.html" );
Note, that module name is case sensitive.
And note that it is not documented way to access local html files.
If you are going to test this in simulator, make sure that MDS simulator is launched and is working.
It is still possible to display local HTML content with the APIs available for earlier BlackBerry OS versions. It is just a bit more complicated to make it work. Doing this involves the older BrowserField API (as opposed to the newer BrowserField2 API you've already discovered). I think the SDK includes a "BrowserField" example app that partially demonstrates this. It involves using the RenderingSession class to retrieve a BrowserContent object, which has a method to return a UI Field that you can actually show within your screen.
The trick is that RenderingSession expects you to supply it with an HttpConnection (or InputConnection) that it can read the data from. Since these are interfaces, you just have to implement them in such a way they they return your own HTML data instead of wrapping an actual HTTP connection.
It may be a little specific to the context of my own application, but here is an example of a class I wrote that wraps this API for local HTML content display: BrowserFieldRenderer

CSV file download to ipad

I am developing a data capture web app, primarily targetting iPad usage. Multiple users will primarily capture data on iPads, but then a manager will typically download all captured records onto a PC.
Even though the file download will primarily target PCs, I am pondering whether I should try and support file downloads to the iPad itself.
The server app is an MVC2 ASP.NET app, and I'm using a controller that returns a File result. Test code is as follows:
public ActionResult DownloadResponseData(string profileid)
{
string billcsv = "account_ref,line1,line2,line3";
var data = System.Text.Encoding.UTF8.GetBytes(billcsv);
string filename = "billfor.csv";
return File(data, "text/csv", filename);
}
Even though the majority of people will download to their PCs, because I am supporting full-screen iPad usage I am using the following client-side code to initiate the file download:
var url="/Download/DownloadResponseData?profileid=" + downloadRequest.profileid + "&unique=" + escape(Date());
window.open(url);
This works fine for non-iPad usage - it downloads the file nicely in Chrome.
My questions are numerous: does it make sense to download a CSV file to an iPad? Does an iPad support CSV? Do I need other software on the iPad to view a CSV file? How should I change the above code to download 'cleanly' to an iPad?
When I run the code above on the iPad, then it simply displays the entire CSV file contents within the iPad window - it doesn't seem to recognise the http response as a file.
Sorry for the rather obtuse question. Thanks.
Yes it makes sense to download csv files to the iPad, a number of iPad apps can deal with them successfully.
However, I find that mobile safari is hit or miss - it will download my activity in csv from the Amex web site okay (displays in spreadsheet form and offers to open in Numbers, DropBox, and other apps), but when I click download to get a csv file of activity on the Chase site, nothing at all happens. I even tried a third part web browser, same thing (although they all use the same webkit underneath I guess).

Resources