1

I am trying to use the Inneractive Ad SDK 5+ in my application and I'd like to position the ad on the bottom. In every case I've tried it will always be in the middle of the screen, centred horizontally and vertically.

Code:

self.myAdView = [[IaAdView alloc]    
initWithAppId:@"MyAppID_iPhone" adType:IaAdType_Banner delegate:self];

self.myAdView.adConfig.refreshIntervalInSec = 30;

[[InneractiveAdSDK sharedInstance] loadAd:self.myAdView];

Delegate method:

- (void)InneractiveAdLoaded:(IaAd *)adView {
    NSLog(@"AD LOADED METHOD CALLED");

    // Here I tried many things I found online without any effect
    [self.view addSubview:self.myAdView];
}

Here how i implement the property at the top of the viewcontroller.m file:

@interface ViewController () <InneractiveAdDelegate>

@property (nonatomic, retain) IaAdView* myAdView;
@end

@implementation ViewController
@synthesize myAdView = _myAdView;

I am sure it must be just a tiny thing but I can't figure it out. I found many solutions that include initWithFrame but this is not usable in this case.

Any help would be appreciated.

Update 1:

I've tried:

- (void)InneractiveAdLoaded:(IaAd *)adView {
    NSLog(@"AD LOADED METHOD CALLED");
    self.myAdView.frame=CGRectMake(x,y,width,height); // With any number and random number

and

    self.myAdView.frame=CGRectOffset(self.myAdView.frame, 0, yOffset); // With any number and random number
    [self.view addSubview:self.myAdView];
}

Nothing helped. Ad stays absolutely centred. I am starting to think there is something wrong with the setup but besides the positioning everything is working fine. See photo below.

app screen

Update 2:

Tried the following without success. ios8 shows banner centred on screen and ios7 for some reason not at all once the line has been added.

- (void)InneractiveAdLoaded:(IaAd *)adView {

     NSLog(@"AD LOADED METHOD CALLED");
    self.myAdView.frame = CGRectMake(0, self.view.frame.size.height -     self.myAdView.frame.size.height , self.view.frame.size.width,    self.myAdView.frame.size.height);

    [self.view addSubview:self.myAdView];

}
SunnySonic
  • 1,318
  • 11
  • 37
  • Why are you using `self.myAdView`? Are you creating a property also? – Daniel Storm Jul 10 '15 at 13:56
  • Yes. The SDK requests to implement it for my understanding like the edit i just did above. – SunnySonic Jul 10 '15 at 14:00
  • Change `@synthesize myAdView = _myAdView;` to `@synthesize myAdView;` Also, can you provide a link to the SDK so I can attempt to implement the banner. – Daniel Storm Jul 10 '15 at 14:05
  • Done. No change so far. Here the link: https://staging.inner-active.com/iamp/publisher/downloadsdk?sdk=files/InneractiveAdSDK-iOS-v5.0.5.zip&sdkName=iOSNative%202 you might have to log in though. Private me and i can email it to you if necessary. – SunnySonic Jul 10 '15 at 14:16

3 Answers3

2

Here's a working solution: You have two options here -

  1. Wrapping your adView in the external UIView and then you have the full control
  2. Updating the frame of adView on the 'InneractiveAdLoaded:' event

ANYWAY: adView must be added to it's superView before calling 'loadAd:' SDK method.

Let me know, if you have any questions.

Update: Option 2:

#import "ViewController.h"
#import "InneractiveAdSDK.h"

@interface ViewController () <InneractiveAdDelegate>

@property (nonatomic, strong) IaAdView *adView;

@end

@implementation ViewController {}

- (void)viewDidLoad {
    [super viewDidLoad];

    self.adView = [[IaAdView alloc] initWithAppId:@"<Your ad unit ID>" adType:IaAdType_Banner delegate:self];

    [self.view addSubview:self.adView];
    [[InneractiveAdSDK sharedInstance] loadAd:self.adView];
}

- (void)positionAd {
    const CGFloat x = (self.view.bounds.size.width - self.adView.frame.size.width) / 2.0f;
    const CGFloat y = self.view.bounds.size.height - self.adView.frame.size.height;

    self.adView.frame = CGRectMake(x, y, self.adView.frame.size.width, self.adView.frame.size.height);
}

#pragma mark - InneractiveAdDelegate

- (void)InneractiveAdLoaded:(IaAd *)adView {
    [self positionAd];
}

- (void)InneractiveDefaultAdLoaded:(IaAd *)adView {
    [self positionAd];
}

