Read the blog at http://fokkezb.nl/2013/08/26/url-schemes-for-ios-and-android-1/
-
-
Save csemrm/e44782a5648e7b347cf69a55e06c6b64 to your computer and use it in GitHub Desktop.
URL schemes for iOS and Android (1/2)
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
if (OS_ANDROID) { | |
// Somehow, only in alloy.js we can get the data (URL) that opened the app | |
Alloy.Globals.url = Ti.Android.currentActivity.intent.data; | |
} |
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
// We don't want our URL to do anything before our main window is open | |
$.index.addEventListener('open', function (e) { | |
if (OS_IOS) { | |
// Handle the URL in case it opened the app | |
handleURL(Ti.App.getArguments().url); | |
// Handle the URL in case it resumed the app | |
Ti.App.addEventListener('resumed', function () { | |
handleURL(Ti.App.getArguments().url); | |
}); | |
} else if (OS_ANDROID) { | |
// On Android, somehow the app always opens as new | |
handleURL(Alloy.globals.url); | |
} | |
}); | |
// Source: https://github.com/FokkeZB/UTiL/blob/master/XCallbackURL/XCallbackURL.js | |
var XCallbackURL = require('XCallbackURL'); | |
function handleUrl(url) { | |
var URL = XCallbackURL.parse(url), | |
controller = URL.action(), | |
args = URL.params(); | |
// Add some better logic here ;) | |
Alloy.createController(controller, args || {}).getView().open(); | |
} |
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
<ti:app> | |
<!-- other stuff --> | |
<android xmlns:android="http://schemas.android.com/apk/res/android"> | |
<!-- keep any custom attributes for manifest --> | |
<manifest> | |
<!-- keep any custom attributes for application --> | |
<application> | |
<activity android:configChanges="keyboardHidden|orientation" android:label="My App" | |
android:name=".MyAppActivity" android:theme="@style/Theme.Titanium" | |
android:launchMode="singleTask" > | |
<!-- add the above launchMode attribute --> | |
<intent-filter> | |
<action android:name="android.intent.action.MAIN"/> | |
<category android:name="android.intent.category.LAUNCHER"/> | |
</intent-filter> | |
<!-- add the below additional intent-filter --> | |
<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:scheme="myapp" /> | |
</intent-filter> | |
</activity> | |
</application> | |
</manifest> | |
<!-- other android stuff --> | |
</android> | |
</ti:app> |
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
<?xml version="1.0" encoding="UTF-8"?> | |
<ti:app xmlns:ti="http://ti.appcelerator.org"> | |
<!-- other stuff --> | |
<ios> | |
<plist> | |
<dict> | |
<key>CFBundleURLTypes</key> | |
<array> | |
<dict> | |
<key>CFBundleURLName</key> | |
<!-- same as ti:app/id --> | |
<string>my.app.id</string> | |
<key>CFBundleURLSchemes</key> | |
<array> | |
<!-- your custom scheme --> | |
<string>myapp</string> | |
<!-- same as 'fb' plus ti:app/property[name=ti.facebook.appid] --> | |
<string>fb123456789</string> | |
</array> | |
</dict> | |
</array> | |
<!-- other ios/plist stuff --> | |
</dict> | |
</plist> | |
<!-- other ios stuff --> | |
</ios> | |
</ti:app> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment