I have a Phonegap iOS app. My app is distributed privately, hence there is and there will be no usage of the app store. The app communicates with a homebrew middleware. In order to manage the app updates, I thought about doing something like:
-> On app start, check if a more recent version is available.
-> If yes then call a home-made Javascript module that will leverage the HTML5 file I/O API in order to update/create/delete files based on the output of the middleware.
In your opinion; is this solution reliable?
Are there any alternatives? (app store is completely out of the picture)
With a PhoneGap/Cordova app you normally load files from your local www folder. The problem with updating files at runtime is that you cannot write to the www location - you can only write to your app's 'documents' folder.
I assume you are using an Enterprise distribution since you are distributing without the app store. You could look at using something like TestFlight to distribute updates if you are happy for the users to have to go and check for updates.
You could also eliminate TestFlight and host the ipa files yourself, check for updates and then ask the user to download and install the update.
EDIT
It is not possible to write to the www folder with or without a plugin. This is due to iOS restrictions rather than PhoneGap/Cordova restrictions.
These links talk about distributing Enterprise apps over-the-air
http://developer.apple.com/library/ios/#featuredarticles/FA_Wireless_Enterprise_App_Distribution/Introduction/Introduction.html
IOS Enterprise Distribution Through OTA
Enterprise In-House App distribution
I was considering using the www folder as a bootstrap to download the actual app in a www folder in the document directory, and loading the index.html page from there (and the rest of the app)
I'm wondering if that would be an option
Of course the ObjectiveC UIWebView would point to the downloaded version if it exists
I know this is an old question, but the accepted answer is no longer correct. Here's a complete project showing how it can be done: https://github.com/ben-ng/phonegap-air
In short, the trick is to not write to the app bundle, but to the Documents directory.
There's an alternate service called Trigger.io. It is a lot like phonegap, but one of its' key features is that it lets you "reload" the app on the device, which is essentially what you're looking for, AFAICT.
So it seems that cordava can only load files that are in the app bundle. You cannot simply alter the webroot parameter to take the documents folder.
What you could do is use the FileReader API to read from the persistent store. This would mean you would have to create some sort of bootstrap html / javascript that is in the app bundle and create code that loads the content from the persistent store (which you can update yourself anytime you like)
This is a great place to start looking: Cordava File API docs
Related
I'm making a chat widget, which will be embeddable to any website using an iframe. Previously I made a react app and then bundled everything to ONE bundle.js file and hosted it on S3(or any static file hosting platform) with public access and then inject that file inside the website with iframe (using the script tag). That bundle.js file has a size of nearly 1.23 MBs. I suspect that it can affect the speed of the website loading.
I have tried one more thing, I created the same react app and deployed it on AWS Amplify, and then use the link of that app in the iframe instead of hosting a static bundle.js file.
Is the latter one a good approach or the former (bundle.js) was better?
I figured it out that the latter approach (Running the app in AWS Amplify) takes more time to load hence is not that useful than hosting a static file on S3. However, I found that CloudFront can improve the speed and also add cache support for it.
I'm writing an app which house over 1000 small images in the www/images folder in my cordova app (am using Intel XDK for the build). The app needs to check for updates and download images that the user doesn't have, along with other content. I want the new images to be saved to the same folder as the existing images (www/images) and can't find anywhere how to do this. All I find is articles about Cordova saving camera images to gallery/camera roll etc.
The content will be run through and "injected" script which will save it to localStorage. I'm just struggling with the images.
As far as I know, you can't do this. The www folder is part of the app bundle, and is sandboxed to protect it from, well, writing. That's the same answer someone else got here: Cordova Write To WWW Directory (iOS).
You have to use the File API to write to one of the writable file areas available to the app. You can find some examples of how to do that here: https://github.com/johnwargo/apache-cordova-api-cookbook-code/tree/master/chapter10-file.
Some details from the book:
The Cordova File API provides an application with the methods it needs
to interact with the device’s local directory structure. The API
exposes methods an application can use to browse the file system,
read, write, copy, move and remove files. An application cannot access
just any part of the file system, only the temporary and persistent
file storage locations (described below) on a mobile device.
Cordova’s implementation of the File API is based in part on the W3C
File API: Directories and System specification
(www.w3.org/TR/file-system-api). Not all of the capabilities of the
W3C specification have been implemented, but the API provides the
essential capabilities most mobile developers will need.
An application would use this API to read and write files on the
device file system. An application might use one of the many available
storage options for web application to store application data, but
developers can also use the file system to persist application
settings or application data using the file system, writing text files
(in XML or JSON format for example) as needed while the application
runs. Additionally, remember that the Camera (Chapter 3) and Capture
(Chapter 4) APIs write their files to the file system, applications
use the File API to manipulate those files as needed.
Most smartphone provide applications with two different types of file
storage space. To store temporary files, the device exposes a
temporary storage location. For content and data that is integral to
the application’s operation and must remain available after the
application is closed and restarted the application should use
persistent storage.
In general, an application might use temporary storage for transient
data, data that’s written to the file system as part of a memory
management strategy or as swap space when analyzing or manipulating a
large amount of data. With temporary storage, the application can read
from and write to the storage area with impunity, creating and
deleting files as needed within the available storage limitations of
the device. The device OS may automatically empty temporary storage
when the application closes or the device reboots – freeing up storage
space for other applications.
Persistent storage on the other hand is more stable; the device OS
protects it during reboots and when the application closes. An
application’s persistent storage will be emptied by the OS only when
the application is uninstalled from the device.
In the sample application, the application’s UI exposes buttons that
are used to interact with the different file system types as shown in
Figure 10.1. As you can see from the figure, I used jQuery Mobile for
the application’s UI in order to simplify the code and let jQuery
Mobile deal with rendering file lists, transitioning between pages and
so on.
Is there a way to hold a large block of text, or images/videos, embedded in a FirefoxOS app, while directly accessing them from the app (similar to /res/raw/ in Android)? I don't see where the /data/ directory is being accessed in the example app.
There are many ways that you can do this:
Distribute your web app as a packaged app. In this scenario all your resource files are zipped up in a single file, available after install via a URL scheme described in the documentation.
The Application Cache allows you to instruct the browser to download files for offline use. I like Rob Hawkes' utility for generating appcache manifest files.
You can manage the data yourself by downloading the files via XMLHttpRequest and storing the data in an IndexedDB database or on the SD card via the DeviceStorage API.
I think that your best bet is the filehandle API, but more importantly keep in mind that a Firefox OS app is basically a website so you shouldn't be thinking as an android app that can carry it's media and so on.
Good luck
If you want to display images in a website you place images in the same root folder or sub folder. The same thing works with firefox OS.Place your images in your app folder and use them. If you want to use images from the mobile then you can use device Storage API .you can find the example here
I want to create a web app platform that runs locally on the users computer.
I am considering using google chrome's app process to make this work.
I am having trouble understanding, wether google will let me do this. so the user would have to download the main chrome app , which contains the base html and javascript code, and within the app be able to download and store locally with in the app new html and js code.
So in other words I want to create an app that allows users to download and install apps from my own app store, and have them run within the chrome app.
Does google chrome app development allow this?
if not what are my alternatives for creating an app that needs to run on a browser storing all files locally?
You can download HTML and CSS as much as you want and then use JavaScript to modify the DOM accordingly. It's not set up as any kind of system that lets you substitute pages, and there's no navigation within the app (using A elements), but you are free to modify the DOM.
There's no way to add any JavaScript to what's initially in the app, as eval and the other code-executing functions are disabled. You can certainly add SCRIPT elements to the DOM, but the files they reference have to have been part of the app at the time it was installed.
Having said all that, you can implement the app as an interpreter for some language and then download programs written in that language. It's just that none of the code can be direct Chrome App code, nor can any code you download (regardless of language) make direct Chrome API calls.
Have you looked at the HTML5 Filesystem API? You can fetch a file and reference it later. You also need the add the "unlimitedStorage" permission to manifest.json.
http://www.html5rocks.com/en/tutorials/file/filesystem/
I am using PhoneGap to develop an application for Android and iOS, and recently in a discussion about this technology, someone told me a seemingly brilliant idea that I can do background updates of my application without having to submit a new application to the app store.
The problem is that, being that I am still fairly new to the HTML5/CSS and Javascript world, I cannot figure out how to download files to my www directory for permanent storage. I can dynamically load JS code or HTML pages at runtime, but I want to create some javascript module that will find that a certain .css, .html, or .js file is out of date, download the new version of that file from some http or file server to the www directory, and then have that new file permanently saved so that it is available the next time the app is opened.
I feel like this should be simple, but I can't figure out how to do it. Thanks in advance.
In order to permanently save files to the devices you will need to make use of the PhoneGap File APIs. Periodic tasks can be achieved with a simple Javascript timer.