How to get values passed from URL scheme after opening the Unity app?

こ雲淡風輕ζ 提交于 2019-12-13 04:17:40

问题


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.

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.

Another code I came across is

-(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];
    }
 }

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.


回答1:


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

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.

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.

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



来源:https://stackoverflow.com/questions/54455339/how-to-get-values-passed-from-url-scheme-after-opening-the-unity-app

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!