Developer

Your First Extensible App

Get the tutorial extensible app running.

Context

Procedure

To get the tutorial extensible app running, open the AppDelegate.m file, and modify the didFinishLaunchingWithOptions: method as shown in this code:
// add the MAFCore header - ensure that you've set up the header search path correctly and have all the required public headers and libraries!
#import "MAFCore.h"

@implementation AppDelegate

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
    // Remove boilerplate code
	// We won't use the generated view controller anymore.
	// The Extensibility framework will create the view controller from the metadata supplied in the layout_phone.xml;
	// Since it is marked as a root view controller in the configuration, the framework will also assign it to the UIWindow object and finally display the window
//    self.viewController = [[ViewController alloc] initWithNibName:@"ViewController" bundle:nil];
//    self.window.rootViewController = self.viewController;

    // Start the Extensibility engine; we pass in the UIWindow object, and that's it - no further data is needed to initialise and start the framework
// Note that the API is executed asynchronously; once it completes, the completion block gets called, and we have to evaluate the error object: it should be nil, otherwise there were issues during initialization 
    [[MAFCore sharedInstance] loadWithWindow:self.window andCompletionBlock:^(NSError* error)
     {
         // Extensibility engine started successfully
         if( !error )
         {
             NSLog( @"Extensibility is Up and Running!" );             
         }
         // Extensibility engine failed to start!
         else
         {
             NSLog( @"Extensibility load failure. Details:%@", error.description );
         }
     }];
    // Can be safely removed, too, since the Extensibility framework will take care of displaying the root view controller
//    [self.window makeKeyAndVisible];
    return YES;
}

Results

The code generated by Xcode, which instantiated a ViewController and set it as the window’s root view controller, has been commented out in the above code. It adds a single MAFCore API call, which instantiates the Extensibility Engine, and additional MAF libraries that are used for styling, value formatting, and so on.

The MAFCore loadWithWindow: API is asynchronous, therefore it does not block the main thread while executing; you can perform other UI related tasks while the Extensibility Framework initializes.

Once the loadWithWindow: API execution completes, the completion block is invoked. This example checks whether everything went fine and logs both the error and the success case. The Extensibility Framework provides advanced possibilities to intercept runtime issues.

You can now build and run the app; doing so shows a black screen on the simulator, indicating that the Extensibility Engine works as expected:


First Extensible App