Skip to content

iOS InApp Documentation

StartApp edited this page Jun 22, 2014 · 8 revisions

Last SDK Version: 2.1.1

This document describes the basic procedure for integrating StartApp In-App Ads into your iOS applications.
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, Add the StartApp SDK to your project ####Add the StartApp SDK files to your application project directory

  1. Right-click on you project and choose "Add Files to…"
  2. 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

  1. Select your application project to bring up the project editor
  2. Select your application target to bring up the target editor
  3. Select the Build Phases tab
  4. Disclose the "Link Binary With Libraries" phase
  5. 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

  1. Select your application project to bring up the project editor
  2. Select your application target to bring up the target editor
  3. Select the Build Phases tab
  4. Disclose the "Copy Bundle Resources" phase
  5. 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

Back to top

##Step 2, Add frameworks ####Add the StartApp SDK files to your application project directory 1. Select your application project to bring up the project editor 2. Select your application target to bring up the target editor 3. Select the Build Phases tab and disclose the "Link Binary with Libraries" phase and click the plus button in that phase 4. Add the following frameworks:
_CoreTelephony.framework_
_SystemConfiguration.framework_
_CoreGraphics.framework_
_StoreKit.framework_
_AdSupport.framework_

Back to top

##Step 3, Initialization In your application delegate class (_AppDelegate.m_), import the StartApp SDK and add the following line to your application's ``didFinishLaunchingWithOptions`` function:
// AppDelegate.m

#import "STAStartAppSDK.h"

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    // initialize the SDK with your appID and devID
    STAStartAppSDK* sdk = [STAStartAppSDK sharedInstance];
    sdk.appID = @"your app Id";
    sdk.devID = @"your developer id";

    return YES;
}

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:

Back to top

##Step 4, Show Interstitial Ad ######You can choose to show the interstitial ad in several locations within your application. This could be between stages, while waiting for an action, when pressing a button and more.

First, import the StartApp SDK in your view controller and add the following lines to the header file for each view in which you would like to show an ad

// YourViewController.h
 
#import "STAStartAppAd.h"    // ADD THIS LINE
 
@interface YourViewController : UIViewController 
{
    STAStartAppAd* startAppAd;    // ADD THIS LINE
} 

In your view controller init STAStartAppAd within the viewDidLoad() method and load it within the viewDidAppear() method. Remember to release STAStatAppAd object in your dealloc() method in case you're not using ARC in your project.

// YourViewController.m 

- (void)viewDidLoad {
    [super viewDidLoad];
    startAppAd = [[STAStartAppAd alloc] init];
}

- (void) viewDidAppear:(BOOL)animated {
    [super viewDidAppear:animated];
    [startAppAd loadAd];  // Add this line
}

- (void) dealloc {
    // Don't release startAppAd if you are using ARC in your project
    [startAppAd release];  // Add this line
    [super dealloc];
} 

Finally, add the following lines where you want to show the ad

[startAppAd showAd];

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 call showAd() 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 your viewDidDisappear() function). 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.

Back to top

##Step 5, Show banners ######To display banners in your app, add a **STABannerView** to your application according to the following steps:

1 In the header file of your view controller, import STABannerView.h and STABannerSize.h and declare an STABannerView instance variable

// YourViewController.h

#import <UIKit/UIKit.h>
#import "STABannerView.h"
#import "STABannerSize.h"

@interface YourViewController : UIViewController 
{
    STABannerView* bannerView;
}

2 Create and initialize the STABannerView and add it as a subView to the view where you want it to be displayed. Remember to release the bannerView object in your dealloc() function in case you're not using ARC in your project

// YourViewController.m

- (void) viewDidAppear:(BOOL)animated {
    [super viewDidAppear:animated];
     if (bannerView == nil) {
        bannerView = [[STABannerView alloc] initWithSize:STA_AutoAdSize autoOrigin:STAAdOrigin_Top     
                                            withView:self.view withDelegate:nil];
        [self.view addSubview:bannerView];
    }
}

- (void) dealloc
{
    // Don't release bannerView if you are using ARC in your project
    [bannerView release];  // Add this line
    [super dealloc];
}

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.m

- (void) didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation {
    [bannerView didRotateFromInterfaceOrientation:fromInterfaceOrientation];
    [super didRotateFromInterfaceOrientation:fromInterfaceOrientation];    
}
####Positioning the banner The origin of the banner is determined by the "``autoOrigin``" parameter which can receive one of the following values
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.

NOTE
If you wish to use a fixed origin for the banner, please refer to the "Advanced Manual"

Back to top

##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.

####Set Age and Gender Upon initialization, after providing your DevId and AppId, use the following line:

sdk.preferences = [STASDKPreferences prefrencesWithAge:<USER_AGE> andGender:<USER_GENDER>];
  • 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.m

#import "STAStartAppSDK.h"

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    // initialize the SDK with your appID and devID
    STAStartAppSDK* sdk = [STAStartAppSDK sharedInstance];
    sdk.appID = @"your app Id";
    sdk.devID = @"your developer id";

    sdk.preferences = [STASDKPreferences prefrencesWithAge:22 andGender:STAGender_Male];

    return YES;
}

####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_Longitude> andLongitude:<Real_Latitude>]];

Example

- (void) viewDidAppear:(BOOL)animated {
    [super viewDidAppear:animated];

        [startAppAd loadAdWithAdPreferences:[STAAdPreferences prefrencesWithLatitude:37.3190383911 andLongitude:-121.96269989]];
}

Back to top

##Updating your IDFA Settings When submitting your application to the App Store you need to update its "Advertising Identifier (IDFA)" settings in order to comply with Apple advertising policy.

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"

Back to top

##Sample Project StartApp provides a sample integration project available on [GitHub](https://github.com/StartApp-SDK/StartApp-InApp-iOS-Example-App)

Back to top

##Advanced Usage For advanced usage, please read our ["Advanced Manual"](ios-advanced-usage)

Back to top

Clone this wiki locally