# SchemeDemo **Repository Path**: kerwinzxc/SchemeDemo ## Basic Information - **Project Name**: SchemeDemo - **Description**: 唤端Demo,网页链接打开App - **Primary Language**: C# - **License**: Not specified - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 6 - **Created**: 2019-03-18 - **Last Updated**: 2020-12-19 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # SchemeDemo #### 介绍 唤端Demo,网页链接打开App,获取启动参数 AndroidPlugin AndroidStudio 工程(版本3.2.1) UnityClient Unity 工程(版本2017.4.10f1) Web 网页端 测试地址https://www.ganghood.net.cn/SchemeDemo.html 目前只有安卓 2019.3.7 iOS 也OK 2019.3.8 对于iOS端: 1、设置Identifler和URL Schemes 2、修改导出的Xcode工程中的UnityAppController.mm ```Object-C #import "UnityAppController.h" NSString *URLString = @""; // 向Unity传递参数; extern void UnitySendMessage(const char *, const char *, const char *); //添加的代码 - (BOOL)application:(UIApplication *)app openURL:(NSURL *)url options:(NSDictionary *)options { URLString = [url absoluteString]; return YES; } - (BOOL)application:(UIApplication*)application openURL:(NSURL*)url sourceApplication:(NSString*)sourceApplication annotation:(id)annotation { //添加的代码 URLString = [url absoluteString]; return YES; } extern "C" { void _GetLaunchInfo(); } void _GetLaunchInfo() { UnitySendMessage( "Main Camera", [@"OnLaunchInfo" UTF8String], [URLString UTF8String] ); // 清空,防止造成干扰; URLString = @""; } ``` 3、Unity端代码 ```Csharp using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI; #if UNITY_IOS using System.Runtime.InteropServices; #endif public class SchemeDemo : MonoBehaviour { public Text text; // Use this for initialization void Start() { GetInfo(); } // Update is called once per frame void Update() { } public void OnLaunchInfo(string launchInfo) { Debug.LogError("launchInfo:" + launchInfo); text.text = launchInfo; } public void GetInfo() { #if UNITY_ANDROID AndroidJavaClass jc = new AndroidJavaClass("com.unity3d.player.UnityPlayer"); AndroidJavaObject jo = jc.GetStatic("currentActivity"); jo.Call("getLaunchInfo"); #elif UNITY_IOS _GetLaunchInfo(); #endif } private void OnApplicationFocus(bool focus) { Debug.LogError("focus:" + focus); if (true) { GetInfo(); } } #if UNITY_IOS [DllImport("__Internal")] private static extern void _GetLaunchInfo(); #endif } ``` 当安卓onResume时获取参数 2019.3.14