 |
 |
|
 |
02-02-2010, 03:08 PM
|
#1 (permalink)
|
|
Registered Member
Join Date: Apr 2009
Location: Setauket, NY
Posts: 114
|
Adding AdMob view just above a tab bar controller
Hello;
My main app uses a Tab Bar Controller in the MainWindow.xib.
I understand the mechanics of adding the AdMob stuff to a generic view, but I'm having a difficult time glueing the concepts in my head enough to add it just above the Tab Bar controller. I want the ads there so that they are present as the user moves about my app.
Or should I incorporate the ads on each of the seperate view controllers that the tab bar controller controls?
Thanks.
|
|
|
02-02-2010, 06:01 PM
|
#2 (permalink)
|
|
Registered Member
Join Date: Dec 2009
Posts: 230
|
You can either add the TBC view to a superview that also has the AdMob view or have a separate AdMob view in each child VC.
__________________
@rarindeed
Sell your ad space directly with .app/ads. Help other developers promote their apps, promote your own apps and in-app purchases, or run ad network ads... all for free!
|
|
|
02-02-2010, 09:21 PM
|
#3 (permalink)
|
|
Registered Member
Join Date: Apr 2009
Location: Setauket, NY
Posts: 114
|
Quote:
Originally Posted by rarindeed
You can either add the TBC view to a superview that also has the AdMob view or have a separate AdMob view in each child VC.
|
Yup. I got it.
Thanks!!!!!
|
|
|
02-04-2010, 05:41 AM
|
#4 (permalink)
|
|
Intermediate Developer
Join Date: Dec 2009
Location: Sydney
Posts: 1
|
Quote:
Originally Posted by hstaniloff
Yup. I got it.
Thanks!!!!!
|
Hi, I have the exact same problem, can you please share the steps that fixed it?
|
|
|
02-04-2010, 07:14 AM
|
#5 (permalink)
|
|
Registered Member
Join Date: Apr 2009
Location: Setauket, NY
Posts: 114
|
AdMob ads in a TableViewHeader
Quote:
Originally Posted by swizzy
Hi, I have the exact same problem, can you please share the steps that fixed it?
|
In my opinion, putting ads at the very top or the very bottom breaks the look and feel of the iPhone interface. I just don't like the way it looks. Take a peek at weather.com app and you'll see what I mean.
Since almost all of my view controllers are tables, I decided to display the ads in a TableViewHeader. It looks good and the user can scroll it away if the display is big enough - I sort of like that behavior.
So here's what I did to implement it:
In my view controller's viewDidLoad I have the following:
Code:
if (tableHeaderView == nil) {
CGRect frameRectangle = CGRectMake(0.0f, 0.0f, 320.0f, 48.0f);
tableHeaderView = [[UIView alloc] initWithFrame:frameRectangle];
tableHeaderView.backgroundColor = [UIColor colorWithRed:0.208 green:0.435 blue:0.659 alpha:1];
self.tableView.tableHeaderView = tableHeaderView;
}
// Request an ad
adMobAd = [AdMobView requestAdWithDelegate:self];
[adMobAd retain]; // this will be released when it loads (or fails to load)
tableHeaderView is defined as a UIView in my .h file. Then, I do the following assignment in the AdMob callback didReceiveAd;
Code:
- (void)didReceiveAd:(AdMobView *)adView {
NSLog(@"AdMob: Did receive ad");
[self.tableView.tableHeaderView addSubview:adMobAd];
[refreshTimer invalidate];
refreshTimer = [NSTimer scheduledTimerWithTimeInterval:AD_REFRESH_PERIOD target:self selector:@selector(refreshAd:) userInfo:nil repeats:YES];
}
So that's how I implemented AdMob ads in my app. Hope that helps!
/H
|
|
|
02-14-2010, 10:36 AM
|
#6 (permalink)
|
|
Registered Member
Join Date: Feb 2010
Posts: 11
|
Quote:
Originally Posted by hstaniloff
In my opinion, putting ads at the very top or the very bottom breaks the look and feel of the iPhone interface. I just don't like the way it looks. Take a peek at weather.com app and you'll see what I mean.
Since almost all of my view controllers are tables, I decided to display the ads in a TableViewHeader. It looks good and the user can scroll it away if the display is big enough - I sort of like that behavior.
So here's what I did to implement it:
In my view controller's viewDidLoad I have the following:
Code:
if (tableHeaderView == nil) {
CGRect frameRectangle = CGRectMake(0.0f, 0.0f, 320.0f, 48.0f);
tableHeaderView = [[UIView alloc] initWithFrame:frameRectangle];
tableHeaderView.backgroundColor = [UIColor colorWithRed:0.208 green:0.435 blue:0.659 alpha:1];
self.tableView.tableHeaderView = tableHeaderView;
}
// Request an ad
adMobAd = [AdMobView requestAdWithDelegate:self];
[adMobAd retain]; // this will be released when it loads (or fails to load)
tableHeaderView is defined as a UIView in my .h file. Then, I do the following assignment in the AdMob callback didReceiveAd;
Code:
- (void)didReceiveAd:(AdMobView *)adView {
NSLog(@"AdMob: Did receive ad");
[self.tableView.tableHeaderView addSubview:adMobAd];
[refreshTimer invalidate];
refreshTimer = [NSTimer scheduledTimerWithTimeInterval:AD_REFRESH_PERIOD target:self selector:@selector(refreshAd:) userInfo:nil repeats:YES];
}
So that's how I implemented AdMob ads in my app. Hope that helps!
/H
|
Hello, I am very new at developing for the iphone but have managed to get the AdMob code working in my normal views. But a portion of my app is in Tables. When I add the code to the tables it does work but the first record is always cut off. I tried using your method from above, but I think some steps were left out.
I am getting the following errors after using your code:
error: 'adMobAd' undeclared (first used in this function)
error: 'AdMobView' undeclared (first used in this function)
error: request for member 'tableView' in something not a structure or union.
Any help would be appreciated.. Baby steps would help too
Thanks
|
|
|
02-14-2010, 02:45 PM
|
#7 (permalink)
|
|
Registered Member
Join Date: Apr 2009
Location: Setauket, NY
Posts: 114
|
Quote:
Originally Posted by tsansone
Hello, I am very new at developing for the iphone but have managed to get the AdMob code working in my normal views. But a portion of my app is in Tables. When I add the code to the tables it does work but the first record is always cut off. I tried using your method from above, but I think some steps were left out.
I am getting the following errors after using your code:
error: 'adMobAd' undeclared (first used in this function)
error: 'AdMobView' undeclared (first used in this function)
error: request for member 'tableView' in something not a structure or union.
Any help would be appreciated.. Baby steps would help too
Thanks
|
It looks like you didn't declare anything in your .h file!
Something like this might help:
Code:
#define AD_REFRESH_PERIOD 60.0 // display fresh ads once per minute
#import <UIKit/UIKit.h>
#import "AdMobDelegateProtocol.h";
@class AdMobView;
@interface AdViewController : UIViewController<AdMobDelegate> {
AdMobView *adMobAd; // the actual ad; self.view is a placeholder to indicate where the ad should be placed; intentially _not_ an IBOutlet
NSTimer *refreshTimer; // timer to get fresh ads
}
- (void)refreshAd:(NSTimer *)timer;
@end
Take a look at the AdMob sample app that comes with their SDK. That will help a lot.
|
|
|
02-15-2010, 07:16 PM
|
#8 (permalink)
|
|
Registered Member
Join Date: Feb 2010
Posts: 11
|
Ok, I tried putting the code in the header and got nowhere. I appreciate you trying to help me. I am attaching code for my files that need to be modified (I believe). I would appreciate it if you could help with this.
VGTData.h file
Code:
#import <Foundation/Foundation.h>
#import <sqlite3.h>
#import "VGTDataUser.h"
#import "VGTGame.h"
#import "VGTManufacturer.h"
#import "VGTPlatform.h"
@interface VGTData : NSObject
{
sqlite3 *readonlyDatabase;
sqlite3 *writableDatabase;
NSArray *manufacturers;
BOOL shouldReloadUserHaves;
BOOL shouldReloadUserWants;
NSMutableSet *dataUsers;
NSMutableSet *haveGames[OwnedStateCOUNT];
NSMutableSet *wantGames[OwnedStateCOUNT];
NSMutableDictionary *havePlatforms;
NSMutableDictionary *wantPlatforms;
}
@property (nonatomic, assign) sqlite3 *readonlyDatabase;
@property (nonatomic, assign) sqlite3 *writableDatabase;
@property (nonatomic, retain) NSArray *manufacturers;
+ (VGTData *)sharedInstance;
+ (void)appWillTerminate;
- (id)init;
- (void)createFavoritesTables;
- (UIImage *)imageForManufacturer:(VGTManufacturer *)manufacturer;
- (UIImage *)imageForPlatform:(VGTPlatform *)platform;
- (NSArray *)platformsWithText:(NSString *)searchText;
//- (NSArray *)gamesForPlatform:(VGTPlatform *)platform;
- (void)addDataUser:(id <VGTDataUser>)aUser;
- (BOOL)loadDatabaseUpdate:(NSData *)aData;
- (NSDictionary *)havePlatforms;
- (NSDictionary *)wantPlatforms;
- (NSSet *)haveCompleteGames;
- (NSSet *)haveLooseGames;
- (NSSet *)wantCompleteGames;
- (NSSet *)wantLooseGames;
- (OwnedState)haveItStateForGame:(NSString *)primaryKey;
- (OwnedState)wantItStateForGame:(NSString *)primaryKey;
- (void)setHaveState:(OwnedState)newState forGame:(NSString *)primaryKey;
- (void)setWantState:(OwnedState)newState forGame:(NSString *)primaryKey;
- (BOOL)shouldReloadUserHaves;
- (BOOL)shouldReloadUserWants;
- (void)userHavesDidChange;
- (void)userWantsDidChange;
@end
VGTData.m file
Code:
#import "VGTData.h"
#import "VGTManufacturer.h"
#import "VGTPlatform.h"
#import "VGTGame.h"
#import "JHSQLiteCocoa.h"
#import <sqlite3.h>
@interface VGTData ()
- (void)initializeDatabase;
- (void)closeDatabase;
@end
@implementation VGTData
VGTData *VGTData__instance = nil;
static sqlite3_stmt *search_statement = NULL;
static sqlite3_stmt *hydrate_have_platforms_statement = NULL;
static sqlite3_stmt *hydrate_have_statement = NULL;
static sqlite3_stmt *query_have_statement = NULL;
static sqlite3_stmt *delete_have_statement = NULL;
static sqlite3_stmt *insert_have_statement = NULL;
static sqlite3_stmt *hydrate_want_platforms_statement = NULL;
static sqlite3_stmt *hydrate_want_statement = NULL;
static sqlite3_stmt *query_want_statement = NULL;
static sqlite3_stmt *delete_want_statement = NULL;
static sqlite3_stmt *insert_want_statement = NULL;
@synthesize readonlyDatabase;
@synthesize writableDatabase;
@synthesize manufacturers;
+ (VGTData *)sharedInstance
{
//DLog(@"%s (%@)", __FUNCTION__, VGTData__instance);
if (VGTData__instance == nil)
{
VGTData__instance = [[VGTData alloc] init];
}
return VGTData__instance;
}
+ (void)appWillTerminate
{
[VGTData__instance closeDatabase];
}
- (void)createFavoritesTables
{
static BOOL did_create_have_table = NO;
static BOOL did_create_want_table = NO;
if (did_create_have_table == NO)
{
did_create_have_table = YES;
sqlite3_stmt *statement = NULL;
const char *sql = "CREATE TABLE IF NOT EXISTS user_have(gameId TEXT PRIMARY KEY, state INT)";
int result = sqlite3_prepare_v2(writableDatabase, sql, -1, &statement, NULL);
//DLog(@"(%d)", result);
if (result != SQLITE_OK)
{
DLog(@"");
NSAssert1(0, @"Error: failed to prepare statement with message '%s'.", sqlite3_errmsg(writableDatabase));
}
int success = sqlite3_step(statement);
//DLog(@"(%d)", success);
result = sqlite3_finalize(statement);
DLog(@"(%d)", result);
}
if (did_create_want_table == NO)
{
did_create_want_table = YES;
sqlite3_stmt *statement = NULL;
const char *sql = "CREATE TABLE IF NOT EXISTS user_want(gameId TEXT PRIMARY KEY, state INT)";
int result = sqlite3_prepare_v2(writableDatabase, sql, -1, &statement, NULL);
//DLog(@"(%d)", result);
if (result != SQLITE_OK)
{
DLog(@"");
NSAssert1(0, @"Error: failed to prepare statement with message '%s'.", sqlite3_errmsg(writableDatabase));
}
int success = sqlite3_step(statement);
//DLog(@"(%d)", success);
result = sqlite3_finalize(statement);
DLog(@"(%d)", result);
}
}
- (void)dealloc
{
[manufacturers release];
[super dealloc];
}
// There is actually more code then this but I think this is all you will need //
I know this is a lot of code to look into and even perhaps outside the scope of this forum. But I am beginner at this and I am stuck. Thanks
|
|
|
02-15-2010, 07:23 PM
|
#9 (permalink)
|
|
Registered Member
Join Date: Apr 2009
Location: Setauket, NY
Posts: 114
|
Quote:
|
I know this is a lot of code to look into and even perhaps outside the scope of this forum. But I am beginner at this and I am stuck. Thanks
|
Ok. I see the code that you have here.
You have to have the AdMob SDK downloaded and installed in your Xcode project. Did you do that? Where are you implementing any of the AdMob stuff? [See previous code from last post]
|
|
|
 |
| Thread Tools |
|
|
| Display Modes |
Linear Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
» Advertisements |
» Online Users: 271 |
| 17 members and 254 guests |
| adison, Bertrand21, bravetarget, Dracor, falcon76, ForrestShi, iSdkDev, jordanclark1993, leeus, LemonMeringue, lepetitapps, ltgbau, pereorra, rajeshgautam, refreshe, Tambourin, warcrow |
| Most users ever online was 779, 05-11-2009 at 09:55 AM. |
» Stats |
Members: 24,226
Threads: 39,006
Posts: 171,094
Top Poster: smasher (2,570)
|
| Welcome to our newest member, mellisakelien54 |
|