How to integrate Kiip ads into Cocos2d

Here is a quick example of how to integrate Kiip rewards into your Cocos2d game.

If you have questions or updates, please post them in the comments below, thanks! 😉

Required:

Kiip Account: http://www.kiip.com/
Cocos2d: http://www.cocos2d-iphone.org/
Kiip SDK: http://docs.kiip.com/en/downloads/

AppDelegate.h
1. Add #import <KiipSDK/KiipSDK.h>
2. Add KiipDelegate to the AppController interface

#import 
#import "cocos2d.h"
#import 

// Added only for iOS 6 support
@interface MyNavigationController : UINavigationController 
@end

@interface AppController : NSObject 
{
	UIWindow *window_;
	MyNavigationController *navController_;

	CCDirectorIOS	*director_;							// weak ref
}

@property (nonatomic, retain) UIWindow *window;
@property (readonly) MyNavigationController *navController;
@property (readonly) CCDirectorIOS *director;

@end

AppDelegate.m
1. Add Kiip init code at the end of the didFinishLaunchingWithOptions method just above the return YES;

Note: You will need to get your “KEY” and “SECRET” from your Kiip dashboard.

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{

//---- Towards End ----//

    //Kiip Start//
    Kiip *kiip = [[Kiip alloc] initWithAppKey:@"1234" andSecret:@"1234"];
    kiip.delegate = self;
    [Kiip setSharedInstance:kiip];
    //Kiip End//
    
	
	return YES;
}

HelloWorldLayer.h

1. Add #import <KiipSDK/KiipSDK.h>
2. Add <KiipDelegate> to interface

#import 

// When you import this file, you import all the cocos2d classes
#import "cocos2d.h"

// HelloWorldLayer
@interface HelloWorldLayer : CCLayer 
{
}

// returns a CCScene that contains the HelloWorldLayer as the only child
+(CCScene *) scene;

@end

HelloWorldLayer.m

1. Added Kiip rewards call inside a CCMenuItem block call ( you would make your own method and triggers to call Kiip rewards )


		// Default font size will be 28 points.
		[CCMenuItemFont setFontSize:28];
        
		// Achievement Menu Item using blocks
		CCMenuItem *kiipAchievement = [CCMenuItemFont itemWithString:@"Kiip Achievement" block:^(id sender) {
			
                [[Kiip sharedInstance] saveMoment:@"Finishing Level One!" withCompletionHandler:^(KPPoptart *poptart, NSError *error) {
                    if (error) {
                        NSLog(@"something's wrong");
                        // handle with an Alert dialog.
                    }
                    if (poptart) {
                        [poptart show];
                    }
                    if (!poptart) {
                        // handle logic when there is no reward to give.
                    }
                }];
		}];
		
		CCMenu *menu = [CCMenu menuWithItems:kiipAchievement, nil];
		
		[menu alignItemsHorizontallyWithPadding:20];
		[menu setPosition:ccp( size.width/2, size.height/2 - 50)];
		
		// Add the menu to the layer
		[self addChild:menu];

That’s it, if you have questions or comments, write them below!

what do you think?