Quantcast
Channel: Questions in topic: "ios"
Viewing all articles
Browse latest Browse all 4709

Saving Data on IOS & retaining that saved data over updates.

$
0
0
Hey Everyone, Thankyou so much for looking at my post. I have been having a mental problem for a few weeks now and i cant seem to get past it. Currently i have an ios game on the cusp of release, The the problem i am having is i have no idea how to save data so that if someone deletes the app or updates it with a new version there information remains, and is reloaded into the game. Currently i am using a singleton design pattern for saving data. Heres the code i am using for that: using UnityEngine; using System.Collections; using System; using System.Runtime.Serialization.Formatters.Binary; using System.IO; public class DataManagement : MonoBehaviour { public static DataManagement datamanagement; public int highScore; public int spaceCash; public int playerSuitColor; void Awake() { if (datamanagement == null){ DontDestroyOnLoad(gameObject); datamanagement = this; } else if (datamanagement != this) { Destroy(gameObject); } } public void SaveData() { BinaryFormatter BinForm = new BinaryFormatter(); // creates a new variabe called "BinForm" that stores a "binary formatter" in charge of writing files to binary FileStream file = File.Create(Application.persistentDataPath + "/gameInfo.dat"); //creates a file gameData data = new gameData(); //creates a new container "data" and stores the "gamedata" class in it data.highScore = highScore; //acceses highScore from the "gameData" class and sets it to the public INT highScore data.spaceCash = spaceCash; //acceses spaceCash from the "gameData" class and sets it to the public INT spaceCash data.playerSuitColor = playerSuitColor; BinForm.Serialize (file, data); // writes the "data" container to the file file.Close(); // closes file //Debug.Log ("Data Saved!"); } public void LoadData() { if (File.Exists (Application.persistentDataPath + "/gameInfo.dat")) { BinaryFormatter BinForm = new BinaryFormatter(); //creates a new variabe called "BinForm" that stores a "binary formatter" in charge of writing files to binary FileStream file = File.Open (Application.persistentDataPath + "/gameInfo.dat", FileMode.Open); // if the file already exists it opens that file gameData data = (gameData)BinForm.Deserialize(file); // deserialized the file and casts it to something we can understand (gamedata)binForm file.Close(); // closes file highScore = data.highScore; spaceCash = data.spaceCash; playerSuitColor = data.playerSuitColor; //Debug.Log ("Data Loaded!"); } } } [Serializable] class gameData { public int playerSuitColor; public int highScore; public int spaceCash; } As you can see the Information that i am trying to save is just 3 simple integers "highScore", "spaceCash" and "playerSuitColor". I am planning on using "IOSNative" for "icloud", "in app purchases" and "gamecenter". **I cannot seem to find the best method for saving data that will not be lost when someone either deletes the app then re downloads it, or updates it too a newer version.** as you can, tell this is a huge problem because i cant release version 1.0 until i have it sorted because if i decide to update the game there could be no way to access the saved data on version 1.0 and transfer it to version 1.1, so someone might get allot of "spaceCash" or a great "highScore" only to have it deleted when they update the game... GRRR. would i use iCloud? if so how would i access the information when the next version comes out? Can i update only certain files when someone updates the app, keeping the "Datamanagement" class? Could i save that Data Online? if so whats the best way to do that? what is the standardised approach for such a task??? If anyone has any experience in any of these areas of IOS development and could shed some light that would be incredibly helpful. Thank you so much for reading this far... haha, and thank you for any suggestions. :)

Viewing all articles
Browse latest Browse all 4709

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>