Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by davidc · Apr 21, 2014 at 06:02 AM · iosloadsavingsingleton

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

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. :)

Comment
Add comment · Show 5
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Stamblew · Oct 31, 2017 at 12:38 PM 0
Share

Hi, @davidc I am facing the same problem now, did you find any solutions for this approach? I found out that Google provides a plugin for Unity in order to save data in the cloud using Play Games Services. However, I have had no luck on finding the same thing for iOS.

avatar image tmalhassan Stamblew · Oct 31, 2017 at 01:07 PM 0
Share

Using PlayerPrefs will save your data between updates. I suggest using it if you're willing to change your code.

avatar image Stamblew tmalhassan · Oct 31, 2017 at 01:25 PM 0
Share

@tmalhassan Right, but I wanted to store game data in the cloud, so the player can continue where s(he) left off, i.e. if s(he) reinstalls the app or wants to play on another device.

Show more comments

0 Replies

· Add your reply
  • Sort: 

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

22 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

The name 'Joystick' does not denote a valid type ('not found') 2 Answers

The best way to save and load data for mobile in unity ? 1 Answer

Facebook unity sdk: is it possible to send friend invites/app requests to non app users ? 1 Answer

using non static variable in static function 1 Answer

Save Gif to Photo Gallery from Persistent Path - iOS Android 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges