How to launch my game with start-up parameter

1 favourites
  • 2 posts
From the Asset Store
75 power-up sound effects; bonus and notification sounds, fanfares, harp glissandi, stabs, clock ticks, etc.
  • I'm looking for a way to start my app with a start-up parameter.

    I want users of my app to be able to exchange a game-scenario via WhatsApp:

    - User 1 saves a game to my server. My server returns a unique value. The app on User 1's device copies a URL (to launch the app) and this unique value to a Whatsapp group.

    - User 2 opens the app by tapping the link in Whatsapp. The app retrieves the game-scenario from my server using the unique value.

    When I launch the game in a browser (e.g. mysite.nl/myapp?test=testing123) I can pick up the parameter without problems with QueryParam. But the QueryParam expression does not work when I build the app for iOS.

    Here is where I am stuck: How can I make my app aware of a start-up parameter on IOS.

    Thanks for any help!

    Tagged:

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • Hi,

    After a lot of trial and error I found a way how to do this for iOS

    In your app in Construct3 add a global variable to hold the URL string and a javascript line to read the URL that was used to launch your game:

    Export your game as iOS project and open it in XCode

    In the Info tab in XCode, add a URL type. For Indentifier use your app identifier in reverse domain name format, for example com.mydomain.myapp. For URL scheme use your app name, for example myapp.

    Now comes the tricky part. I'm open to better suggestions because my solution involves adding some code manually, and I realise this is not ideal.

    In CDVAppDelegate.m, in the function didFinishLaunchingWithOptions add this code (after the comment lines that are already there):

    This code defines a NSURL object (named url) that holds the URL that was used to start the app. If url is not empty, the URL parameterstring (url.query) is added to the startpage string as parameterstring.

    After building and installing on your device, you can now launch your app on your device using a URL with parameters, for example myapp://main?test=test123

    Because the Construct3 code is now launched with the URL parameters, the javascript code can pick up this string and you can use it in your application. In the example above it is added to a global variable.

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)