Code Monkey home page Code Monkey logo

ti-sample-url-scheme's Introduction

ti-sample-url-scheme

An sample application to demonstrate how to setup and handle custom URL schemes in Titanium.

iOS

For iOS we want to define the handle in the tiapp.xml by adding the below to our <plist> section:

<key>CFBundleURLTypes</key>
<array>
  <dict>
    <key>CFBundleURLSchemes</key>
    <array>
      <string>{{your-url-scheme}}</string>
    </array>
  </dict>
</array>

You can find the definition for this in the tiapp.xml here

Then in our application we can handle the event that the SDK emits using the below code:

Ti.App.iOS.addEventListener('handleurl', (e) => {
  /** handle **/
});

You can find the code for this app here

Android

To handle these on Android we need to include ti.deeply. That module is already included in this project.

After adding the module we want to configure the intent filter in our tiapp.xml. Inside the <manifest> tag we want to setup the following:

<application>
  <activity android:name="ti.deeply.DeepLinkHandlerActivity" android:noHistory="true" android:excludeFromRecents="true" android:theme="@android:style/Theme.NoDisplay" android:launchMode="singleTask">
    <!-- {{your-url-scheme}}://{{your-host} -->
    <intent-filter>
      <action android:name="android.intent.action.VIEW" />
      <category android:name="android.intent.category.DEFAULT" />
      <category android:name="android.intent.category.BROWSABLE" />
      <data android:host="{{your-host}}" android:scheme="{{your-url-scheme}}" />
    </intent-filter>
  </activity>
</application>

You can find the definition for this in the tiapp.xml here

Then in our application to handle the event we want to use ti.deeply to set the callback:

const deeply = require('ti.deeply');
deeply.setCallback((e) => {
 /** handle **/
});

You can find the code for this here

Testing

To demonstrate handling different behaviour dependent on the URL this sample has two "actions". They are alert and updateLabel, to use them:

  • tisample://alert?name=Titanium&whatIsIt=awesome
    • Will extract the query parameters and display the data as an alert
  • tisample://updateLabel?name=Titanium&whatIsIt=awesome
    • Will extract the query parameters and display the data in a label

To test this you want to trigger the app launch by the URL scheme:

  • iOS: Open Safari and enter a URL like tisample://alert?name=Titanium&whatIsIt=awesome
  • Android: Use adb to trigger the launch, adb shell am start -a android.intent.action.VIEW -d "tisample://alert?name=Titanium\&whatIsIt=awesome" com.axway.urlschemesample
    • Note the \ before & in the query parameters. That's required for it to be handled correctly

ti-sample-url-scheme's People

Contributors

ewanharris avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.