打开Unity应用后如何从URL方案获取值? [英] How to get values passed from URL scheme after opening the Unity app?

查看:933
本文介绍了打开Unity应用后如何从URL方案获取值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

虽然我在阅读中阅读了尚未在Unity中实现的功能,但可能会在Unity的未来版本中实现.我在ipad的Safari中打开该链接时,我得到了一个链接(coar://mylink.com/id=12345)打开了我的Unity应用程序.如何从Unity中的此链接获取ID值12345.我们是否需要插件?还有其他替代方法吗?

While searching I read this feature is not yet implemented in Unity may be in future version Unity might bring it.I got a link(coar://mylink.com/id=12345) when opened in Safari in my ipad it opened up my Unity app.How to get the id value 12345 from this link in Unity.Do we need plugin?Any other alternate simple method.

在播放器设置中,有一个支持URL方案的选项,可用于我们的目的. 我引用了一些链接.链接1 链接2 .在第二个链接中放置代码的位置.任何分步说明都将有所帮助.

In player settings there is an option for supported URL schemes any use for our purpose. There are some links I refered.Link 1 Link 2.In the second link where to place the code.Any step by step explanation will be helpful.

我遇到的另一个代码是

-(BOOL) application:(nonnull UIApplication *)application openURL:(nonnull NSURL *)url options:(nonnull NSDictionary<NSString *,id> *)options {


if([url.absoluteString rangeOfString:@"mygame://text="].location != NSNotFound){
   [[NSUserDefaults standardUserDefaults] setObject:url.absoluteString forKey:@"myurl"];
   [[NSUserDefaults standardUserDefaults] synchronize];
    }
 }

从上面我了解到,数据是存储在"myurl"键中的playerprefs中的.但是,确切地将代码粘贴到什么地方?没有头绪.如何使用C#代码检索myurl.

From the above what I understand is the data is stored in playerprefs in the "myurl" key.But where exactly to paste the code?No clue.How to retrieve the myurl using C# code.

推荐答案

是的,一个插件,我认为第一个链接中的教程已经足够详细了.

Yes, a plugin, and the tutorial in the first link I think is detailed enough.

对于第二个链接,请首先构建您的项目,然后统一将生成一个Xcode项目.在 Classes 文件夹中找到 UnityAppController.mm ,然后在文件末尾添加功能.

For the second link, first build your project and unity will generate a Xcode project. Find UnityAppController.mm, may inside Classes folder, then add the function at the end of the file.

第一个链接中提到了另一个选项,在您的 Assets/Plugins/iOS/文件夹中创建一个mm文件,包括 UnityAppController.h ,然后添加应用程序其中的handleOpenURL 函数.

Another option is mentioned from the first link, create a mm file in your Assets/Plugins/iOS/ folder, include UnityAppController.h then add application handleOpenURL function in it.

如果您想知道如何将数据从OC传递到C#,我有

If you want to know how to pass the data from OC to C#, I have an answer from another post.

这篇关于打开Unity应用后如何从URL方案获取值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