Advertise Mobile SDKs Books Events Forum News Social Networking Support Us
Follow @iphonedevsdk on Twitter

Interface 2, Advanced iOS
Mockup & Code Gen
($9.99)

Make your own iPhone apps
and run them live!
(free)

Pic Frame Dynamo: Photo Editing
($0.99)

Abiliator
($1.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum > iPhone SDK Development Forums > iPhone SDK Development

Reply
 
LinkBack Thread Tools Display Modes
Old 09-02-2011, 05:17 PM   #1 (permalink)
Always learning...
 
PawApps's Avatar
 
Join Date: Jul 2011
Location: USA
Posts: 46
PawApps is on a distinguished road
Default Cocos2d and Mobclix

Hello,

Does anyone have any experience with adding Mobclix to a cocos2d app?

I have tried following the advice at this site to no avail. No errors or anything, just no ads.

I'm just starting out, so figuring out the right questions to ask is the first mountain I'm trying to climb.

Thanks all.
__________________

PawApps.com **** Bottle Tunes **** Word Overflow
PawApps is offline   Reply With Quote
Old 09-02-2011, 06:04 PM   #2 (permalink)
Always learning...
 
PawApps's Avatar
 
Join Date: Jul 2011
Location: USA
Posts: 46
PawApps is on a distinguished road
Default

Quote:
Originally Posted by PawApps View Post
Hello,

Does anyone have any experience with adding Mobclix to a cocos2d app?

I have tried following the advice at this site to no avail. No errors or anything, just no ads.

I'm just starting out, so figuring out the right questions to ask is the first mountain I'm trying to climb.

Thanks all.
Generally how it works. I spend hours trying to figure out a problem, then as soon as I post it or ask someone else for help... I get a solution.

For others (I'll be writing a tutorial because there were no good tutorials that I could find) here is the quick and dirty of what I did (lots of thanks to this thread):

1. Updated AppDelegate.h
Code:
#import "Mobclix.h"

...
- (void) applicationDidFinishLaunching:(UIApplication*)application
{
    ...
    [Mobclix startWithApplicationId:@"mobclix-id-goes-here"];
    ...
}
2. Here's my HelloWorldLayer.h
Code:
#import "cocos2d.h"
#import "MobclixAds.h"

// HelloWorldLayer
@interface HelloWorldLayer : CCLayer
{
    MobclixAdView *adView;
}

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

@property (retain, nonatomic) MobclixAdView *adView;

@end
3. Updated HelloWorldLayer.m
Code:
#import "MobclixAds.h"

...

-(void) onEnter
{
    CGSize winSize = [[CCDirector sharedDirector] winSize];
    self.adView = [[[MobclixAdViewiPhone_320x50 alloc] initWithFrame:CGRectMake(10.0f, 10.0f, 320.0f, 50.0f)] autorelease];
    UIViewController *controller = [UIViewController new];
    [controller.view addSubview:adView];
    [[[[CCDirector sharedDirector] openGLView] window] addSubview: controller.view];

    [self.adView resumeAdAutoRefresh];
    
    [super onEnter];
}

-(void) onExit {
    [self.adView pauseAdAutoRefresh];
    [adView removeFromSuperview];
    [adView release];
    
    [super onExit];
}
That was enough to make an ad show up (error ad until I updated with my mobclix id)

4. My app is landscape, so rotate the ad. I added this directly after [CCDirector .... addSubview:...]
Code:
    // Need some landscape ads
    CGAffineTransform makeLandscape = CGAffineTransformMakeRotation(M_PI * 0.5f);
    makeLandscape = CGAffineTransformTranslate(makeLandscape, 100, 130);
    makeLandscape = CGAffineTransformScale(makeLandscape, 0.8f, 0.8f);
    adView.transform = makeLandscape;
5. TODO: I still have figure out the best way to make that rotation as well as placement. If I do the rotation the way show above, the CGMakeRect keeps its portrait mode coordinate system.

It is a work in progress. Any pointers would be much appreciated, but at least I have a little bit of results to work off.
__________________

PawApps.com **** Bottle Tunes **** Word Overflow

Last edited by PawApps; 09-02-2011 at 06:07 PM. Reason: Updating code examples
PawApps is offline   Reply With Quote
Old 09-08-2011, 02:01 PM   #3 (permalink)
Registered Member
 
Join Date: Aug 2010
Location: Bay Area, CA
Posts: 219
AdamL is on a distinguished road
Default

Quote:
Originally Posted by PawApps View Post

5. TODO: I still have figure out the best way to make that rotation as well as placement. If I do the rotation the way show above, the CGMakeRect keeps its portrait mode coordinate system.

It is a work in progress. Any pointers would be much appreciated, but at least I have a little bit of results to work off.

Also, make sure to turn testing off, and sign up for ad networks in the mobclix dashboard. Until that point you wont get real ads.
__________________
mobclix.com
AdamL is offline   Reply With Quote
Old 09-15-2011, 04:00 PM   #4 (permalink)
Always learning...
 
PawApps's Avatar
 
Join Date: Jul 2011
Location: USA
Posts: 46
PawApps is on a distinguished road
Default Mobclix with cocos2d tutorial

Thanks for the reply Adam.

So here's the tutorial that I mentioned before: Mobclix and cocos2d | Paw Apps

And for those that don't want to click the link here's the code:

This is a singleton class that I wrote to handle a single ad in a scene. (First attempt at a singleton class, so please feel free make better!)
Code:
//
//  AdsManager.h
//  Bottle Tunes
//
//  Created by Jason Pawlak on 9/2/11.
//  Copyright 2011 Paw Apps LLC. All rights reserved.
//
 
#import <Foundation/Foundation.h>
#import "cocos2d.h"
#import "MobclixAds.h"
 
@interface AdsManager : CCLayer {
    MobclixAdView *adView;
    BOOL adStarted;
}
 
-(UIViewController*) getRootViewController;
-(void) presentViewController:(UIViewController*)vc;
-(void) newAd:(CGPoint)loc;
-(void) showAd;
-(void) hideAd;
-(void) cancelAd;
-(void) startMobclix;
-(NSString*) platform;
 
+(AdsManager*)sharedAdsManager;
 
@property (retain, nonatomic) MobclixAdView *adView;
@property (assign, nonatomic) BOOL adStarted;
 
@end
Code:
//
//  AdsManager.m
//  Bottle Tunes
//
//  Created by Jason Pawlak on 9/2/11.
//  Copyright 2011 Paw Apps LLC. All rights reserved.
//
 
#import "AdsManager.h"
#import "Mobclix.h"
#include <<sys/types.h>
#include <sys/sysctl.h>
 
#define MOBCLIX_ID @"ENTER_YOUR_MOBCLIX_ID_HERE"
 
@implementation AdsManager
 
@synthesize adView;
@synthesize adStarted;
 
static AdsManager *_sharedAdsManager = nil;
 
// Helper methods
 
-(UIViewController*) getRootViewController
{
	return [UIApplication sharedApplication].keyWindow.rootViewController;
}
 
-(void) presentViewController:(UIViewController*)vc
{
	UIViewController* rootVC = [self getRootViewController];
	[rootVC presentModalViewController:vc animated:YES];
}
 
-(NSString *) platform
{
    size_t size;
    sysctlbyname("hw.machine", NULL, &size, NULL, 0);
    char *machine = malloc(size);
    sysctlbyname("hw.machine", machine, &size, NULL, 0);
    NSString *platform = [NSString stringWithCString:machine encoding:NSUTF8StringEncoding];
    free(machine);
    return platform;
}
 
-(void) newAd:(CGPoint)loc {
 
    if (adView) {
        // We only want one ad at a time
        [self cancelAd];
    }
    CGSize winSize = [[CCDirector sharedDirector] winSize];
    bool is3GDevice = [[self platform] isEqualToString:@"iPhone1,2"];
 
    if (is3GDevice) {
        adView = [[[MobclixAdViewiPhone_320x50 alloc] initWithFrame:CGRectMake(-1 * (winSize.height/2 - 25 - loc.y), 160 - 25 + loc.x, 320.0f, 50.0f)] autorelease];
        [adView setTransform:CGAffineTransformMakeRotation(M_PI / 2.0)];
    } else {
        adView = [[[MobclixAdViewiPhone_320x50 alloc] initWithFrame:CGRectMake(loc.x, winSize.height - loc.y - 50.0f, 320.0f, 50.0f)] autorelease];
    }
//    [[[self getRootViewController] view] addSubview:adView];
    [[[CCDirector sharedDirector] openGLView] addSubview:adView];
 
    [self.adView resumeAdAutoRefresh];
}
 
-(void) showAd {
    if (!adView)
        [self newAd:ccp(0,0)];
    [self.adView resumeAdAutoRefresh];
    [self.adView setHidden:NO];
}
 
-(void) hideAd {
    [self.adView pauseAdAutoRefresh];
    [self.adView setHidden:YES];
}
 
-(void) cancelAd {
    // Can only cancel it if it exists
    if (adView) {
        [adView cancelAd];
        [adView setDelegate:nil];
        [adView removeFromSuperview];
        adView = nil;
    }
}
 
-(void) startMobclix {
    if (!adStarted)
        adStarted = YES;
        [Mobclix startWithApplicationId:MOBCLIX_ID];
}
 
+(AdsManager*)sharedAdsManager
{
	@synchronized([AdsManager class])
	{
		if (!_sharedAdsManager)
			[[self alloc] init];
 
		return _sharedAdsManager;
	}
 
	return nil;
}
 
+(id)alloc
{
	@synchronized([AdsManager class])
	{
		NSAssert(_sharedAdsManager == nil, @"Attempted to allocate a second instance of a singleton.");
		_sharedAdsManager = [[super alloc] init];
		return _sharedAdsManager;
	}
 
	return nil;
}
 
-(id)autorelease {
    [self cancelAd];
 
    return self;
}
 
-(id)init {
    if (!adStarted)
        [self startMobclix];
	return [super init];
}
 
@end
Here is how AdsManager gets used:
Code:
// AppDelegate.m
- (void) applicationDidFinishLaunching:(UIApplication*)application
{
    ...
    // Set up ads
    [[AdsManager sharedAdsManager] startMobclix];
    ...
}
Code:
// HelloWorldLayer.m (or something else...)
// Create ad but don't show it yet
[[AdsManager sharedAdsManager] newAd:ccp(winSize.width / 2 - 160.0f, 25.0f)];
[[AdsManager sharedAdsManager] hideAd];
...
// Show the ad
[[AdsManager sharedAdsManager] showAd];
...
// Done with this scene, cancel the ad because we'll create a new one at another scene
[[AdsManager sharedAdsManager] cancelAd];
Hope that helps people. Again, feel free to comment or condemn, won't hurt my feelings. All for the good of the community!
__________________

PawApps.com **** Bottle Tunes **** Word Overflow
PawApps is offline   Reply With Quote
Reply

Bookmarks

Tags
cocos2d, mobclix

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



» Advertisements
» Online Users: 393
5 members and 388 guests
JackReidy, jeroenkeij, Sami Gh, yomo710
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,671
Threads: 94,121
Posts: 402,903
Top Poster: BrianSlick (7,990)
Welcome to our newest member, JackReidy
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 04:49 AM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0