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
2
Question by Reimus · Mar 08, 2015 at 06:22 AM · cloudwaitparseonapplicationquit

Update Parse.com Database OnApplicationQuit

I need to update the Database on Parse.com when a user quits the game. I have the inventory class check OnApplicationQuit() and when it does, it calls a SaveInventory function which saves to the Parse.com Database.

I know that the SaveInventory function works, if I call that at any point during the normal game, it saves as it should. When OnApplication is Called, Every Debug.Log in SaveInventory is called as it should be. Does anyone know how I can update the database when a user quits.

Here is my SaveInventory function:

 public void SaveInventory(DictionaryOfStringAndInt inventory) {
         Debug.Log("Save Starting");
         myInventory = inventory;
         inventoryData.SaveAsync().ContinueWith(t => {
             List<string> slots = new List<string>() {
                 "slot01", "slot02", "slot03", "slot04", "slot05", "slot06", 
                 "slot07", "slot08", "slot09", "slot10", "slot11", "slot12", 
                 "slot13", "slot14", "slot15", "slot16", "slot17", "slot18", 
                 "slot19", "slot20"
             };
             int slotsIndex = 0;
 
             inventoryData["coins"] = myInventory["coins"];
             foreach (KeyValuePair<string, int> item in myInventory) {
                 if (item.Key == "coins") continue;
                 
                 inventoryData[slots[slotsIndex] + "Name"] = item.Key;
                 inventoryData[slots[slotsIndex] + "Amount"] = item.Value;
                 Debug.Log(slots[slotsIndex] + "Name" +": " + item.Key + " - " + slots[slotsIndex] + "Amount" + ": " + item.Value);
                 slotsIndex++;
             }
 
             inventoryData.SaveAsync().ContinueWith(tt => {
                 Debug.Log("WHAT");
             });
             Debug.Log("Save Completed");
         });
     }
Comment
Add comment · Show 1
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 curiouspers · Mar 08, 2015 at 10:31 AM 0
Share

Have you tried to use OnDisable() ins$$anonymous$$d of OnApplicationQuit()?

1 Reply

· Add your reply
  • Sort: 
avatar image
1

Answer by urban2000 · Mar 08, 2015 at 05:29 PM

Hi,

I had the same issue with my Application (on Android). To get it to work I used OnApplicationPause instead.

 public void OnApplicationPause(bool pauseStatus)
 {
     if (pauseStatus == true)
     {
         SaveToParse();
     }
 }

However, I could not use the normal SaveAsync() API for saving. Instead I did a synchronous save through the REST API (https://parse.com/docs/rest).

In the synchronous save you have to upload your data as JSON.

 WebClient client = new WebClient();
 
 client.Headers.Add("X-Parse-Application-Id", ApplicationId);
 client.Headers.Add("X-Parse-REST-API-Key", RestApiKey);
 client.Headers.Add("Content-Type", "application/json");
 
 string json = yourParseObjAsJson;
 byte[] data = Encoding.UTF8.GetBytes(json);
 
 var uri = string.Format("https://api.parse.com/1/classes/{0}/{1}", obj.ClassName, obj.ObjectId);
     
 client.UploadData(uri, "PUT", data);
 


Comment
Add comment · Show 3 · Share
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 $$anonymous$$ · Aug 12, 2015 at 08:31 PM 0
Share

I've tried this too, but I alwas get this error:

System.Net.WebException: Error getting response stream (Write: The authentication or decryption has failed.): SendFailure ---> System.IO.IOException: The authentication or decryption has failed. ---> $$anonymous$$ono.Security.Protocol.Tls.TlsException: Invalid certificate received from server. Error code: 0xffffffff800b010a

avatar image urban2000 · Aug 12, 2015 at 08:52 PM 1
Share

You could ignore the SSL certificate validation by doing this.

 ServicePoint$$anonymous$$anager.ServerCertificateValidationCallback = (p1, p2, p3, p4) => true;
 
avatar image $$anonymous$$ · Aug 13, 2015 at 08:53 AM 0
Share

Thanks worked perfectly

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

23 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 avatar image

Related Questions

Unity Vs ParseCloud Vs Server 0 Answers

Cloud recognition in Vuforia 0 Answers

Parse and Unity on Windows Store App 1 Answer

Google Cloud Messaging for Android 1 Answer

Unity Cloud Build Android : Error installing bvr 0 Answers


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