I have two methods `SaveToiCloud` and `GetFromiCloud` that are doing what they say. I removed on purpose any null checks to see if the try and catch could do their job alone. However in Unity it is not crashing but when I build it to swift it is. "terminating with uncaught exception of type NSException
(lldb) " . I thought I'am catching every exception... Also the crash ONLY happens when I first try to get the value (this is not giving me an error!) and then try to save it (this is). I think this is because I'am setting the value to null with `GetFromiCloud`, but then again I thought the exception should be catched.
public void SaveToiCloud()
{
try
{// all variables are stored on GlobalD. with default value assigned to them
level = GlobalData.instance.level;
health = GlobalData.instance.health;
doorOpen = GlobalData.instance.doorOpen;
nameplayer = GlobalData.instance.nameplayer;
IntToDictionary(); //I have made sure no keys are overriding
StringToDictionary();
BoolToDictionary();
iCloudSaveValue();
}
catch (System.Exception ex)
{//Unity is successfully showing me this exception without crashing/quitting
Debug.Log(ex);
Debug.Log(ex.Message);
Debug.Log(ex.StackTrace);
}
}
public void GetFromiCloud()
{
try
{
GetIntFromiCloudDic();
GetStringFromiCloudDic();
GetBoolFromiCloudDic();
GlobalData.instance.level = level;
GlobalData.instance.health = health;
GlobalData.instance.doorOpen = doorOpen;
GlobalData.instance.namePlayer = namePlayer;
SaveSystem4.SavingToFile();
}
catch (System.Exception ex)
{
Debug.Log(ex);
Debug.Log(ex.Message);
Debug.Log(ex.StackTrace);
}
public void iCloudSaveValue()
{
foreach (KeyValuePair pair in DicInt)
{
bool success = iOSPlugin.iCloudSaveIntValue(pair.Key, pair.Value);
if (success)
{
iOSPlugin.ShowAlert("iCloud Value Saved Success", pair.Value.ToString());
}
else
{
iOSPlugin.ShowAlert("iCloud Value Saved failed", pair.Value.ToString());
}
}
void GetIntFromiCloudDic()
{
try
{
level = iOSPlugin.iCloudGetIntValue("Level"); // I know I should use null check
health = iOSPlugin.iCloudGetIntValue("Health");
}
catch
{
iOSPlugin.ShowAlert("iCloud Value", string.IsNullOrEmpty(nameplayer) ? "Nothing Saved Yet..." : level.ToString());
iOSPlugin.ShowAlert("iCloud Value", string.IsNullOrEmpty(nameplayer) ? "Nothing Saved Yet..." : health.ToString());
}
}
↧