Quick Example of registering a scheme in TiApp.xml, implementing the code in app.js / alloy.js
-
-
Save csemrm/886e1429a10360a65187428db993fdcd to your computer and use it in GitHub Desktop.
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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(); | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<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> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment