Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Quick example of registering a URLScheme in a Titanium app using the TiApp.xml without info.plist file. Just add the following into your TiApp.xml (I put it under the </iphone> tag. Works on Android and iOS.

Quick Example of registering a scheme in TiApp.xml, implementing the code in app.js / alloy.js

// points for getting this shorter using regex
function urlToObject(url) {
var returnObj = {};
url = url.replace('URLSCHEMENAME://?', '');
var params = url.split('&');
params.forEach(function(param) {
var keyAndValue = param.split('=');
returnObj[keyAndValue[0]] = decodeURI(keyAndValue[1]);
});
return returnObj;
}
function processArgs() {
if (Ti.App.getArguments().url) {
urlToObject(Ti.App.getArguments().url);
}
}
// on launch
processArgs();
// on resume
Ti.App.addEventListener("resumed", function(){
processArgs();
});
<ios>
<plist>
<dict>
<key>CFBundleURLTypes</key>
<array>
<dict>
<key>CFBundleURLName</key>
<string>com.yourdomain.yourappprefix</string>
<key>CFBundleURLSchemes</key>
<array>
<string>URLSCHEMENAME</string>
</array>
</dict>
</array>
</dict>
</plist>
</ios>
<android xmlns:android="http://schemas.android.com/apk/res/android">
<activities>
<activity url="app.js"
android:launchMode="singleTask" android:alwaysRetainTaskState="true">
<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="" android:scheme="URLSCHEMENAME"/>
</intent-filter>
</activity>
</activities>
</android>
@FokkeZB
Copy link

FokkeZB commented Jul 5, 2013

@skypanther
Copy link

skypanther commented Jul 18, 2013

Looks like line 18 should be return returnObj (variable set on line 4)

@ajitjati
Copy link

ajitjati commented Aug 13, 2014

Hi , when i hit URLSCHEMENAME from a mobile browser say chrome , it always searches it in google.Can you please help me.

@jasonkneen
Copy link
Author

jasonkneen commented Dec 11, 2014

Fixed.

Replace URLSCHEMENAME with your own - don't use this one!

@falkolab
Copy link

falkolab commented Dec 24, 2014

Can't open my url with custom scheme from gmail or default android browser. It's possible?

@GertjanSmits
Copy link

GertjanSmits commented Mar 9, 2015

I assume this tag in is some Titanium uses to generate stuff for the AndroidManifest.xml right? I get a generated activity in there, but I'm missing the declared intent-filters. Any idea what I'm doing wrong?

@cauboy
Copy link

cauboy commented Mar 15, 2015

I've the same problem as @GertjanSmits. Activity is listed in the generated AndroidManifest.xml but there is no <intent-filter> tag within the <activity> tag. Does anyone have an idea why?

@bert-w
Copy link

bert-w commented Feb 21, 2017

Is this still working as supposed to? What does line #20 do in TiApp.xml ? url="app.js" does not make sense to me

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment