Skip to content

Instantly share code, notes, and snippets.

@FokkeZB
Last active April 6, 2020 14:57
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save FokkeZB/6340484 to your computer and use it in GitHub Desktop.
Save FokkeZB/6340484 to your computer and use it in GitHub Desktop.
URL schemes for iOS and Android (1/2)
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;
}
// 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();
}
<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>
<?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>
@mitulbhalia
Copy link

@FokkeZB
The above was working fine till now but i need to change the urlscheme for ios something like https://www.url.com/param/?view=123
so i tried to set CFBundleURLSchemes to https://www.url.com and www.url.com but did not work.
should i need to use something else for CFBundleURLSchemes?

@FokkeZB
Copy link
Author

FokkeZB commented Apr 9, 2018

@mitulbhalia I have no idea, sorry. I haven't been using Titanium for 2 years anymore. I'd suggest to try TiSlack.org

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