title: URL schemes in Cocos Creator-written iOS game
body: <p>I am trying to implement URL schemes in my app, which I wrote in Cocos Creator 2.4.5 and then exported to XCode for iOS deployment. The app works fine, but I can't get URL schemes to work. I think it is a matter of Swift code vs. Objective C (both of which I am not very proficient at, as you can tell from me posting this).</p>
  <p>I'm trying to implement something like this</p>
  <pre><code>func application(_ application: UIApplication,
                   open url: URL,
                   options: [UIApplicationOpenURLOptionsKey : Any] = [:] ) -&gt; Bool {
  
      // Determine who sent the URL.
      let sendingAppID = options[.sourceApplication]
      print(&quot;source application = \(sendingAppID ?? &quot;Unknown&quot;)&quot;)
  
      // Process the URL.
      guard let components = NSURLComponents(url: url, resolvingAgainstBaseURL: true),
          let albumPath = components.path,
          let params = components.queryItems else {
              print(&quot;Invalid URL or album path missing&quot;)
              return false
      }
  
      if let photoIndex = params.first(where: { $0.name == &quot;index&quot; })?.value {
          print(&quot;albumPath = \(albumPath)&quot;)
          print(&quot;photoIndex = \(photoIndex)&quot;)
          return true
      } else {
          print(&quot;Photo index missing&quot;)
          return false
      }
  }
  
  
  </code></pre>
  <p>(following this doc: <a href="https://developer.apple.com/documentation/xcode/defining-a-custom-url-scheme-for-your-app" rel="nofollow noreferrer">https://developer.apple.com/documentation/xcode/defining-a-custom-url-scheme-for-your-app</a>)</p>
  <p>in my AppDelegate.cpp:</p>
  <pre><code>/****************************************************************************
   Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd.
  
   http://www.cocos.com
  
   Permission is hereby granted, free of charge, to any person obtaining a copy
   of this software and associated engine source code (the &quot;Software&quot;), a limited,
   worldwide, royalty-free, non-assignable, revocable and non-exclusive license
   to use Cocos Creator solely to develop games on your target platforms. You shall
   not use Cocos Creator software for developing other software or tools that's
   used for developing games. You are not granted to publish, distribute,
   sublicense, and/or sell copies of Cocos Creator.
  
   The software or tools in this License Agreement are licensed, not sold.
   Xiamen Yaji Software Co., Ltd. reserves all rights not expressly granted to you.
  
   THE SOFTWARE IS PROVIDED &quot;AS IS&quot;, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
   IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
   FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
   AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
   LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
   OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
   THE SOFTWARE.
   ****************************************************************************/
  
  #include &quot;AppDelegate.h&quot;
  
  #include &quot;cocos2d.h&quot;
  
  #include &quot;cocos/scripting/js-bindings/manual/jsb_module_register.hpp&quot;
  #include &quot;cocos/scripting/js-bindings/manual/jsb_global.h&quot;
  #include &quot;cocos/scripting/js-bindings/jswrapper/SeApi.h&quot;
  #include &quot;cocos/scripting/js-bindings/event/EventDispatcher.h&quot;
  #include &quot;cocos/scripting/js-bindings/manual/jsb_classtype.hpp&quot;
  
  USING_NS_CC;
  #ifdef SDKBOX_ENABLED
  #include &quot;PluginIAPJS.hpp&quot;
  #include &quot;PluginIAPJSHelper.h&quot;
  #endif
  #ifdef SDKBOX_ENABLED
  #include &quot;PluginReviewJS.hpp&quot;
  #include &quot;PluginReviewJSHelper.h&quot;
  #endif
  
  AppDelegate::AppDelegate(int width, int height) : Application(&quot;Cocos Game&quot;, width, height)
  {
  }
  
  AppDelegate::~AppDelegate()
  {
  }
  
  
  
  bool AppDelegate::applicationDidFinishLaunching()
  {
      se::ScriptEngine* se = se::ScriptEngine::getInstance();
  
      jsb_set_xxtea_key(&quot;7d334562-0879-4b&quot;);
      jsb_init_file_operation_delegate();
  
  #if defined(COCOS2D_DEBUG) &amp;&amp; (COCOS2D_DEBUG &gt; 0)
      // Enable debugger here
      jsb_enable_debugger(&quot;0.0.0.0&quot;, 6086, false);
  #endif
  
      se-&gt;setExceptionCallback([](const char* location, const char* message, const char* stack){
          // Send exception information to server like Tencent Bugly.
          cocos2d::log(&quot;\nUncaught Exception:\n - location :  %s\n - msg : %s\n - detail : \n      %s\n&quot;, location, message, stack);
      });
  
      jsb_register_all_modules();
  #ifdef SDKBOX_ENABLED
      se-&gt;addRegisterCallback(register_all_PluginIAPJS);
      se-&gt;addRegisterCallback(register_all_PluginIAPJS_helper);
  #endif
  #ifdef SDKBOX_ENABLED
      se-&gt;addRegisterCallback(register_all_PluginReviewJS);
      se-&gt;addRegisterCallback(register_all_PluginReviewJS_helper);
  #endif
  
      se-&gt;start();
  
      
      se::AutoHandleScope hs;
      jsb_run_script(&quot;jsb-adapter/jsb-builtin.js&quot;);
  
      jsb_run_script(&quot;main.js&quot;);
  
      
      se-&gt;addAfterCleanupHook([](){
          JSBClassType::destroy();
      });
  
      return true;
  }
  
  // This function will be called when the app is inactive. When comes a phone call,it's be invoked too
  void AppDelegate::onPause()
  {
      EventDispatcher::dispatchOnPauseEvent();
  }
  
  // this function will be called when the app is active again
  void AppDelegate::onResume()
  {
      EventDispatcher::dispatchOnResumeEvent();
  }
  </code></pre>
  <p>... which is a cpp file. I can't find a cpp example for that URL handling, unfortunately.</p>
  <p>(Here, I would then write objects into the JS environment in which my game runs:</p>
  <pre><code> se::ScriptEngine::getInstance()-&gt;evalString(&quot;window.your_func('put string here')&quot;);
  </code></pre>
  <p>)</p>
  <p>But adding the URL-handling function to my AppDelegate is something I can't really manage to pull off. Any ideas on this would be fantastic! Thank you!</p>