附录5.Lobi资料翻译
此文档为Lobi资料的中文翻译
Last updated
Was this helpful?
此文档为Lobi资料的中文翻译
Last updated
Was this helpful?
请检测用户手机中有没有安装Lobi app
参照下面的【代码部分】
lobi://game_community?gameId=<游戏页面ID>&backScheme=<能启动游戏的scheme>
https://web.lobi.co/game/<游戏页面ID>?backScheme=<能启动游戏的scheme>
参考地址: https://github.com/kayac/Lobi/wiki/Lobi-OfficialCommunity
iOS9以后,为了启动Lobi App,需要在Info.plist的LSApplicationQueriesSchemes中添加lobi
Android不需要额外操作
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];
}
}