代码拉取完成,页面将自动刷新
同步操作将从 xuefei/SchemeDemo 强制同步,此操作会覆盖自 Fork 仓库以来所做的任何修改,且无法恢复!!!
确定后同步将在后台操作,完成时将刷新页面,请耐心等待。
唤端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
#import "UnityAppController.h"
NSString *URLString = @"";
// 向Unity传递参数;
extern void UnitySendMessage(const char *, const char *, const char *);
//添加的代码
- (BOOL)application:(UIApplication *)app openURL:(NSURL *)url options:(NSDictionary<NSString *,id> *)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端代码
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<AndroidJavaObject>("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
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。