# 附录5.Lobi资料翻译

## 1.跳转参考图

![lobi redirect](/files/-LmIAf2CBwGzI6XmRfNO)

## 2.为了使【返回】按钮游戏有效，需要游戏有scheme，并且将Scheme作为参数传递过来。

## 3.Lobi App有没有安装的检测

请检测用户手机中有没有安装Lobi app

参照下面的【代码部分】

## 4.URL（参照上面1的参考图，需要实现①和②）

### ①游戏页面 URL Scheme

lobi://game\_community?gameId=<游戏页面ID>\&backScheme=<能启动游戏的scheme>

### ②游戏页面 Web URL

<https://web.lobi.co/game/><游戏页面ID>?backScheme=<能启动游戏的scheme>

## 【代码部分】

参考地址： <https://github.com/kayac/Lobi/wiki/Lobi-OfficialCommunity>

### 1.事前准备

* iOS9以后，为了启动Lobi App，需要在Info.plist的LSApplicationQueriesSchemes中添加lobi
* Android不需要额外操作

### 2.实例Demo

iOS部分

```
- (void)openOfficialCommunity
{
	// 请将<游戏页面ID>替换为Lobi团队给出的正确ID
	NSString *const officialCommunityUrlString       = @"https://web.lobi.co/special/community-lp/<游戏页面ID>";
	NSString *const officialCommunityUrlSchemeString = @"lobi://game_community?gameId=<游戏页面ID>";

	// Lobi初回起動時にゲームページヘ遷移するためにペーストボードを利用する。
 	UIPasteboard.generalPasteboard.string = @"{\"co.lobi.pasteboard.urlscheme\":\"lobi://game_community?gameId=<游戏页面ID>\"}";

 	NSURL *officialCommunityUrl       = [NSURL URLWithString:officialCommunityUrlString];
 	NSURL *officialCommunityUrlScheme = [NSURL URLWithString:officialCommunityUrlSchemeString];
     
 	if ([[UIApplication sharedApplication] canOpenURL:officialCommunityUrlScheme]) {
 		[[UIApplication sharedApplication] openURL:officialCommunityUrlScheme];
 	}
 	else {
 		[[UIApplication sharedApplication] openURL:officialCommunityUrl];
 	}
}
```

Android部分

```
/** Lobiチームよりご案内した <ゲームページID> を設定してください */
    private static final String LOBI_GAME_PAGE_ID = "<ゲームページID>";
    
    /** 公認コミュニティ Lobi web URL */
    private static final String LOBI_WEB_URL = "https://web.lobi.co/special/community-lp/%s";
    
    /** 公認コミュニティ URL Scheme */
    private static final String LOBI_URL_SCHEME = "lobi://game_community?gameId=%s";
    
    /** Lobiアプリのインストールチェックに使用するパッケージ情報 */
    private static final String LOBI_APP_PACKAGE = "com.kayac.nakamap";

    /**
     * 公認コミュニティページを表示する<br>
     * Lobiアプリがインストール済みであれば、Lobiアプリで、
     * Lobiアプリが未インストールであれば、Webブラウザで公認コミュニティを表示する
     *
     * @param context Activity Context
     */
    public static void openOfficialCommunity(Context context) {
        PackageManager packageManager = context.getPackageManager();
        Intent launchIntent = packageManager.getLaunchIntentForPackage(LOBI_APP_PACKAGE);

        String uri;
        if (launchIntent == null) {
            // Lobiアプリ未インストール
            uri = String.format(LOBI_WEB_URL, LOBI_GAME_PAGE_ID);
        } else {
            // Lobiアプリインストール済み
            uri = String.format(LOBI_URL_SCHEME, LOBI_GAME_PAGE_ID);
        }

        Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(uri));
        ContextCompat.startActivity(context, intent, null);
    }
```

Unity Demo

```
// コミュニティ遷移用ブリッジ
public class CommunityBridge : object {
 
	private void OpenOfficialCommunity_android() {
		using (AndroidJavaClass unityPlayer = new AndroidJavaClass("com.unity3d.player.UnityPlayer"))
		using (AndroidJavaObject currentActivity = unityPlayer.GetStatic<AndroidJavaObject>("currentActivity"))
		using (AndroidJavaObject packageManager = currentActivity.Call<AndroidJavaObject>("getPackageManager")) {
			AndroidJavaObject launchIntent = null;
			try {
				launchIntent = packageManager.Call<AndroidJavaObject>("getLaunchIntentForPackage", "com.kayac.nakamap");
			} catch(System.Exception ex) {
				// nothing to do
			}
            
			if (launchIntent == null) {
				// Lobi is not installed
				Application.OpenURL("https://web.lobi.co/special/community-lp/<ゲームページID>");
			} else {
				// Lobi is installed
				launchIntent.Dispose();
				using (AndroidJavaObject gamePageIntent = new AndroidJavaObject("android.content.Intent"))
				using (AndroidJavaClass uri = new AndroidJavaClass("android.net.Uri")) {
					gamePageIntent.Call<AndroidJavaObject>("setAction", "android.intent.action.VIEW");
					gamePageIntent.Call<AndroidJavaObject>("setData", uri.CallStatic<AndroidJavaObject>("parse", "lobi://game_community?gameId=<ゲームページID>"));
					currentActivity.Call ("startActivity", gamePageIntent);
				}
			}
		}
	}
 
	public static void officialCommunityHandler() {
		#if UNITY_ANDROID && !UNITY_EDITOR
		OpenOfficialCommunity_android();
		#endif
		#if ((UNITY_IOS || UNITY_IPHONE) && ! UNITY_EDITOR)
		OpenOfficialCommunity_ios();
		#endif
	}
 
	#if ((UNITY_IOS || UNITY_IPHONE) && ! UNITY_EDITOR)
	[DllImport("__Internal")]
	private static extern void OpenOfficialCommunity_ios();
	#endif
}
```

Unity iOS用的接口

```
void OpenOfficialCommunity_ios()
{
	// Lobiチームよりご案内した<ゲームページID>を設定してください。
	NSString *const officialCommunityUrlString       = @"https://web.lobi.co/special/community-lp/<ゲームページID>";
	NSString *const officialCommunityUrlSchemeString = @"lobi://game_community?gameId=<ゲームページID>";

	// Lobi初回起動時にゲームページヘ遷移するためにペーストボードを利用する。
 	UIPasteboard.generalPasteboard.string = @"{\"co.lobi.pasteboard.urlscheme\":\"lobi://game_community?gameId=<ゲームページID>\"}";

	NSURL *officialCommunityUrl       = [NSURL URLWithString:officialCommunityUrlString];
	NSURL *officialCommunityUrlScheme = [NSURL URLWithString:officialCommunityUrlSchemeString];
    
	if ([[UIApplication sharedApplication] canOpenURL:officialCommunityUrlScheme]) {
		[[UIApplication sharedApplication] openURL:officialCommunityUrlScheme];
	}
	else {
		[[UIApplication sharedApplication] openURL:officialCommunityUrl];
	}
}
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://cydonia.gitbook.io/doc/cydonia-sdk/ref/lobi.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
