Added contains and clear implementations for iOS Settings

This commit is contained in:
Kyle Spearrin 2016-12-26 10:49:34 -05:00
parent ce8bedb340
commit 17e18a2a7a

View file

@ -1,5 +1,4 @@

using System;
using System;
#if __UNIFIED__
using Foundation;
#else
@ -230,6 +229,50 @@ namespace Bit.iOS.Core.Services
}
}
}
/// <summary>
/// Clear all keys from settings
/// </summary>
public void Clear()
{
lock(locker)
{
var defaults = _defaults;
try
{
defaults.RemovePersistentDomain(NSBundle.MainBundle.BundleIdentifier);
defaults.Synchronize();
}
catch(Exception ex)
{
Console.WriteLine("Unable to clear all defaults. Message: " + ex.Message);
}
}
}
/// <summary>
/// Checks to see if the key has been added.
/// </summary>
/// <param name="key">Key to check</param>
/// <returns>True if contains key, else false</returns>
public bool Contains(string key)
{
lock(locker)
{
var defaults = _defaults;
try
{
var nsString = new NSString(key);
var setting = defaults.ValueForKey(nsString);
return setting != null;
}
catch(Exception ex)
{
Console.WriteLine("Unable to clear all defaults. Message: " + ex.Message);
}
return false;
}
}
}
}