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:
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:
Call these methods on the
TiApp property directly.
|app()||void||TiApp||The singleton object to call all other API's on.|
|getController()||void||UIViewController||Returns the application's root view controller.|
|getTiAppProperties()||void||NSDictionary||Return a read-only dictionary from tiapp.xml properties.|
Call these methods on the
|showModalController(controller, animated)||UIViewController, BOOL||void||Presents a view controller on the top presented view controller (e.g. "|
|hideModalController(controller, animated)||UIViewController, BOOL||void||Hides a currently presented view controller (e.g. "|
|showModalError(error)||NSString||void||Shows the "red screen of death" indicating an unhandled error.|
Tells application to show network activity indicator.
Tells application to hide network activity indicator.
|id<UIApplicationDelegate>||void||Registers a new |
|id<UIApplicationDelegate>||void||Unregisters an existing |
|windowIsKeyWindow()||void||BOOL||Indicates weather the current window is the key-window of the host application.|
|getRemoteDeviceUUID()||void||NSString||Returns the remote UUID for the current running device.|
|getSessionId()||void||NSString||Returns the unique identifier for the current application launch.|
|getLaunchOptions()||void||NSDictionary||Returns the application's launch options.|
Call these properties on the
|userAgent||NSString||The user agent string to use for system network requests.|
|window||UIWindow||The application's primary window.|
|remoteNotification||NSDictionary||The details for the last remote notification.|
|localNotification||NSDictionary||The details for the last local notification.|
|userAgent||NSString||The user agent string to use for network requests.|
Present a view controller
This example shows how to open a new view controller in your current application context.
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).
Get the device's push notifications UUID
This examples shows how to receive the device's UUID used for remote notifications.
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.