-
Notifications
You must be signed in to change notification settings - Fork 0
iOS Swift InApp Documentation
Last SDK Version: 2.1.1
This document describes the basic procedure for integrating StartApp In-App Ads into your iOS applications written in Swift programming language.
After this simple integration process, StartApp In-App Ads enables you to reap the benefits of StartApp's In-App monetization products, which maximize the revenue generated by your application. All this profit-making is achieved with minimal effort and minimal interference with your users’ experience.
NOTES:
- The code samples in this document can be copy/pasted into your source code
- When submitting your application to the App Store,do not forget to update your "IDFA Settings"
- Please notice that steps 1-3 are mandatory
- If you have any questions, contact us via support@startapp.com
##Step 1, Adding the StartApp SDK to your project
####Add the StartApp SDK files to your application project directory
- Right-click on you project and choose "Add Files to…"
- Add the StartApp SDK files:
libStartAppAdSDK.a
STAStartAppAd.h
STABannerSize.h
STABannerView.h
StartAppAdSDK-resources.bundle
STAAbstractAd.h
STAStartAppSDK.h
####Add the libStartAppAdSDK.a to the Build Phases of the desired target
- Select your application project to bring up the project editor
- Select your application target to bring up the target editor
- Select the Build Phases tab
- Disclose the "Link Binary With Libraries" phase
- Make sure "libStartAppAdSDK.a" exists. if not, click the plus button in that phase, then click "Add Other…" and select the "libStartAppAdSDK.a" file
####Add the Bundle to the Build Phases of the desired target
- Select your application project to bring up the project editor
- Select your application target to bring up the target editor
- Select the Build Phases tab
- Disclose the "Copy Bundle Resources" phase
- Make sure "StartAppAdSDK-resources.bundle" exists. if not, click the plus button in that phase, then click "Add Other…" and select the "StartAppAdSDK-resources.bundle" file
_CoreTelephony.framework_
_SystemConfiguration.framework_
_CoreGraphics.framework_
_StoreKit.framework_
_AdSupport.framework_
##Step 3, Adding the Bridging-Header file
####Create or edit your application's Bridging-Header file
1. Right-click your project and choose “New File…”
2. Choose iOS->Source->Header File->Next
3. Name the file "-Bridging-Header.h”
Please notice: the product name should be identical to the one being used in your build's settings

- Import the following header files:
#import "STAStartAppSDK.h"
#import "STAStartAppAd.h"
#import "STABannerView.h"
#import "STABannerSize.h"
#import "STAAbstractAd.h"// AppDelegate.swift
func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: NSDictionary?) -> Bool {
// initialize the SDK with your appID and devID
var sdk: STAStartAppSDK = STAStartAppSDK.sharedInstance()
sdk.appID = "Your App Id"
sdk.devID = "Your Developer Id"
return true
}Replace "Your Developer Id" and "Your App Id" with your own values provided in the developers’ portal.
After logging in, your developer ID will be at the top right-hand corner of the page:

To find your application ID, click on the
at the top of the main screen and then choose the relevant ID from your app list:

In your view controller declare STAStartAppAd at the begin of the class. Init STAStartAppAd within the viewDidLoad() method and load it within the viewDidAppear() method.
var startAppAdAutoLoad: STAStartAppAd?
override func viewDidLoad() {
super.viewDidLoad()
startAppAd = STAStartAppAd()
}
override func viewDidAppear(animated: Bool) {
super.viewDidAppear(animated)
startAppAd!.loadAd()
}Finally, add the following lines where you want to show the ad
startAppAd!.showAd()##Step 6, Show banners ######To display banners in your app, follow the following steps:IMPORTANT
Loading an ad might take a few seconds so it's important to show the ad as late as you can. In case you callshowAd()while the ad hasn't been successfully loaded yet, nothing will be displayed. For example, if you'd like to show an ad after completing a game's level, the best practice would be to show the ad upon completing the level (for example in yourviewDidDisappear()method). On the other hand, loading and showing the ad together at the beginning of the next level might result with a failure – as the ad might not have enough time to load.
1 In your view controller declare STAStartAppAd at the begin of the class.
// ViewController.swift
var startAppBanner: STABannerView?2 Create and initialize the STABannerView and add it as a subView to the view where you want it to be displayed.
override func viewDidAppear(animated: Bool) {
super.viewDidAppear(animated)
if !startAppBanner {
startAppBanner = STABannerView(size: STA_AutoAdSize, autoOrigin: STAAdOrigin_Top, withView: self.view, withDelegate: nil);
self.view.addSubview(startAppBanner)
}
}NOTE:
- You can find your "developerId" and "appId" the same way as in step 3 above
- This example shows the banner at the top of the root view controller (
self.view), but you can pass any other view where you want to show the banner
3 Finally, implement didRotateFromInterfaceOrientation in your view controller
// YourViewController.swift
override func didRotateFromInterfaceOrientation(fromInterfaceOrientation: UIInterfaceOrientation) {
// notify StartApp auto Banner orientation change
startAppBanner!.didRotateFromInterfaceOrientation(fromInterfaceOrientation)
super.didRotateFromInterfaceOrientation(fromInterfaceOrientation)
}| Value | Position | Behavior |
|---|---|---|
STAAdOrigin_Top |
Auto Top | The banner will be centered and pinned to the top of the view. In case the view is a root view controller, the banner will be located under the status bar, if exists. |
STAAdOrigin_Bottom |
Auto Bottom | The banner will be centered and pinned to the bottom of the view. |
##Enjoy Higher eCPM with Demographic-Targeted Ads If you know your user's gender, age or location, StartApp can use it to serve better-targeted ads which can increase your eCPM and revenue significantly.NOTE
If you wish to use a fixed origin for the banner, please refer to the "Advanced Manual"
####Set Age and Gender Upon initialization, after providing your DevId and AppId, use the following line:
sdk.preferences = STASDKPreferences.prefrencesWithAge(22, andGender: STAGender_Male)- Replace <USER_AGE> with the user's real age
- Replace <USER_GENDER> with the user's real gender, using STAGender_Male or STAGender_Female.
Example
// AppDelegate.swift
func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: NSDictionary?) -> Bool {
// initialize the SDK with your appID and devID
var sdk: STAStartAppSDK = STAStartAppSDK.sharedInstance()
sdk.appID = "Your App Id"
sdk.devID = "Your Developer Id"
sdk.preferences = STASDKPreferences.prefrencesWithAge(22, andGender: STAGender_Male)
return true
}####Set Location The location of the user is a dynamic property which is changed constantly. Hence, you should provide it every time you load a new Ad:
startAppAd!.loadAdWithAdPreferences(STAAdPreferences.prefrencesWithLatitude(<Real_Latitude>, andLongitude: <Real_Longitude>))Example
override func viewDidAppear(animated: Bool) {
super.viewDidAppear(animated)
startAppAd!.loadAdWithAdPreferences(STAAdPreferences.prefrencesWithLatitude(37.3190383911, andLongitude: -121.96269989))
}On the "Advertising Identifier" section:
1 Choose "Yes" on the right pane
2 Opt-in the "Serve advertisements within the app" checkbox
3 Opt-in the confirmation checkbox under "Limit Ad tracking setting in iOS"

Step 1, Adding the StartApp SDK to your project
Step 3, Adding the Bridging-Header file
Enjoy Higher eCPM with Demographic-Targeted Ads
Advanced Usage
Controlling the size of your banner
Using banner delegates
Using a fixed origin for your banner
Changing the banner size and origin upon rotation
Using Interstitial delegates
Explicitly selecting the type of interstitial ad to load
Showing banners in UITableView