Skip to content

Instantly share code, notes, and snippets.

@amay077
Last active September 8, 2017 10:20
Show Gist options
  • Save amay077/5465967 to your computer and use it in GitHub Desktop.
Save amay077/5465967 to your computer and use it in GitHub Desktop.
Xamarin.Android/iOS で IsolatedStorage を使う ref: http://qiita.com/amay077/items/672aaf058357a4ecf8a5
using System;
using System.Drawing;
using MonoTouch.Foundation;
using MonoTouch.UIKit;
using System.IO.IsolatedStorage;
using System.IO;
namespace IsolatedStorageiOSTest
{
public partial class IsolatedStorageiOSTestViewController : UIViewController
{
public IsolatedStorageiOSTestViewController() : base ("IsolatedStorageiOSTestViewController", null)
{
}
public override void DidReceiveMemoryWarning()
{
// Releases the view if it doesn't have a superview.
base.DidReceiveMemoryWarning();
// Release any cached data, images, etc that aren't in use.
}
public override void ViewDidLoad()
{
base.ViewDidLoad();
var file = IsolatedStorageFile.GetUserStoreForApplication();
// 分離ストレージにtest.txtというファイルを作成しストリームを開く
using (IsolatedStorageFileStream strm = file.CreateFile("test.txt"))
using (StreamWriter writer = new StreamWriter(strm))
{
// データを書き込む
writer.Write("Hello!");
writer.Write("Storage.");
}
}
public override bool ShouldAutorotateToInterfaceOrientation(UIInterfaceOrientation toInterfaceOrientation)
{
// Return true for supported orientations
return (toInterfaceOrientation != UIInterfaceOrientation.PortraitUpsideDown);
}
}
}
using System;
using Android.App;
using Android.Content;
using Android.Runtime;
using Android.Views;
using Android.Widget;
using Android.OS;
using System.IO.IsolatedStorage;
using System.IO;
namespace IsolatedStorageTest
{
[Activity (Label = "IsolatedStorageTest", MainLauncher = true)]
public class Activity1 : Activity
{
int count = 1;
protected override void OnCreate(Bundle bundle)
{
base.OnCreate(bundle);
// Set our view from the "main" layout resource
SetContentView(Resource.Layout.Main);
var file = IsolatedStorageFile.GetUserStoreForApplication();
// 分離ストレージにtest.txtというファイルを作成しストリームを開く
using (IsolatedStorageFileStream strm = file.CreateFile("test.txt"))
using (StreamWriter writer = new StreamWriter(strm))
{
// データを書き込む
writer.Write("Hello!");
writer.Write("Storage.");
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment