I'm developing a mobile app using Flutter and it's backed using Laravel. For each page, I'm making a request. Since the page content doesn't change that often I'm thinking to store a copy of content locally on phone and update it weekly. But the issue is that the data can change more often.
Is it possible for Laravel to notify when there is a data change, and start the sync?
It wouldn't be possible for the backend to update the front end for every instance of the app.
Instead you could do a specific route like
Route::get('/recently-updated', 'APIController#recentlyUpdated')
Then in your controller
public function recentlyUpdated() {
$updatedAt = Page::orderBy('CREATED_AT', 'desc')->get()->updated_at;
return $updatedAt;
}
And just store that in your app and compare them. Maybe have it checked on launch or at x interval.
This is not the only way but a good starting point.
I have a small PHP app in Cloud9 and I hosted it at Heroku using the Git terminal of Cloud9.
The point of the web app is that there are some configuration values (essentially name value pairs) which an administrator can set in the web app. These values are then stored in a .json file. The web app offers those configuration values stored in that .json through a Rest API and from my Android app, I use the Volley library to consume this API, and get those configuration values in the Android app.
When I change a configuration value through the user interface in the web app, the change IS reflected when I access the REST API through the URL in the browser. When I consume the REST API from my Android app, the change is reflected there too. This change is reflected correctly no matter how many times I run the Android app (which consumes the REST API through Volley) in this session.
BUT The problem is that if I turn off my computer and return to it, say, a couple hours later, the configuration data seems to be set back to initial values again. I checked it many times in the browser (by accessing through URL in browser) as well as in my Android app which is consuming the REST API; the value which I had changed in the web app gives its initial value again.
Any ideas about why this is happening and what I can do about it?
EDIT:
Problem installing MLab MongoDB at Heroku:
Could you confirm where you are currently storing your .json file? If you are using the filesystem you'll have this problem as Heroku uses something it calls an ephemeral filesystem. Each dyno gets its own filesystem that exists only as long as that dyno is running. Any changes will be reset whenever your dyno restarts. This happens whenever there is a deployment or once a day. If this is a free dyno it may occur each time it sleeps/wakes but I can't confirm this.
If you are storing values that can change during the lifetime of your application you will need to use non filesystem storage. Heroku has several add-ons that you can experiment with for free. The first ones that spring to mind are mlab or redis.
https://elements.heroku.com/addons/mongolab
https://elements.heroku.com/addons/rediscloud
You can read more about the file system here
I am working on Phonegap android app which should take the content from my remote server.
After searching the things I found the 2 ways of getting the contents from remote server to phonegap App :
1. Getting the content using Ajax call to remote server by returning
the json data from remote server PHP file.
2. Getting complete HTML page from remote server using Ajax.
If i am going to implement one of the above, my app is going to send the request each and every time while loading the page which i think not a good idea.
I know very well how to implement above mentioned option in my App.
but i wanted to know which one is efficient.
How i can accomplished this?
I am also using the Jquery mobile.
I am working on Android app that should simulate browser request, load reasons.
I have successfully recorded all the traffic on the device.
My question:
Could I start WebKit engine and send URL to start navigate, I doesn't need the response to be rendered or to see the browser at all?
Flow:
start WebKit engine without UI.
use WebKit API to start navigate.
get response saved in file/DB/or any other storage.
Is that Possible?
Depends exactly what you want and what your requirements are.
If you want to just request a URL via HTTP and retrieve the result, you could use HttpGet.
If you want to simulate fetching a page, as a browser would - including fetching all images, stylesheets, scripts and other data on it - you could use an invisible WebView
I need help figuring out the best, cross-browser compatible way to "SAVE" user input and STORE them locally(offline mod) AND on a server(online). Program will be used by Android and iOS.
I want to know the best way to track user progress while the device is online OR offline.
Hello I have been researching AJAX, JSON, XMLHttpRequest, REST, Java, and HTML5 (specifically, localStorage).
The scenario: (Read a book online/offline, save page progress)
A user logs in to a Web Service and the Web Service allows the user to download an "html webpage book" (view with HTML5 browser).
After every page turn, a REST API uses a GET request to post the Progress data to a Web Server. Simultaneously, a JSON string is created and saved in a file on the server. (let's say "ProgressData.txt")
In the background, a separate "copy" of ProgressData.txt is saved LOCALLY on the mobile device. The user then leaves the internet connection and continues to read the HTML Book.
When the user regains connectivity, the ProgressData.txt is uploaded to the server using a REST API where it will update the old server file with the NEW .txt file with all of the user ProgressData.
Possible solutions:
HTML5 localStorage solution looks good. jQuery even simplifies it:
http://plugins.jquery.com/project/html5Storage
Straight Javascript looks good for Server-Side storage, however it doesn't have access to a mobile device's physical hard-drive, thus preventing any kind of offline saving.
Java applets look possible. Plus not sure how Java runs with Android/iOS.
I don't want to have to run a localhost(PHP/Apache/Python) from a mobiledevice every time the user goes offline, however that may be where the solution lies. I did stumble on this powerful tool: http://couchdb.apache.org/
Question:
I need to know the best way to track user progress while the device is online OR offline. What is the best way to do this?
I stumbled across store.js the other day which might help solve the cross browser local storage. It was from this article about local storage.
I think your best option for tracking online/offline is to ping the server via an AJAX call when the page is turned. Always try and update the server on a page turn, but if it fails, handle the failure and store the progress locally. Each page turn will either amend the locally stored progress file or if connection is restored then simply update the server with the progress.
The issue I am thinking might occur is if a book is finished offline then there are no more clicks that would trigger the syncing, regardless of a restored connection. You may want to think about a manual sync link/button at the end of a book. Or maybe have a manual sync available at all times anyway? Give some control to the users and describe the whole offline/online reading scenario. You might find that it is easier to just let the users do the work… if they don't sync then it's their problem!
Here are 2 screencasts what will help you with your problem.
They are in Ruby on Rails but maybe you can get the idea. It is using the html5 cache manifest.
Hope it will help you!
http://railscasts.com/episodes/247-offline-apps-part-1
http://railscasts.com/episodes/248-offline-apps-part-2
some more resources (sorry i dont have experiences myself with html5 cache manifest)
http://diveintohtml5.ep.io/offline.html
http://developer.apple.com/library/safari/#documentation/iPhone/Conceptual/SafariJSDatabaseGuide/OfflineApplicationCache/OfflineApplicationCache.html
I'd suggest just using a cookie to store the current state. That way it is automatically sent to your server with every user request (so no need to build out a custom server-side API for receiving the state after a lost connection, and no need to have any custom client-side code for sending the data to the server), and still updateable even if the user has lost Internet connectivity. Also it doesn't rely on HTML5 features, so you don't need to restrict people to HTML5-capable browsers.
In any case, the best way to handle storing the current state would be to have a simple onclick handler on your "next page" link (or button, or whatever it is) that calls a function and sets the cookie value to whatever the current position is. Note that because the state is always available client-side, and sent to the server on every request, there is no need to maintain any explicit copy of the state server-side, unless you want to be able to remember the user's place even when they manually delete their cookies (which is overkill in my opinion).
You may want to look at the W3C Example Code for setting/getting cookie values in JavaScript.
Also, here's a website that demonstrates functionality similar to what you want to build. It uses cookies to keep track of a user's place when reading various webcomics. Pretty much the same as what it sounds like you want, except with comics instead of books.
It would be wise to track the progress in both a server side database and in the client's local storage if a constant internet connection is not necessary.
Evercookie is a controversial javascript api that aims to provide local storage using any means available including standard cookies, Flash shared object, Silverlight, browser history and HTML 5 storage. Data should persist when the user is offline and when the connection is restored, sync the cookie and database with whichever data has greater page number for the given book. Droid has Flash and the Flash shared object data is a "cookie" available to both desktop and web-based apps.
With great power comes great responsibility:
http://samy.pl/evercookie/