「Xamarin.Mac/カスタムURLスキームを利用する」の版間の差分
imported>Administrator ページの作成:「== 実装 == 以下でカスタムURLスキームが利用可能になる。 # Xamarin Studioでプロジェクト内の「Info.plist」を開く # 下部の「Advanced...」 |
|||
| (他の1人の利用者による、間の6版が非表示) | |||
| 1行目: | 1行目: | ||
[[Xamarin.Mac]]で[[カスタムURLスキーム]]を使いたい。 | |||
URLを叩くとアプリが起動するアレである。 | |||
[[Xamarin.iOS]]とは微妙に実装方法が異なる。 | |||
== 実装 == | == 実装 == | ||
=== カスタムURLスキームを有効にする === | |||
以下でカスタムURLスキームが利用可能になる。 | 以下でカスタムURLスキームが利用可能になる。 | ||
# Xamarin | # [[Xamarin Studio]]でプロジェクト内の「Info.plist」を開く | ||
# 下部の「Advanced」タブを開く | # 下部の「Advanced」タブを開く | ||
# URL Typesの「Add URL Type」ボタンを押す | # URL Typesの「Add URL Type」ボタンを押す | ||
#: まれにボタンを押しても何も起きない場合がある。その際はInfo.plistを閉じて再度開くと追加されている。 | |||
# 「Identifier」は何でもよい。アプリのIdentifierでも入れておく。 | # 「Identifier」は何でもよい。アプリのIdentifierでも入れておく。 | ||
# 「URL | # 「URL Schems」にURLスキーム名を入れる(例:monobook) | ||
=== カスタムURLスキームで呼ばれるメソッドを作る === | |||
次にカスタムURLスキームが叩かれた際に呼ばれるメソッドの登録と実装をする。 | |||
<source lang="csharp"> | <source lang="csharp"> | ||
using System; | using System; | ||
| 29行目: | 36行目: | ||
{ | { | ||
// URLスキームで呼ばれるメソッドを指定する。 | // URLスキームで呼ばれるメソッドを指定する。 | ||
// Export("handleGetURLEvent:withReplyEvent:")属性が付いたメソッドが呼ばれる。 | |||
var appleEventManager = NSAppleEventManager.SharedAppleEventManager; | var appleEventManager = NSAppleEventManager.SharedAppleEventManager; | ||
appleEventManager.SetEventHandler(this | appleEventManager.SetEventHandler(this | ||
| 56行目: | 64行目: | ||
; | ; | ||
// ブレークポイント挿入用 | |||
Console.WriteLine(parameters); | Console.WriteLine(parameters); | ||
} | } | ||
/// <summary> | /// <summary> | ||
/// Xamarin. | /// NSAppleEventDescriptorのParamDescriptorForKeywordメソッドに指定する定数。 | ||
/// Xamarin.Macに定数らしきものが見当たらなかったのでxcode眺めつつ作った。 | |||
/// </summary> | /// </summary> | ||
public static class AEKeyword | public static class AEKeyword | ||
| 85行目: | 95行目: | ||
} | } | ||
</source> | </source> | ||
=== デバッグ === | |||
ターミナルでopenコマンドを叩けば簡単に[[デバッグ]]できる。openの引数(URLスキーム)にアンパサンド(&)を含む場合はダブルクォーテーション(")で囲むこと。 | |||
open "monobook://" | |||
open "monobook://inbox" | |||
open "monobook://inbox?sort=date" | |||
open "monobook://inbox?sort=date&filter=abc" | |||
== 関連項目 == | == 関連項目 == | ||
* [[Xamarin.iOS/カスタムURLスキームを利用する]] | |||
== 参考文献 == | == 参考文献 == | ||