iOS InApp Documentation - yanivav/Documentation GitHub Wiki

Last SDK Version: 2.4.2

For Swift documentation, please click here.

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/paste 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 [email protected]


##Step 1, Adding the StartApp SDK to your project

NOTE: If you're upgrading from an StartApp SDK, please refer to the Advanced Usage section before moving forward with the steps below.

  1. Right-click on you project and choose "Add Files to…"
  2. Add the StartApp SDK files:
    StartApp.framework
    StartApp.bundle

Back to top

##Step 2, Adding 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_
_QuartzCore.framework_
_libz.dylib_

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 <StartApp/StartApp.h>

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

    return YES;
}

Replace "your account id" and "your app id" with your own values provided in the developers’ portal.
After logging in, your account ID will be displayed at the top right-hand corner of the page:

To find your application ID, click on the "Apps and Sites" tab on the left pane and choose the relevant ID from your app list:

Back to top

##Showing Splash Ad (recommended) A Splash Ad is a full-page ad that is displayed immediately after the application is launched. A Splash Ad first displays a full page splash screen that you define (as described below) followed by a full page ad.

StartApp Splash Ad is a top performing ad unit, presenting the industry's highest CPM's

StartApp SDK provides two modes for displaying Splash screens:

Splash Screen Mode Description
User-Defined Mode (default) Using your application's default splash image, with a loading animation
Template Mode StartApp SDK provides a pre-defined template in which you can place your own creatives, such as application name, logo and loading animation. for more details, please refer to the "Advanced Manual"

####Adding the Splash Screen In your application delegate class (AppDelegate.m), after initializing the SDK, call the sdk showSplashAd method:

// AppDelegate.m

#import <StartApp/StartApp.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 showSplashAd];  // display the splash screen

    return YES;
}

If you wish to customize or use a different splash screen, please refer to the Advanced Usage.

Back to top

##Showing Interstitial Ads ######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.

Import the StartApp SDK in your view controller and call showAd where you want to show the ad

// YourViewController.m
#import <StartApp/StartApp.h>

[STAStartAppAdBasic showAd];

NOTE
If you need to gain more control over your interstitial ad like using callbacks or multiple ads with different properties, you should implement it as an object. For more info please refer to the Advanced Usage

Back to top

##Return Ads The **Return Ad** is a new ad unit which is displayed once the user returns to your application after a certain period of time. To minimize the intrusiveness, short time periods are ignored. For example, the Return Ad won't be displayed if the user leaves your application to take a short phone call before returning.

Return ads are enabled and activated by default. If you want to disable this feature, simply call [sdk disableReturnAd] as part of the initialization process, in your AppDelegate.m file:

// AppDelegate.m

#import <StartApp/StartApp.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 disableReturnAd];  // disable return ads

   return YES;
}

Back to top

##Native Ads A "Native Ad" is a raw representation of an ad without any pre-defined wrapping UI, which gives you the freedom to design and control the ad exactly as you want. Using Native Ads, you can design an ad experience that perfectly fits your application's scene, content and functionality.

For a full integration guide, please refer to the "Using Native Ads" section under the "Advanced Usage" page.

Back to top

##Showing 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 <StartApp/StartApp.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];
}

The STA_AutoAdSize detects the width of the device's screen in its current orientation, and provides the optimal banner for this size.

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 Implement didRotateFromInterfaceOrientation in your view controller

// YourViewController.m

- (void) didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation {
    [bannerView didRotateFromInterfaceOrientation:fromInterfaceOrientation];
    [super didRotateFromInterfaceOrientation:fromInterfaceOrientation];    
}

4 If your app supports iOS 8, implement viewWillTransitionToSize in your view controller

// YourViewController.m

- (void)viewWillTransitionToSize:(CGSize)size withTransitionCoordinator:(id<UIViewControllerTransitionCoordinator>)coordinator {
    [bannerView viewWillTransitionToSize:size withTransitionCoordinator:coordinator];
	[super viewWillTransitionToSize:size withTransitionCoordinator:coordinator];
}  
####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 <StartApp/StartApp.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

⚠️ **GitHub.com Fallback** ⚠️