Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
1
Question by taku0812 · Mar 04, 2014 at 05:26 AM · applicationbrowser

Launched from a browser

I want to start the app, passing arguments (such as URL) from the browser.

But I do not know how.

Please tell me What is the way.

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

1 Reply

· Add your reply
  • Sort: 
avatar image
8

Answer by whydoidoit · Mar 04, 2014 at 07:31 AM

EDIT: Don't know why I thought you wanted this for IOS - must have been reading something else. Please ignore if you do not.

ON IOS

You have to modify the XCode project to achieve this and add a entry to the info.plist plus handle the code on app launching.

This defines a URL scheme for radicalWords which you use in a link as radicalWords://someparameters

The following is at the bottom of my info.plist just before the last tag

    <key>CFBundleURLTypes</key>    
    <array>
     
     <dict>
         
         <key>CFBundleURLName</key>
         
         <string></string>
         
         <key>CFBundleURLSchemes</key>
         
         <array>
             
             <string>radicalWords</string>
             
         </array>
         
     </dict>
     
 </array>



Then you need to register your own app controller to take the initial parameters - this is achieved by putting the definition in Plugins/IOS in your project - I'll list it at the bottom. My version calls a method on a game object called !URLSchemeHandler (which must be available in the first scene) - the method is OnOpenWithUrl and it takes a string parameter of the url passed in which I then parse in C#.

MyAppController.m

 #import <UIKit/UIKit.h>
 #import "UnityAppController.h"
 
 @interface MyAppController : UnityAppController
 {
 }
 
 - (BOOL)application:(UIApplication*)application didFinishLaunchingWithOptions:(NSDictionary*)launchOptions;
 
 - (void) openURLAfterDelay:(NSURL*) url;
 
 -(BOOL) application:(UIApplication *)application handleOpenURL:(NSURL *)url;
 
 -(BOOL) application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation;
 
 @end
 @implementation MyAppController
 
 - (BOOL)application:(UIApplication*)application didFinishLaunchingWithOptions:(NSDictionary*)launchOptions
 {
     [super application:application didFinishLaunchingWithOptions:launchOptions];
     
     if ([launchOptions objectForKey:UIApplicationLaunchOptionsURLKey]) {
         NSURL *url = [launchOptions objectForKey:UIApplicationLaunchOptionsURLKey];
         
         [self performSelector:@selector(openURLAfterDelay:) withObject:url afterDelay:2];
     }
 
     return YES;
 }
 
 - (void) openURLAfterDelay:(NSURL*) url
 {
     
     UnitySendMessage("!URLSchemeHandler", "OnOpenWithUrl", [[url absoluteString] UTF8String]);
 }
 
 -(BOOL) application:(UIApplication *)application handleOpenURL:(NSURL *)url
 {
     
     UnitySendMessage("!URLSchemeHandler", "OnOpenWithUrl", [[url absoluteString] UTF8String]);
     
     return YES;
     
 }
 
 
 -(BOOL) application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation
 
 {
     UnitySendMessage("!URLSchemeHandler", "OnOpenWithUrl", [[url absoluteString] UTF8String]);
     return YES;
     
 }
 @end
 
 
 
 IMPL_APP_CONTROLLER_SUBCLASS(MyAppController)
Comment
Add comment · Show 7 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image taku0812 · Mar 04, 2014 at 12:44 PM 0
Share

Thank you for your answer.

I will be helpful.

avatar image JaviTheGreat · Aug 24, 2016 at 12:27 AM 0
Share

Thanks a lot!

avatar image SweatyChair · Apr 28, 2017 at 11:47 AM 0
Share

I don't need this for now but sure to vote up if that's working, so there's no way in Android yet right?

avatar image RunSwimFly SweatyChair · Aug 01, 2017 at 02:57 PM 2
Share

I'm using this for Android: https://www.assetstore.unity3d.com/en/#!/content/30430

avatar image stefanob · Jun 15, 2017 at 02:01 PM 0
Share

Thanks so much! The only detailed example I could find. Works perfectly!

avatar image RunSwimFly · Aug 01, 2017 at 02:53 PM 1
Share

Thanks for your answer, saved a number of people a lot of headaches. I've been using it for a while. Just recently I made a change which increased my frequency of cold starts compared to background resumes and I noticed that, for my code at least, openURLAfterDelay was failing to message Unity.

I think it's because, despite the delay, the Unity object doesn't exist or isn't being found. Anyway, this mod worked for me:

 NSURL *launchURL = NULL;
 
 - (BOOL)application:(UIApplication*)application didFinishLaunchingWithOptions:(NSDictionary*)launchOptions
 {
    [super application:application didFinishLaunchingWithOptions:launchOptions];
     
     if ([launchOptions objectFor$$anonymous$$ey:UIApplicationLaunchOptionsURL$$anonymous$$ey]) {
         NSURL *url = [launchOptions objectFor$$anonymous$$ey:UIApplicationLaunchOptionsURL$$anonymous$$ey];
         launchURL = url;
     }
     
     return YES;
 }
 
 extern "C" void _startURL()
 {
     if (launchURL!=NULL)
         UnitySend$$anonymous$$essage("!URLSchemeHandler", "OnOpenWithUrl", [[launchURL absoluteString] UTF8String]);
 }
 

And I call _startURL from the Start method in my URLSchemeHandler script.

Show more comments

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

26 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

How to create a complicated game over scenario ? HELP 0 Answers

A node in a childnode? 1 Answer

Help on Jumping 1 Answer

is the unity player browser specific? 1 Answer

Can't find MonoDevelop. Unity 4.5.2 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges