Skip to content

Commit

Permalink
Fix platform storage for iOS
Browse files Browse the repository at this point in the history
  • Loading branch information
maxkatz6 committed Dec 6, 2023
1 parent 56bf74a commit 2d19718
Showing 1 changed file with 4 additions and 8 deletions.
12 changes: 4 additions & 8 deletions Solitaire/Utils/PlatformProviders.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,10 @@ private class DefaultSettingsStore<T> : IRuntimeStorageProvider<T>
public async Task SaveObject(T obj, string key)
{
// Get a new isolated store for this user, domain, and assembly.
var isoStore = IsolatedStorageFile.GetStore(IsolatedStorageScope.User |
IsolatedStorageScope.Domain |
IsolatedStorageScope.Assembly, null, null);
using var isoStore = IsolatedStorageFile.GetUserStoreForApplication();

// Create data stream.
await using var isoStream = new IsolatedStorageFileStream(Identifier + key, FileMode.Create, isoStore);
await using var isoStream = isoStore.OpenFile(Identifier + key, FileMode.CreateNew, FileAccess.Write);
await JsonSerializer.SerializeAsync(isoStream, obj, typeof(T), JsonContext.Default);
}

Expand All @@ -41,10 +39,8 @@ public async Task SaveObject(T obj, string key)
{
try
{
var isoStore = IsolatedStorageFile.GetStore(IsolatedStorageScope.User |
IsolatedStorageScope.Domain |
IsolatedStorageScope.Assembly, null, null);
await using var isoStream = new IsolatedStorageFileStream(Identifier + key, FileMode.Open, isoStore);
using var isoStore = IsolatedStorageFile.GetUserStoreForApplication();
await using var isoStream = isoStore.OpenFile(Identifier + key, FileMode.Open, FileAccess.Read);
var storedObj = (T?)await JsonSerializer.DeserializeAsync(isoStream, typeof(T), JsonContext.Default);
return storedObj ?? default;
}
Expand Down

0 comments on commit 2d19718

Please sign in to comment.