Skip to content
Tuni edited this page May 12, 2014 · 55 revisions

create a new IOS project

Image

Add Cobalt as a project Library

Once your project is created, import the Cobalt framework in your workspace too by cloning it from github.

Drag and drop the cobalt/sources/iOS/Cobalt folder in your new project's Frameworks folder.

Image

###Adding a www folder

This folder contains the web part of the application : web pages, styles, javascript libraries. As it is an essential part of the application, we let you define your own folders hierarchy.

Let's start by adding the www folder in the project and add some files.

Image

Notice that we ticked folder reference to keep files organisation within the bundle file. The created group will appear in blue in Xcode Project Navigator

###Initialise the web side

Once the www folder is linked to the projet, it is time to make it yours, and initialise cobalt on the web side.

Jump to the Web Setup page to do this. Don't forget to come back ;)

###Load your first html page

Create a Cobalt Controller

In your controller header file, import "CobaltViewController.h" and make the ViewController inherit of it and implement CobaltDelegate protocol.

#import "CobaltViewController.h"

@interface ViewController : CobaltViewController<CobaltDelegate>

@end

Then you need to implement methods required by the CobaltDelegate protocol in the ViewController:

#import "ViewController.h"

@implementation ViewController

- (BOOL)onUnhandledMessage:(NSDictionary *)message
{
    return NO;
}

- (BOOL)onUnhandledEvent:(NSString *)event withData:(NSDictionary *)data andCallback:(NSString *)callback
{
    return NO;
}

- (BOOL)onUnhandledCallback:(NSString *)callback withData:(NSDictionary *)data
{
    return NO;
}

@end

####Load the page you want in the didFinishLaunchingWithOptions method

Finally, you have to declare your web folder's location, and load your ViewController from the AppDelegate:

#import "Cobalt.h"
#import "CobaltViewController.h"

@implementation AppDelegate

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    // Override point for customization after application launch.
    [Cobalt setResourcePath:myResourcePath];    // default: [[NSBundle mainBundle] resourcePath], @"/www/"]
    UIViewController * viewController = [CobaltViewController getViewControllerForController:@"default" andPage:@"index.html"];
    UINavigationController * navigationController = [[UINavigationController alloc] initWithRootViewController:viewController];
    self.window.rootViewController = navigationController;
    
    [self.window makeKeyAndVisible];
    return YES;
}

By default index.html should be loaded if you don't specify any page.

Enable debug

TODO

Clone this wiki locally