- (UIViewController *)viewControllerForPresentingModalView { return self; }

@end

enter image description here

Nikita
  • 1,811
  • 1
  • 20
  • 41
  • Thanks. Do you have some code example for me? Especially option 2 sounds interesting. – SunnySonic Jul 13 '15 at 00:25
  • Please mark as a right answer, in case it helped you. Thanks. – Nikita Jul 13 '15 at 16:25
  • thanks a lot! my app breaks when i'm running it like that on the "positionAd" method. Why could that be? (My app is an universal app upwards from ios7 if that means anything) – SunnySonic Jul 14 '15 at 00:39
  • You should investigate the crash. Try to put exception breakpoint / enable zombie objects or something else. Sometimes, clearing the project derived data also helps (known Xcode bug). P.S. There is no problem in the supplied code. You can open a new project and add the code above (obviously after adding IA SDK and all the dependent frameworks), and it will work. – Nikita Jul 14 '15 at 09:14
  • 1
    all i had to do was delete the breakpoint, which i don't know how it got there in the first place. Anyways, you saved my day! Thanks a lot!! I'm sure it'll help others too! – SunnySonic Jul 14 '15 at 09:49
0

Try setting its frame this way:

self.myAdView.frame=CGRectMake(x,y,width,height);

Where x,y,width,height is your desired position and size.

Or if its already positioned nicely by X coordinate, width and height you could use:

self.myAdView.frame=CGRectOffset(self.myAdView.frame, 0, yOffset);

Where yOffset is how much you want it moved on that coordinate. Be sure you calculate it using self.view.frame and not with exact number, so its on bottom on every device.

Uros19
  • 391
  • 2
  • 11
  • thanks for you prompt reply Uros19. Unfortunately it didnt work. See my updated question above please. – SunnySonic Jul 10 '15 at 12:11
  • Try using adView object thats passed as parameter in (void)InneractiveAdLoaded:(IaAd *)adView method. So instead self.myAdView.frame, try setting adView.frame – Uros19 Jul 10 '15 at 12:57
  • Tried. unfortunately all the same. nothing is moving at all. The strange this is also that i am trying it on ios8 simulator and ios7 iphone 4. Also it is a universal app. The moment i put a line like yours on ios7 the ad completely disappears and on ios8 simulator it stays in the centre. – SunnySonic Jul 10 '15 at 13:53
  • Hmm the only thing i have left in mind is to create UIView and add adView as subview to it, then position new UIView on bottom of screen – Uros19 Jul 10 '15 at 14:40
  • wrapped it in an UIView but now the ads are not clickable/ touchable. What could be the problem here? – SunnySonic Jul 13 '15 at 09:01
0

To position your banner at the bottom of your UIView you need to change its frame.

self.myAdView.frame = CGRectMake(x, y, width, height);

self.myAdView.frame = CGRectMake(0, self.view.frame.size.height - self.myAdView.frame.size.height , self.view.frame.size.width, self.myAdView.frame.size.height);
  • x - Set to origin of 0
  • y - Set origin to the UIView's height. But this will make it appear off the bottom of the screen. So, we must subtract the height of our self.myAdView to move it up onto the screen: self.view.frame.size.height - self.myAdView.frame.size.height
  • width - Set it to the width of the UIView: self.view.frame.size.width
  • height - Set it to the height of our self.myAdView: self.myAdView.frame.size.height
Daniel Storm
  • 18,301
  • 9
  • 84
  • 152
  • Thanks. Nice explanation and it makes sense. Yet it doesn't move anything unfortunately. Please see my edit above. – SunnySonic Jul 10 '15 at 14:12
  • how can i send it to you? i think you need to create a login at inneractive to download it... https://staging.inner-active.com/iamp/publisher/downloadsdk?sdk=files/InneractiveAdSDK-iOS-v5.0.5.zip&sdkName=iOSNative%202 – SunnySonic Jul 10 '15 at 14:18
  • here also the implementation manual: https://inneractive.jira.com/wiki/display/DevWiki/iOS+SDK+guidelines under point 3.8 there is a method to centre the ad which i haven't implemented. I tried implementing it with adjustments but i failed. I also wasnt sure if it had been called at all. If i wanted to implement it that way, how would i have to do it? – SunnySonic Jul 10 '15 at 14:21
  • wrapped it in an UIview but now the ads are not clickable/ touchable. What could be the problem here? – SunnySonic Jul 13 '15 at 09:01