はじめに
ここでは、Xamarin Studio で /n software の Xamarin エディション ツールキットを使用する方法について説明します。このツールキットは、Xamarin コンポーネント パッケージ (.xam) としてXamarin Component Store からインストールできます。
Android
Xamarin Studio でコンポーネントを使用するには、Xamarin Component Store からツールキットをインストールするか、Xamarin コンポーネント パッケージ (.xam) を手動でインストールします。手動でインストールするには、まず Xamarin の提供する xamarin-component tool をダウンロードし、次のコマンドを実行します。
xamarin-component.exe install nsoftware.IPWorks-9.0.xam
コンポーネントをプロジェクトに追加する
Xamarinコンポーネント パッケージをインストールすると、Xamarin Studio からツールキットにアクセスできます。プロジェクト内でコンポーネントを選択するには、[Components] を右クリックし、[Edit Components] を選択します。
新しく追加したコンポーネントが [Components] リストに表示され、コード内で使用できるようになります。
コンポーネントの使い方の詳細は、サンプル プロジェクトを参照してください。以下は、よく使われる非常にシンプルなコード スニペットの一例です。
using System; using Android.App; using Android.Content; using Android.Runtime; using Android.Views; using Android.Widget; using Android.OS; using nsoftware.IPWorks; namespace nsoftware.HttpurlDemo { [Activity (Label = "HttpurlDemo", MainLauncher = true)] public class MainActivity : Activity { protected override void OnCreate (Bundle bundle) { base.OnCreate (bundle); // Set our view from the "main" layout resource SetContentView (Resource.Layout.Main); // Get our button from the layout resource, // and attach an event to it Button goButton = FindViewById<Button> (Resource.Id.GoButton); EditText txtResponse = FindViewById<EditText> (Resource.Id.txtResponse); EditText txtURL = FindViewById<EditText> (Resource.Id.urlField); goButton.Click += (object sender, EventArgs e) => { try{ Http http = new Http(this); http.Get(txtURL.Text); txtResponse.Text = http.TransferredData; } catch(Exception ex) { txtResponse.Text = "ERROR: " + ex.Message; } }; } } }
iOS
Xamarin Studio でコンポーネントを使用するには、Xamarin Component Store からツールキットをインストールするか、Xamarin コンポーネント パッケージ (.xam) を手動でインストールします。手動でインストールするには、まずXamarin の提供する xamarin-component toolをダウンロードし、次のコマンドを実行します。
mono xamarin-component.exe install nsoftware.IPWorks-9.0.xam
コンポーネントをプロジェクトに追加する
Xamarinコンポーネント パッケージをインストールすると、Xamarin Studio からツールキットにアクセスできます。プロジェクト内でコンポーネントを選択するには、[Components] を右クリックし、[Edit Components] を選択します。
新しく追加したコンポーネントが [Components] リストに表示され、コード内で使用できるようになります。
コンポーネントの使い方の詳細は、サンプル プロジェクトを参照してください。以下は、よく使われる非常にシンプルなコード スニペットの一例です。
using System; using System.Drawing; using MonoTouch.Foundation; using MonoTouch.UIKit; using nsoftware.IPWorks; namespace nsoftware.HttpurlDemo { public partial class httpurlViewController : UIViewController { Http http; public httpurlViewController (IntPtr handle) : base (handle) { http = new Http (this); } 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. } #region View lifecycle public override void ViewDidLoad () { base.ViewDidLoad (); // Perform any additional setup after loading the view, typically from a nib. var g = new UITapGestureRecognizer(() => View.EndEditing(true)); g.CancelsTouchesInView = false; //for iOS5 View.AddGestureRecognizer(g); } public override void ViewWillAppear (bool animated) { base.ViewWillAppear (animated); } public override void ViewDidAppear (bool animated) { base.ViewDidAppear (animated); } public override void ViewWillDisappear (bool animated) { base.ViewWillDisappear (animated); } public override void ViewDidDisappear (bool animated) { base.ViewDidDisappear (animated); } #endregion partial void btnGetClick (UIButton sender) { try{ http.Get(txtURL.Text); txtOutput.Text = http.TransferredData; } catch(Exception ex) { new UIAlertView("Error",ex.Message,null,"OK",null).Show(); } } } }
/n software 製品の詳細は、こちら をご覧ください。