iOS Question Custom size for admob - need help with objc

tufanv

Expert
Licensed User
Longtime User
Hello,

It is possible to set custom size in admob. Objective c code is as follows:

B4X:
GADAdSize size = GADAdSizeFromCGSize(CGSizeMake(300, 50));

How can I implement this line of code during initialization of adview? An example adview init code is:
B4X:
adviewhaber.Initialize("adview","", Page1, sizes.Get(0))

An example by Erel to use medium rect size using obj c is :

B4X:
    #if objc
#import <GoogleMobileAds/GoogleMobileAds.h>
- (NSObject*)SIZE_MEDIUM_RECTANGLE {
  return [NSValue valueWithBytes:&kGADAdSizeMediumRectangle objCType:@encode(GADAdSize)];
}
#end if
 
Last edited:

tufanv

Expert
Licensed User
Longtime User
Try this:
B4X:
- (NSObject*)SIZE_MEDIUM_RECTANGLE {
   GADAdSize size = GADAdSizeFromCGSize(CGSizeMake(300, 50));
  return [NSValue valueWithBytes:&size  objCType:@encode(GADAdSize)];
}
Yes, code compiles Thanks! Is it somehow possible to use a size from a b4i variable instead of using hard coded size in objc code ? I need to set the size according to users screen width and height.
 
Upvote 0

tufanv

Expert
Licensed User
Longtime User
B4X:
Me.As(NativeObject).RunMethod("customSize::", Array(240, 60))

#if OBJC

- (NSObject*)customSize:(int)width :(int)height {
   GADAdSize size = GADAdSizeFromCGSize(CGSizeMake(width, height));
  return [NSValue valueWithBytes:&size  objCType:@encode(GADAdSize)];
}
I just tried the code, I am getting :

B4X:
Method not found: customSize, target: <b4i_main: (null)>

When I initialize the ad. What am i doing wrong here?
B4X:
adviewnoti.Initialize("adviewnoti","ca-app-pu...", pagenoti, no.RunMethod("customSize", Null))
 
Upvote 0
Top