Using the TiApp utility class in Hyperloop iOS



This document describes technologies available in Hyperloop >= 3.1.0 and Titanium >= 7.2.0.

When developing iOS modules with Hyperloop, there are situations where you want to present a new view controller from your current context or pass your current context to a new view controller. Natively, you would usually reference "self" as its represents your current UIViewController subclass. In Titanium, your "self" is usually a Ti.UI.Window instance, which is fine for Titanium development, but cannot be used in native development.

That's why Hyperloop includes a number of utility methods that solve these kind of problems. They are exposed in the "TiApp" class that can be required as the following:

var TiApp = require('Titanium/TiApp');

And that's basically it. As the TiApp class is a singleton in Titanium all calls should be done on the "" instance. The following table shows a reference of the available utilities:


Name Parameters Return Description
app()  Void TiApp  The singleton object to call all other API's on.
showModalController(controller, animated) UIViewController, Boolean  Void Presents a view controller on the top presented view controller (e.g. "presentViewController:animated:").
hideModalController(controller, animated) UIViewController, Boolean Void Hides a currently presented view controller (e.g. "dismissViewControllerAnimated:completion:").
showModalError(error) String Void Shows the "red screen of death" indicating an unhandled error.
startNetwork() Void Void

Tells application to show network activity indicator.

stopNetwork() Void Void

 Tells application to hide network activity indicator.


Name Type Description
userAgent String

The user agent string to use for system network requests.

window UIWindow The application's primary window.
remoteDeviceUUID NSString The remote UUID for the current running device.
remoteNotification NSDictionary The details for the last remote notification.
localNotification NSDictionary The details for the last local notification.
launchOptions NSDictionary

The application launch options.

windowIsKeyWindow Boolean Indicates weather the current window is the key-window
applicationDelegate id<UIApplicationDelegate> The application delegate to set in order to use methods of the UIApplicationDelegate
controller UIViewController

The application's root view controller.

userAgent String

The user agent string to use for network requests.

sessionId String The unique identifier for the current application launch.


Present a view controller

This example shows how to open a new view controller in your current application context.

var myNewViewController = new UIViewController(); // Create a new view controller or pass it from existing libraries / SDK's
var myNewView = UIView.alloc().initWithFrame(CGRectMake(0,0, 200, 200)); // Create a  new UIView with a 200x200 frame
myNewView.backgroundColor = UIColor.greenColor; // Set a green background color
myNewViewController.view = myNewView; // Assign the UIView instance to your UIViewController, true); // Present the view controller

Pass the current view controller

This example shows how to pass your top presented controller to a native method (e.g. in the Facebook SDK).

var FBSDKShareDialog = require('FBSDKShareKit/FBSDKShareDialog');
var FBSDKShareDialogModeAutomatic = require('FBSDKShareKit').FBSDKShareDialogModeAutomatic;
var FBSDKShareLinkContent = require('FBSDKShareKit/FBSDKShareLinkContent');
var NSURL = require('Foundation/NSURL');
var TiApp = require('Titanium/TiApp');

var dialog = new FBSDKShareDialog(); // Create a new share dialog. Equals "FBSDKShareDialog.alloc().init()".
var content = new FBSDKShareLinkContent(); // Create new share content (link-based). Equals "FBSDKShareLinkContent.alloc().init()".
content.contentURL = NSURL.URLWithString(''); // Construct a native URL
dialog.setMode(FBSDKShareDialogModeAutomatic); // Use enumerations to define how the dialog should be shown
dialog.setFromViewController(; // <- This is where you pass your current context
dialog.setShareContent(content); // Assign the share content; // Present it!

Get the device's push notifications UUID

 This examples shows how to receive the device's UUID used for remote notifications.

var TiApp = require('Titanium/TiApp');
var remoteUUID =;'UUID: ' + remoteUUID);

Subscribe to the UIApplicationDelegate

This example shows how to subscribe to the UIApplicationDelegate in order to use the "application:didFinishLaunchingWithOptions:" delegate method. For more infos, see the UIApplicationDelegate guide.

var TiApp = require('Titanium/TiApp');
var UIApplicationDelegate = require('UIKit').UIApplicationDelegate;

// Create a new class to handle the delegate
var TiAppApplicationDelegate = Hyperloop.defineClass('TiAppApplicationDelegate', 'NSObject', UIApplicationDelegate);

// Add the selector to handle the result
  selector: 'application:didFinishLaunchingWithOptions:',
  instance: true,
  returnType: 'BOOL',
  arguments: [
  callback: function(application, options) {
    if (this.didFinishLaunchingWithOptions) {
      return this.didFinishLaunchingWithOptions(application, options);
    return true;

// Instantiate the delegate subclass
var applicationDelegate = new TiAppApplicationDelegate();
// Called when the application finished launching. Initialize SDK's here for example
applicationDelegate.didFinishLaunchingWithOptions = function(application, options) {'Hey there!');
  return true

// Finally, assign your subclass to the "applicationDelegate" property of the TiApp class;

Related Links