Integration – App – iOS SDK
Last Updated
May 2018
- Fix issue with observer where app crash below iOS 11 for latest Xcode.
April 2018
- Fix issue with scaling where aspect ratios of ad and adSpace are same but sizes are different.
March 2018
- MRAID 3 support.
- Expose a boolean property isSizeChangeAutomatic to disable automatic size change of WSAdSpace.
October 2017
- Native header bidding support.
- Now it is possible to check the CPM value of ad before running it.
- Fix permission exception crash for iOS 11 when permission descriptions are missing from info.plist.
- Fix bug where app name contain special character which stops SDK to work.
April 2017
- Audio/Video ads no longer stop other media apps (ex. Spotify) if no audio is played.
- When audio is played the other apps are paused. When media finishes the other audio apps are signaled to let them resume their media. (Tested with Spotify and Apple Music)
- Fix issue where playing a StreamView ad while deallocating the AdSpace could lead to a crash.
- Fix extremely rare crash where RPC communication between ad and native SDK was interrupted by a deallocation.
March 2017
- Fix dangling pointer crash related to deallocation of WSAdSpace (reported by publisher)
- Fix permission exception crash for when permission descriptions are missing from info.plist
November 2016
- Fix bug where opening the landing page from an interstitial ad puts the landing page behind the ad.
- Fix over release issue for WSURLConnectionOperation.
- Add support for bitcode. While this increases the size of the SDK download, it will not significantly increase the size of your app. The app will be sliced on Apple’s servers into specific architecture builds and make the final app download the same size or smaller. To enable bitcode for your app, go to
Project>Build Settings>Build Options
, setEnable Bitcode
toYes
.
Add the Widespace SDK
iOS SDK version 4.10.2 download
Deliverables
AppleDoc Folder
Contains the updated AppleDoc of the SDK where you’ll be able to find more specific information about the methods and events available.
WSLibrary Framework
WSLibrary framework includes all the SDK logic. Through the framework you will also able to access the WSAdSpace.h file including the public delegates and methods that you as a publisher are able to access in order to adapt the SDK integration after your specific environment and needs.
CocoaPods Integration
CocoaPods Integration
What is CocoaPods?
CocoaPods is a package manager with dependency linking designed for use when developing Objective-C (soon also Swift) applications. CocoaPods works by adding a “podfile” to the project folder where deployment platform and current dependencies are defined. CocoaPods will resolve all dependencies for you and keep your code separated from the dependencies in a nice clean way.
Learn more at CocoaPods.org
How to install CocoaPods
Installing CocoaPods is as easy as running this command in your terminal:
$ sudo gem install cocoapods
Add Widespace PodSpec
Create Podfile & install
Create a file called “Podfile” (no extension needed) in your project directory containing this:
source 'https://bitbucket.org/WidespaceGIT/widespacepublicpodrepo.git' platform :ios, '8.0' target 'TARGET_NAME' do pod 'WidespaceSDK' end
Once the file is created, open a terminal in your project folder and run:
$ pod install
When running $ pod install it will automatically generate a new xCode workspace that you will use instead:
PROJECT_NAME.xcworkspace
In your info.plist
Add the following entries to your Info.plist (SupportingFiles/Info.plist).
Note that from iOS 10 you need to include all permissions used in your ‘info.plist’:
Mandatory:
<key>NSLocationWhenInUseUsageDescription</key> <string>This message will be shown for the user when requesting for their location and can be modified</string>
Optional:
<key>NSCalendarsUsageDescription</key> <string>This message will be shown for the user when requesting for their location and can be modified</string> <key>NSPhotoLibraryUsageDescription</key> <string>This message will be shown for the user when requesting for their location and can be modified</string> <key>NSCameraUsageDescription</key> <string>This message will be shown for the user when requesting for their location and can be modified</string>
In ViewController.h
In any ViewController that you want to display ads, you need to import the WSAdSpace.h header and implement the WSAdSpaceDelegate protocol.
include the following code:
// ViewController.h #import <WSLibrary/WSAdSpace.h> @interface ViewController : UIViewController <WSAdSpaceDelegate> @property (strong, nonatomic) WSAdSpace *adSpace; @end
The <WSAdSpaceDelegate> lets your ViewController access its delegate methods.
In ViewController.m
One common way to implement an ad display can look like this:
// ViewController.m - (void)viewDidLoad { // Declare and Initiate the WSAdSpace object self.adSpace = [[WSAdSpace alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, 50) sid:@"64c174ed-9ca1-4390-b456-8bbcd2c89757" autoStart:YES autoUpdate:NO delegate:self]; // Add WSAdSpace as a subview of ViewController [self.view addSubview:_adSpace]; }
Note: “self.view.frame.size” might have to be modified dependent on what view frame you want to pick the size from.
Manual SDK Integration
Manual SDK Integration
Add SDK Manually
Start by downloading the SDK-zip file and unarchive it. The contents of the ZIP-file is the SDK. Add the the files to your project by dragging them to the ‘Frameworks’-folder found in the ‘Project navigator’ of your XCode project. Make sure the ‘Copy items into destination..’-option is highlighted as well as the ‘Add to targets’-option for the targets that you want to be able to show Widespace ads.
The Widespace SDK is now added to your project! The next step is to add the frameworks that is required by the SDK.
Link required Frameworks
- AdSupport.framework
- AVFoundation.framework
- AssetsLibrary.framework
- CoreGraphics.framework
- CoreLocation.framework
- CoreMedia.framework
- CoreMotion.framework
- CoreTelephony.framework
- CoreVideo.framework
- EventKit.framework
- EventKitUI.framework
- Foundation.framework
- QuartzCore.framework
- SafariServices.framework
- SystemConfiguration.framework
- UIKit.framework
- WebKit.framework
To add frameworks in XCode, select the summary tab for the target you want to have access to Widespace ads. Scroll down to the ‘Linked Frameworks and Libraries’-section and select the ‘+’-button. This brings up a dialog that lets you choose frameworks and link them to your target. Use the search field to find the frameworks.
In your info.plist
Add the following entries to your Info.plist (SupportingFiles/Info.plist).
Note that from iOS 10 you need to include all permissions used in your ‘info.plist’:
Mandatory:
<key>NSLocationWhenInUseUsageDescription</key> <string>This message will be shown for the user when requesting for their location and can be modified</string>
Optional:
<key>NSCalendarsUsageDescription</key> <string>This message will be shown for the user when requesting for their location and can be modified</string> <key>NSPhotoLibraryUsageDescription</key> <string>This message will be shown for the user when requesting for their location and can be modified</string> <key>NSCameraUsageDescription</key> <string>This message will be shown for the user when requesting for their location and can be modified</string>
In ViewController.h
In any ViewController that you want to display ads, you need to import the WSAdSpace.h header and implement the WSAdSpaceDelegate protocol.
include the following code:
// ViewController.h #import <WSLibrary/WSAdSpace.h> @interface ViewController : UIViewController <WSAdSpaceDelegate> @property (strong, nonatomic) WSAdSpace *adSpace; @end
The <WSAdSpaceDelegate> lets your ViewController access its delegate methods.
In ViewController.m
One common way to implement an ad display can look like this:
// ViewController.m - (void)viewDidLoad { // Declare and Initiate the WSAdSpace object self.adSpace = [[WSAdSpace alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, 0) sid:@"64c174ed-9ca1-4390-b456-8bbcd2c89757" autoStart:YES autoUpdate:NO delegate:self]; // Add WSAdSpace as a subview of ViewController [self.view addSubview:_adSpace]; }
Note: “self.view.frame.size” might have to be modified dependent on what view frame you want to pick the size from.
Native Header Bidding
Native Header Bidding Example Implementation
It is possible to check the CPM price of the ad before running the ad.
In ViewController.m
Example implementation:
#import <WSLibrary/WSAdSpace.h> @interface ViewController () @property (nonatomic, strong) WSAdSpace *adSpace; @end @implementation ViewController - (void)viewDidLoad { // Initialize ad space with publisher ad space id self.adSpace = [[WSAdSpace alloc] initWithFrame:CGRectMake(0, 0, 320, 50) sid:@"64c174ed-9ca1-4390-b456-8bbcd2c89757" autoStart:NO autoUpdate:NO delegate:nil]; // Add the ad space to view hierarchy [self.view addSubview:self.adSpace]; // Request bid and run the ad if cpm value of the bid is expected. [self.adSpace requestBidWithCurrency:@"EUR" bidHandler:^(WSBid *bid, NSError *error) { if (bid != nil) { if (bid.cpm >= 10.0) { [bid acceptAndRunAd]; } } else { NSLog(@"%@", error.localizedDescription); } }]; } @end
—
Do you have any questions or need further guidance?
Feel free to contact integrations@widespace.com and we’ll do our very best to help you out!