ios advanced usage - yanivav/Documentation GitHub Wiki
Value | Size | Best fits for |
---|---|---|
STA_AutoAdSize |
Auto-size (recommended) | detects the width of the device's screen in its current orientation, and provides the optimal banner for this size |
STA_PortraitAdSize_320x50 |
320x50 | iPhone/iPod touch in portrait mode |
STA_LandscapeAdSize_480x50 |
480x50 | iPhone/iPod touch in landscape mode |
STA_PortraitAdSize_768x90 |
768x90 | iPad in portrait mode |
STA_LandscapeAdSize_1024x90 |
1024x90 | iPad in landscape mode |
- Add the STABannerDelegateProtocol to the header file
@interface YourViewController : UIViewController <STABannerDelegateProtocol>
{
STABannerView* bannerView;
}
- Use "withDelegate:self" when initializing the STABannerView object:
bannerView = [[STABannerView alloc] initWithSize:STA_AutoAdSize
autoOrigin:STAAdOrigin_Top
withView:self.view
withDelegate:self];
- Implement the following functions:
- (void) didDisplayBannerAd:(STABannerView*)banner;
- (void) failedLoadBannerAd:(STABannerView*)banner withError:(NSError *)error;
- (void) didClickBannerAd:(STABannerView*)banner;
Locating your banner 100 pixels above the view's bottom:
bannerView = [[STABannerView alloc] initWithSize:STA_AutoAdSize
origin:CGPointMake(0, self.view.frame.size.height - 100)
withView:self.view
withDelegate:nil];
To use a different banner origin in a specific layout, call the "setOrigin"/"setStartAppAutoOrigin" with the new origin value.
###Changing the banner size and origin upon rotation If you choose to manually control the banner's size & origin upon rotation, you can do it in the didRotateFromInterfaceOrientation function.Example:
// YourViewController.m
- (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation {
if (UIInterfaceOrientationIsPortrait(self.interfaceOrientation)) {
[bannerView setOrigin:CGPointMake(0, 0)];
} else {
[bannerView setOrigin:CGPointMake(0, 300)];
}
[super didRotateFromInterfaceOrientation:fromInterfaceOrientation];
}
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 <StartApp/StartApp.h>
@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];
###Using Interstitial delegates Set your view controller as a delegate so it is able to receive callbacks from the interstitial ad.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()
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.
- Add the STADelegateProtocol to the header file
@interface YourViewController : UIViewController <STADelegateProtocol>
{
STAStartAppAd* startAppAd;
}
-
Use "withDelegate:self" when calling the loadAd function:
[startAppAd loadAd:STAAdType_Automatic withDelegate:self]
-
Implement the following functions:
- (void) didLoadAd:(STAAbstractAd*)ad;
- (void) failedLoadAd:(STAAbstractAd*)ad withError:(NSError *)error;
- (void) didShowAd:(STAAbstractAd*)ad;
- (void) failedShowAd:(STAAbstractAd*)ad withError:(NSError *)error;
- (void) didCloseAd:(STAAbstractAd*)ad;
- (void) didClickAd:(STAAbstractAd*)ad;
For example - using splash preferences to choose template mode:
STASplashPreferences *splashPreferences = [[STASplashPreferences alloc] init];
splashPreferences.splashMode = STASplashModeTemplate;
[sdk showSplashAdWithPreferences:splashPreferences];
###Splash Preferences API The following API describes all customization options available for the splash screen.
####►Splash screen mode Decide whether to use user-defined or template mode.
Parameter: splashMode
Values:
STASplashModeUserDefined
STASplashModeTemplate
Usage:
splashPreferences.splashMode = STASplashModeTemplate;
####►Change splash image (for user-defined mode) Change the splash screen image, instead of using the default one.
Parameter: splashUserDefinedImageName
Usage:
splashPreferences.splashUserDefinedImageName = @"MyImage";
####►Choosing splash template (for template mode) Choose of of 6 pre-designed templates.
Parameter: splashTemplateTheme
Values:
STASplashTemplateThemeDeepBlue
STASplashTemplateThemeSky
STASplashTemplateThemeAshenSky
STASplashTemplateThemeBlaze
STASplashTemplateThemeGloomy
STASplashTemplateThemeOcean
Usage:
splashPreferences.splashTemplateTheme = STASplashTemplateThemeBlaze;
####►Changing template's icon and title (for template mode) The SDK uses your default application's name and icon. You can choose however to use your own assets.
Parameters:
splashTemplateIconImageName
splashTemplateAppName
Usage:
splashPreferences.splashTemplateIconImageName = @"MyIcon";
splashPreferences.splashTemplateAppName = @"MyAppName";
####►Enable/Disable loading indicator (for user-defined mode) Choose whether to display a loading indicator on the splash screen.
Parameter: isSplashLoadingIndicatorEnabled
Values:
YES
NO
Usage:
splashPreferences.isSplashLoadingIndicatorEnabled = YES;
####►Choose loading indicator's type (for user-defined and template modes) Choose which loading indicator type to display: iOS default activity indicator or a "dots" loading indicator
Parameter: splashLoadingIndicatorType
Values:
STASplashLoadingIndicatorTypeIOS
STASplashLoadingIndicatorTypeDots
Usage:
splashPreferences.splashLoadingIndicatorType = STASplashLoadingIndicatorTypeDots;
####►Change loading indicator's position (for user-defined mode) The loading indicator is displayed by default on the center of the screen. You can choose however to set a custom position.
Parameter: splashLoadingIndicatorCenterPoint
Values:
CGPointMake(x, y)
Usage:
splashPreferences.splashLoadingIndicatorCenterPoint = CGPointMake(100, 100);
####►Force landscape orientation (for user-defined and template modes) The SDK display the splash screen using the orientation supported by the application and the device real orientation. You can choose however to force landscape orientation.
Parameter: isLandscape
Values:
YES
NO
Usage:
splashPreferences.isLandscape = YES;
- Declare an STABannerView instance variable in your UITableView class
@interface YourViewController ()
{
STABannerView* bannerview;
}
@end
- Override the
cellForRowAtIndexPath
method, and add the required code:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell=nil;
cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
}
// ADD THE FOLLOWING LINES
if(bannerview == nil)
{
bannerview = [[STABannerView alloc] initWithSize:STA_AutoAdSize autoOrigin:STAAdOrigin_Top withView:cell withDelegate:self];
}
[bannerview addSTABannerToCell:cell withIndexPath:indexPath atIntexPathRow:2 repeatEach:8];
return cell;
}
Use the addSTABannerToCell
method to set the banner's position and frequency:
-
atIntexPathRow
- set the cell where you want to show the banner -
repeatEach
- set repetition frequency
In the above example, the banner will be displayed at the second cell, and will be repeated each 8 cells.
###Upgrading from an old SDK 1. Remove all old StartApp files (including all .h and .m files, StartApp.bundle and StartApp.framework). 2. Clean your project- Continue to add the new StartApp SDK files to your project, as describes here.
#import <StartApp/StartApp.h>
@interface YourViewController : UIViewController { STAStartAppNativeAd *startAppNativeAd; // ADD THIS LINE }
In your view controller, initialize **STAStartAppNativeAd** within the ``viewDidLoad()`` method and load the ad with your selected preferences.
```objectivec
// YourViewController.m
- (void)viewDidLoad
{
[super viewDidLoad];
startAppNativeAd = [[STAStartAppNativeAd alloc] init];
[startAppNativeAd loadAd];
}
You can check if the ad has been loaded, using startAppNativeAd.adIsLoaded;
.
###Using Native Ad delegates Set your view controller as a delegate so it is able to receive callbacks from the native ad.
- Add the STADelegateProtocol to the header file
@interface YourViewController : UIViewController <STADelegateProtocol>
{
STAStartAppNativeAd *startAppNativeAd;
}
- Implement the following functions
- (void) didLoadAd:(STAAbstractAd*)ad;
- (void) failedLoadAd:(STAAbstractAd*)ad withError:(NSError *)error;
- Load an ad using
loadAdWithDelegate
[startAppNativeAd loadAdWithDelegate:self];
###Using Native Ad Preferences STANativeAdPreferences can be used to customize some of the native ad properties to suit your needs, such as the number of ads to load, the image size of the ad, or whether the image should be pre-cached or not. For a full description of the NativeAdPreferences object, please refer to NativeAdPreferences API.
In order to use the STANativeAdPreferences object, simply use it when loading the ad:
[startAppNativeAd loadAdWithNativeAdPreferences:pref];
Example: load 4 native ads with 100x100 icons, send lat/lon and register for callbacks:
// YourViewController.m
- (void)viewDidLoad
{
[super viewDidLoad];
startAppNativeAd = [[STAStartAppNativeAd alloc] init];
STANativeAdPreferences *pref = [[STANativeAdPreferences alloc]init];
pref.adsNumber = 4; // Select ads number
pref.bitmapSize = SIZE_100X100; //Select image quality
pref.autoBitmapDownload = YES; // When set to NO no images will be downloaded by the SDK
// You can pass longitude/latitude if available
pref.userLocation.latitude = 31.776719;
pref.userLocation.longitude = 35.234508;
[startAppNativeAd loadAdWithDelegate:self withNativeAdPreferences:pref];
}
###Using the Native Ad Object After initializing and loading your STAStartAppNativeAd object, use the STANativeAdDetails object to get details of all returning ads. The STANativeAdDetails object provides access to each ad's details, such as the ad's title, description, image, etc. This object also provides methods for firing an impression once the ad is displayed, and for executing the user's click on the ad. For a full description of the STAStartAppNativeAd object, please refer to NativeAdDetails API.
Example: get some details of the 3rd ad.
STANativeAdDetails *adDetails = [startAppNativeAd.adsDetails objectAtIndex:3];
titleLabel.text=[[startAppNativeAd.adsDetails objectAtIndex:3] title];
descriptionLabel.text=[[startAppNativeAd.adsDetails objectAtIndex:3] description];
imageView.image=[[startAppNativeAd.adsDetails objectAtIndex:3] imageBitmap];
Note: It is possible to get less ads than you requested. It is also possible that no ad will be returned. In this case you will receive an empty array.
###Showing and Clicking a Native Ad
Once you decide to actually show a native ad, you must call the [adDetails sendImpression]
method.
Once the user clicks on the ad, you must call [adDetails sendClick]
method.