Search code examples
objective-cadsmopub

Invalid suffix 'x50' on integer constant


I am integrating MoPub in my app, but ran into the following error when I should write the size on the ad banner: Invalid suffix 'x50' on integer constant

self.adView = [[[MPAdView alloc] initWithAdUnitId:@"adUnitCode" size:320x50] autorelease];

If it does't work to write the size as MoPub said, does anyone know How i can write it?


Solution

  • The method signature is:

    - (id)initWithAdUnitId:(NSString *)adUnitId size:(CGSize)size
    

    so you need to supply a CGSize. That could be done with CGSizeMake(320, 50) or the constant supplied by MoPub: MOPUB_BANNER_SIZE.

    Writing 320x50 looks like an invalid integer to the compiler and that is the reason for the description of the problem.


    So, removing your ARC issue too, you need to import the constants

    #import "MPConstants.h"
    

    and your line will be:

    self.adView = [[MPAdView alloc] initWithAdUnitId:@"adUnitCode" size:MOPUB_BANNER_SIZE];