CocoaPods trunk is moving to be read-only. Read more on the blog, there are 19 months to go.
TestsTested | ✗ |
LangLanguage | Obj-CObjective C |
License | MIT |
ReleasedLast Release | Jun 2015 |
Maintained by Nart Shabsough.
Requirements: IOS 6.0 +
RedTroops SDK 3.1.0 currently features:
Push Notifications.
Send user spent time.
4 types of (HTML5/Image/audio) ads.
Setting Up RedTroops SDK 3.1.0 In Your Project
Follow the steps below to get your RedTroops SDK 3.1.0 running:
1) Download the SDK from here.
2) Drag & Drop downloaded files (RedTroops.a + include) to your project.
3) Add following frameworks:
1) In your app delegate (AppDelegate.m), import RTSessionManager
#import "RTSessionManager.h"
2) In your app delegate (AppDelegate.m), find the method
- (BOOL)application:(UIApplication*)application didFinishLaunchingWithOptions:
(NSDictionary*)launchOptions
and add the following line of code
[[RTSessionManager defaultManager]startSessionWithAPIKey:@"Your API KEY"];
3) In your app delegate (AppDelegate.m), find the method
- (void)applicationWillEnterForeground:(UIApplication*)application
and add the following line of code
[[RTSessionManager defaultManager]startSessionWithAPIKey:@"Your API KEY"];
4) In your app delegate (AppDelegate.m), find the method
- (void)applicationWillTerminate:(UIApplication *)application
and add the following line of code
[[RTSessionManager defaultManager] endTheSession];
5) In your app delegate (AppDelegate.m), find the method
(void)applicationDidEnterBackground:(UIApplication *)application
and add the following line of code
[[RTSessionManager defaultManager] endTheSession];
In the targeted viewController.m , add these 2 properties
@property (nonatomic,assign) CGFloat heightOfScreen;
@property (nonatomic,assign) CGFloat widthOfScreen;
and the following method (this method will give the current screen width and height using any iOS)
-(void) getScreenSize
{
NSString *osVersion = [[UIDevice currentDevice] systemVersion];
float osVERSION = [osVersion floatValue];
CGRect screenRect = [[UIScreen mainScreen] bounds];
CGFloat screenWidth = screenRect.size.width;
CGFloat screenHeight = screenRect.size.height;
if (osVERSION >= 8)
{
_heightOfScreen = screenHeight;
_widthOfScreen = screenWidth;
}
else
{
UIInterfaceOrientation statusBarOrientation =[UIApplication sharedApplication].statusBarOrientation;
if (statusBarOrientation==4||statusBarOrientation==3)
{
_heightOfScreen = screenWidth;
_widthOfScreen = screenHeight;
}
else if (statusBarOrientation==1||statusBarOrientation==2)
{
_heightOfScreen = screenHeight;
_widthOfScreen = screenWidth;
}
}
}
1) Import the following file to your view controller
#import "RTAdView.h"
2) In the ViewController.m Interface
@interface ViewController ()
@end
Add the following property
@property (nonatomic,strong) RTAdView *topBanner;
3) Add the following line to your view controller to show the ad
[self getScreenSize];
float widthOfAd;
if ( UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad ){
widthOfAd = _widthOfScreen*0.5;}
else{
widthOfAd = 320;}
float heightOfAd = widthOfAd*(75.0/320);
float xOfAd = (_widthOfScreen-widthOfAd)/2;
float yOfAd = _heightOfScreen-heightOfAd;
self.topBanner = [[RTAdView alloc] initWithSize:RTAdBannerTop];
self.topBanner.frame = CGRectMake(xOfAd,0,widthOfAd,heightOfAd);
[self.view addSubview:self.topBanner];
[self.view bringSubviewToFront:self.topBanner];
[self.topBanner prepareAd];
[self.topBanner loadRequest];
1) Import the following file to your view controller
#import "RTAdView.h"
2) In the ViewController.m Interface
@interface ViewController ()
@end
Add the following property
@property (nonatomic,strong) RTAdView *bottomBanner;
3) Add the following line to your view controller to show the ad
[self getScreenSize];
float widthOfAd;
if ( UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad ){
widthOfAd = _widthOfScreen*0.5;}
else{
widthOfAd = 320;}
float heightOfAd = widthOfAd*(75.0/320);
float xOfAd = (_widthOfScreen-widthOfAd)/2;
float yOfAd = _heightOfScreen-heightOfAd;
self.bottomBanner = [[RTAdView alloc] initWithSize:RTAdBannerBottom];
self.bottomBanner.frame = CGRectMake(xOfAd,yOfAd,widthOfAd,heightOfAd);
[self.view addSubview:self.bottomBanner];
[self.view bringSubviewToFront:self.bottomBanner];
[self.bottomBanner prepareAd];
[self.bottomBanner loadRequest];
Note 1: Banner’s size and position are fixed, changing any will result in removing them from the view.
Note 2: Hidding the adView will result in deleting it. Instead use the following method.
[self.adView removeTheAd];
In the targeted viewController.m , add these 2 properties
@property (nonatomic,assign) CGFloat heightOfScreen;
@property (nonatomic,assign) CGFloat widthOfScreen;
and the following method (this method will give the current screen width and height using any iOS)
-(void) getScreenSize
{
NSString *osVersion = [[UIDevice currentDevice] systemVersion];
float osVERSION = [osVersion floatValue];
CGRect screenRect = [[UIScreen mainScreen] bounds];
CGFloat screenWidth = screenRect.size.width;
CGFloat screenHeight = screenRect.size.height;
if (osVERSION >= 8)
{
_heightOfScreen = screenHeight;
_widthOfScreen = screenWidth;
}
else
{
UIInterfaceOrientation statusBarOrientation =[UIApplication sharedApplication].statusBarOrientation;
if (statusBarOrientation==4||statusBarOrientation==3)
{
_heightOfScreen = screenWidth;
_widthOfScreen = screenHeight;
}
else if (statusBarOrientation==1||statusBarOrientation==2)
{
_heightOfScreen = screenHeight;
_widthOfScreen = screenWidth;
}
}
}
1) Import the following file to your view controller
#import "RTAdView.h"
2) In the ViewController.m Interface
@interface ViewController ()
@end
Add the following property
@property (nonatomic,strong) RTAdView *ad;
3) Add the following lines to your view controller
[self getScreenSize];
self.ad= [[RTAdView alloc] initWithSize:RTAdPopUp];
self.ad.frame = CGRectMake(0,0,_widthOfScreen,_heightOfScreen);
if the view contains a navigation bar:
[self.navigationController.view addSubview:self.ad];
[self.navigationController.view bringSubviewToFront:self.ad];
if the view contains a tab bar:
[self.tabBarController.view addSubview:ad];
[self.tabBarController.view bringSubviewToFront:ad];
else
[self.view addSubview:self.ad];
[self.view bringSubviewToFront:self.ad];
[self.ad prepareAd];
[self.ad loadRequest];
#import "RTAdView.h"
@interface ViewController ()
@end
Add the following property
@property (nonatomic,strong) RTAdView *adView;
self.adView = [[RTAdView alloc] initWithSize:RTAdNative1to1];
self.adView.frame = CGRectMake(100,400,300,50);
[self.view addSubview:self.adView];
[self.view bringSubviewToFront:self.adView];
[self.adView prepareAd];
[self.adView loadRequest];
Note 1.Native ads can be placed anywhere INSIDE the screen. Placing the ad outside the boarder of the screen will result in deleteing the ad. (This also apply after device orientation)
Note 2.The Native must be initialized with respect to the following aspect ratios (4:1 , 3:2).
*Here you can find the guide to add a native ad to a table view.
Note 3: Hidding the adView will result in deleting it. Instead use the following method
[self.adView removeTheAd];
The Audio Ad will play an audio file.
#import "RTAudio.h"
#import <AVFoundation/AVFoundation.h>
@property (nonatomic, strong) AVPlayerItem *playerItem;
self.playerItem = [[AVPlayerItem alloc]init];
RTAudio *player = [[RTAudio alloc]initWithPlayerItem:self.playerItem];
[player playRTAudioAd];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(RedTroopsAudioAdFinished:)
name:AVPlayerItemDidPlayToEndTimeNotification
object:self.playerItem];
and this method is called after the audio ad finished playing
-(void)RedTroopsAudioAdFinished:(NSNotification *) notification {
NSLog(@"Finished");
[[NSNotificationCenter defaultCenter]removeObserver:self name:AVPlayerItemDidPlayToEndTimeNotification object:self.playerItem];
}
** You can find the guide for generating certificates and integrating them with RedTroops on this link
1) Import the following file to your app delegate AppDelegate.m
#import "RTNotificationManager.h"
2) In your app delegate (AppDelegate.m), find the method
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
and add the following line of code
application.applicationIconBadgeNumber = 0 ;
if ([application respondsToSelector:@selector(isRegisteredForRemoteNotifications)])
{
//iOS 8
[application registerUserNotificationSettings:[UIUserNotificationSettings settingsForTypes:
(UIUserNotificationTypeSound | UIUserNotificationTypeAlert |UIUserNotificationTypeBadge) categories:nil]];
[application registerForRemoteNotifications];
} else {
//iOS < 8
[application registerForRemoteNotificationTypes:
(UIUserNotificationTypeBadge | UIUserNotificationTypeSound |UIUserNotificationTypeAlert)];
}
if ([launchOptions objectForKey:UIApplicationLaunchOptionsRemoteNotificationKey])
{
NSDictionary *payload = [launchOptions objectForKey:UIApplicationLaunchOptionsRemoteNotificationKey];
[[RTNotificationManager defaultManager]startProcessingNotificationPayload:payload];
}
*Note: This code snippet handles notifications for iOS 8 and earlier versions. if you are targeting iOS 8 only, you can add the first part of the first if statement.
3) In your app delegate (AppDelegate.m), find the method
-(void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData*)deviceToken
and add the following line of code
[[RTSessionManager defaultManager] registerDeviceToken:deviceToken];
4) In your app delegate (AppDelegate.m), find the method
-(void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo
and add the following line of code
[UIApplication sharedApplication].applicationIconBadgeNumber = [[[userInfo objectForKey:@"aps"] objectForKey: @"badgecount"] intValue];
[[RTNotificationManager defaultManager]startProcessingNotificationPayload:userInfo];
5) In your app delegate (AppDelegate.m), find the method
-(void)application:(UIApplication *)application didFailToRegisterForRemoteNotificationsWithError:(NSError *)error
and add the following line of code
NSLog(@"4:%@", error.localizedDescription);
*Remember: After creating you application on redtroop.com there 2 options (Development and Production).
Development is when your app is still under development and not on the AppStore yet. The certificates on Apple Dev Center are still the development ones.
Production is when your application in on the AppStore. The certificates on Apple Dev Center must be the production ones.
Commom Log Errors
Click here
If you need any help or for more information, please visit: RedTroops Docs