How to save Data from HTTPRequest for offline use

  1. 3 months ago

    Hello Creo's

    I need to load data from HTTPRequest (for example from Spotify) and make it available when device offline
    maybe we could use HTTPRequest than SQLite to save data but I need to know how we connect them together

    Thanks in advance

  2. 2 months ago

    marco

    Jul 10 Administrator User since 2016

    Hi @Roayati can you please let us know what kid of data are you trying to get from Spotify?

  3. I need to save song information such us (name, artist, album .. etc) and save to for Offline use

  4. 8 weeks ago

    @marco ?!

  5. marco

    Jul 24 Administrator User since 2016

    You can save all that information in a sqlite database.
    Do you have a sample project to show me?

  6. @marco I have attached iTunes search, I need to save data as offline , so whenever I open app in offline it show the data

    Thanks @marco

  7. 7 weeks ago

    @marco !?

  8. marco

    Aug 1 Administrator User since 2016
    Edited 7 weeks ago by marco

    In Request -> NewValue event write the following code:

    var n = value["resultCount"];
    var r = value["results"];
    for (var entry in r) {
    	var artistId = entry["artistId"];
    	var artistName = entry["artistName"];
    	var trackName = entry["trackName"];
    	Console.write("\(artistName) \(trackName)");
    }

    entry is a dictionary extracted from the JSON result set, and each key of the dictionary corresponds to the key of the JSON result (that you can see from the preview panel).

    Once you extracted the fields you are interested on then you can serialise them to an sqlite database and then reuse it when network connection if off.

    Please note that in order to trigger the NewValue event one the simulator you have to pull to refresh the tableView (issue will be fixed in the next version). This trick is not necessary on a real device.

or Sign Up to reply!