0

I'm trying to implement MobFox ad network into my Swift app. The framework is built in ObjC which I'm not familiar with.

I have added my bridging header.

Im getting 2 errors which I cannot figure out. This is the code that is producing the errors:

class ViewController: UIViewController, MobFoxNativeAdDelegate {

...

    func nativeAdFailedToLoadWithError(error: NSError!) {
    }

    func nativeAdWasClicked() {
    }

    func nativeAdWasShown() {
    }

    func publisherIdForMobFoxNativeAdController(controller: MobFoxNativeAdController!) -> String! {
    return "PUBLISHER_ID_HERE"
    }

    func nativeAdDidLoad(ad: MobFoxNativeAd!) {
    }
}

These are the issues:

class ViewController: UIViewController, MobFoxNativeAdDelegate {

The above code causes an error: Type 'ViewController' cannot conform to protocol 'MobFoxNativeAdDelegate' because it has requirements that cannot be satisfied

I'm sure there are no other methods that I need to implement - unless Im mistaken.

The other issue is:

func nativeAdDidLoad(ad: MobFoxNativeAd!) {
}

On this line I get the following error: Use of undeclared type 'MobFoxNativeAd'

The strange thing is XCode doesn't suggest this method when typing, so it seems to be invalid. For example if I type native, xcode suggests nativeAdFailedToLoadWithError, nativeAdWasClicked and nativeAdWasShown - but it does not suggest nativeAdDidLoad.

However, it is a required method.

Looking at the ObjC framework this is what it contains:

@class MobFoxNativeAdController;
@class MobFoxNativeAd;

@protocol MobFoxNativeAdDelegate <NSObject>

- (NSString *)publisherIdForMobFoxNativeAdController:(MobFoxNativeAdController *)controller;

- (void) nativeAdDidLoad:(MobFoxNativeAd *)ad;

- (void) nativeAdFailedToLoadWithError:(NSError *)error;

- (void) nativeAdWasShown;

- (void) nativeAdWasClicked;

- (UIViewController*) viewControllerForNativeAds;

@end

@interface MobFoxNativeAdController : NSObject

@property (strong, nonatomic) NSString *requestURL;
@property (nonatomic, assign) IBOutlet __unsafe_unretained id <MobFoxNativeAdDelegate> delegate;
@property (nonatomic, assign) BOOL locationAwareAdverts;
@property (nonatomic, assign) NSInteger userAge;
@property (nonatomic, strong) NSString* userGender;
@property (nonatomic, strong) NSArray* keywords;

@property (nonatomic, strong) NSArray* adTypes;

- (void)setLocationWithLatitude:(CGFloat)latitude longitude:(CGFloat)longitude;

- (UIView*)getNativeAdViewForResponse:(MobFoxNativeAd*)response xibName:(NSString*)name;

- (void)requestAd;

@end
Bingo
  • 375
  • 6
  • 17

2 Answers2

0

First, you appear to be missing your implementation of viewControllerForNativeAds, it is listed in the protocol and not in the code you posted.

Are you importing the framework module at the top of your .swift file?

Charles A.
  • 10,685
  • 1
  • 42
  • 39
  • no im not importing the framework module - I thought I should too, but isn't this handled by the bridging header? I've looked at an example project written in swift and it doesn't have an import either. Here's the project file: https://github.com/mobfox/MobFox-iOS-Demo/blob/master/MobFoxSwiftDemo/MobFoxSwiftDemo/ViewController.swift – Bingo Oct 22 '15 at 13:35
  • I've added func viewControllerForNativeAds() -> UIViewController! { } I'm not sure if this is the correct implementation. It still doesn't resolve any of the issues though. – Bingo Oct 22 '15 at 13:38
0

I have figured it out. It was caused by a bug in the framework. The file MobFox.h needed to import MobFoxNativeAd.h

Bingo
  • 375
  • 6
  • 17