Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

And that's basically it. As the TiApp class is a singleton in Titanium, the instance methods are done on the TiApp.app() singleton and the class methods on TiApp directly. See the following table for a reference of the available utilities:

Class Methods

Call these methods on the TiApp property directly.

NameParametersReturnDescription
app()voidTiApp The singleton object to call all other API's on.
getController()voidUIViewControllerReturns the application's root view controller.
getTiAppProperties()voidNSDictionaryReturn a read-only dictionary from tiapp.xml properties.

Instance Methods

Call these methods on the TiApp.app() singleton.

NameParametersReturnDescription
showModalController(controller, animated)UIViewController, BOOLvoidPresents a view controller on the top presented view controller (e.g. "presentViewController:animated:").
hideModalController(controller, animated)UIViewController, BOOLvoidHides a currently presented view controller (e.g. "dismissViewControllerAnimated:completion:").
showModalError(error)NSStringvoidShows the "red screen of death" indicating an unhandled error.
startNetwork()voidvoid

Tells application to show network activity indicator.

stopNetwork()voidvoid

Tells application to hide network activity indicator.

registerApplicationDelegate(delegate)

id<UIApplicationDelegate>voidRegisters a new UIApplicationDelegate to the host application.

unregisterApplicationDelegate(delegate)

id<UIApplicationDelegate>voidUnregisters an existing UIApplicationDelegate from the host application.
windowIsKeyWindow()voidBOOLIndicates weather the current window is the key-window of the host application.
getRemoteDeviceUUID()voidNSStringReturns the remote UUID for the current running device.
getSessionId()voidNSStringReturns the unique identifier for the current application launch.
getLaunchOptions()voidNSDictionaryReturns the application's launch options.

Instance Properties

Call these properties on the TiApp.app() singleton.

NameTypeDescription
userAgentNSStringThe user agent string to use for system network requests.
windowUIWindowThe application's primary window.
remoteNotificationNSDictionaryThe details for the last remote notification.
localNotificationNSDictionaryThe details for the last local notification.
userAgentNSStringThe user agent string to use for network requests.

Examples

Present a view controller

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

Code Block
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

TiApp.app().showModalController(myNewViewController, 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).

Code Block
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('http://appcelerator.com'); // Construct a native URL
dialog.setMode(FBSDKShareDialogModeAutomatic); // Use enumerations to define how the dialog should be shown
dialog.setFromViewController(TiApp.controller); // <- This is where you pass your current context
dialog.setShareContent(content); // Assign the share content

dialog.show(); // Present it!

Get the device's push notifications UUID

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

Code Block
var remoteUUID = TiApp.app().remoteDeviceUUID;
Ti.API.info('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 iOS Modules - Use Native UI Application Delegates in Hyperloop and Native Modules.

...