Swelen Labs

Swelen iOS SDK 5.0 for iPhone and iPad

Last Build: 50000e - 2015/03/30


Swelen iOS SDK for iPhone and iPad - Build 50000e (status: Stable)

The Swelen Mobile Manager SDK is provided as a static library that will be linked directly against your application using Xcode.
This library is named libswAdLib.a and is compatible with iOS 7.0 or later.

Integration instructions

1. Import the SDK folder in your Xcode Project

To do this, simply locate the SwelenSDK folder and drag it onto the root node of your Xcode project.
When asked, click on the checkbox to tell Xcode to copy the files into the project folder (Copy items into destination group's folder).
Select the "Recursively create groups for any added folder" option and click the Finish button.

2. Add the AdSupport, AVFoundation, SystemConfiguration, CoreMotion, CodeTelephony, MediaPlayer, QuartzCore, OpenGLES, AdSupport and CoreGraphics to your project.

In order to add these Frameworks, go to the TARGETS menu of your project and click the "Build Phases" tab.
Collapse the "Link Binary With Libraries" menu and add every framework listed above.

3. Get your slot UID from Swelen and set it in your delegate.

To find your slot UID, log into your Swelen Account, click on
“Sites and Applications”, select an application then copy the desired slot UID.

4. Add the following line into the import section of the view where you want ads.

#import "swAdAPI.h"


Displaying Ads (general concept)

The library expose two main type of object : swAdInterstitial and swAdView. The former is used for interstitial, expend video, and other type of format and the latter for fixed banner.

In order to allocate one of these class, one need to provides a "Slot".

Example :

swAdView *sv = [[swAdView alloc] initWithSlot:@"ab72975504d2326aecea123e34448b7e" andSize:CGSizeMake(768, 90)];
sv.delegate = self;

[attachView addSubview:sv]; // attachView is provided by the host application

[sv loadAd]; // Load a new ad into "sv"

Ad Invocation for Fixed Slots

Example: Creating a fixed 320x50 ad slot

1. Create an UIView object named fixedAdSlot in the @interface of your .h header file

@interface {
	IBOutlet UIView *fixedAdSlot;

2. Open Interface Builder and place a 320x50 UIView where you want ads to appear.
Then set the view outlet to the fixedAdSlot object. (Make sure you set the "view" outlet of the "File's Owner" appropriately).

3. In your code, you need to set the API to display ads within the UIView.

swAdView *sv = [[swAdView alloc] initWithSlot:@"___YOUR_SLOT_UID___" andSize:CGSizeMake(320, 50)];
sv.delegate = self;
[fixedAdSlot addSubview:sv];
[sv loadAd];

Fixed slot properties :

Swelen ads will now be displayed in the fixedAdSlot UIView.
You can load a new ad at any given time by calling [sv loadAd]

Ad Invocation for Interstitials, expand video, and other type of Slots

Create a new interstitial

1. In your code, you need to set the API to display ads within the UIView.

swAdInterstitial *sai = [[swAdInterstitial alloc] initWithSlot:@"f23872ea64050a7dfcae26488e40e48c"];

  One must keep at least one reference to the object.
  loadAd doesn't keep a reference to the object.
  If an ad load while the object is beeing freed, it can lead to a crash
self.inter = sai;
sai.delegate = self;

[sai loadAd];

Interstitials properties :

You can load a new interstitial at any given time by calling [sv loadAd]
Note that you must keep a reference to the returned object.
That is, int the case of ARC, make sure that you keep a strong reference to the object.

Ad Invocation for AdMob (fixed slot)

First, if you are not using the AdMob SDK already, follow the Incorporating the SDK instructions at https://developers.google.com/mobile-ads-sdk/docs/ios/fundamentals

The process is exactly the same than a regular Fixed slot except that you must call SW_LOAD_ADMOB(); after the application has started.

Important note : Add -ObjC to the "Other Link Flags" : How to

#import "swAdAPI.h"
#import "GADBannerView.h"

// [...]

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
	// [...] Regular code here
	return YES;

Delegate Callbacks

Developers interested in getting more control over the implementation can add the following methods in
the instantiation delegate:

Fixed banner

- (void) swAdVideoDidStartPlaying;
- (void) swAdVideoDidStopPlaying;
- (void) swAdDidDisplay:(swAdView *)slot args:(id)args;
- (void) swAdDidFail:(swAdView *)slot args:(id)args;
- (void) swAdDidClose:(swAdView *)slot args:(id)args;
- (void) swAdDidReceiveClick:(swAdView *)slot args:(id)args;


- (void) swAdInterstitialVideoDidStartPlaying;
- (void) swAdInterstitialVideoDidStopPlaying;
- (void) swAdInterstitialDidDisplay:(swAdInterstitial *)slot args:(id)args;
- (void) swAdInterstitialDidFail:(swAdInterstitial *)slot args:(id)args;
- (void) swAdInterstitialDidClose:(swAdInterstitial *)slot args:(id)args;
- (void) swAdInterstitialDidReceiveClick:(swAdInterstitial *)slot args:(id)args;


Errors : codes

swAdDiDFail (or swAdInterstitialDidFail) is triggered with the following errors codes :
SW_ERR_NOADS,            /* No Ad to display on the current slot */
SW_ERR_CON               /* Connection error */,
SW_ERR_ALREADY_RUNNING   /* The Ad is already running */,
SW_ERR_BLOCKED           /* The Ad has been blocked (i.e. another modal or overlay ad is running) */,
SW_ERR_INTERNAL          /* Internal error */,
SW_ERR_SLOT              /* Slot UID not found */	
Example :
- (void) swAdDidFail:(swAdSlot *)slot args:(id)args
    NSLog(@"Ad has failed on %d : %@", slot.tag, [((NSError *)args) localizedDescription]);
	switch([((NSError *)args) code]) {
		case SW_ERR_NOADS:
		NSLog(@"No Ad found !");
		case SW_ERR_CON:
		NSLog(@"Connection Error")
		NSLog(@"An error as occurred");


What's new?

Issues and Known Bugs


Advanced Features: Conversion Tracking

Example: Tracking application downloads

The conversion can be instantiated anywhere. This is an example for Download Tracking, where the instanciation is defined
in applicationDidFinishLaunching. You can use viewDidLoad as well.

- (void)applicationDidFinishLaunching:(UIApplication *)application {
	// .. .... ...
	[[swAdMain sharedSwAd] registerConversion:@"--CONVERSION-UID--" mode:SwConversionModeUnique];

Replace --CONVERSION-UID-- with the UID you have defined on Swelen (in the Conversion Goals tab of an application).

SwConversionModeUnique : the conversion will be registered only one time
SwConversionModeMultiple : the conversion will be registered each time  

The following modes wil be implemented soon, in a futur version:

(soon) SwConversionModeUniquePerVersion : the conversion will be registered only one time per application's version
(soon) SwConversionModeUniquePerSession : the conversion will be registered only one time per session