要求:IOS 6.0以上
红鹰部队SDK 3.1.0目前具有以下功能
推送通知。
发送用户花费时间。
4种类型(HTML5/图片/音频)的广告。
在您的项目中配置红鹰部队SDK 3.1.0
按照以下步骤来使您的红鹰部队SDK 3.1.0运行
1) 从这里下载SDK。
2) 将下载的文件(RedTroops.a + include)拖放到您的项目中。
3) 添加以下框架
1) 在您的应用程序代理(AppDelegate.m)中导入RTSessionManager
#import "RTSessionManager.h"
2) 在您的应用程序代理(AppDelegate.m)中找到以下方法
- (BOOL)application:(UIApplication*)application didFinishLaunchingWithOptions:
(NSDictionary*)launchOptions
并添加以下行代码
[[RTSessionManager defaultManager]startSessionWithAPIKey:@"Your API KEY"];
3) 在您的应用程序代理(AppDelegate.m)中找到以下方法
- (void)applicationWillEnterForeground:(UIApplication*)application
并添加以下行代码
[[RTSessionManager defaultManager]startSessionWithAPIKey:@"Your API KEY"];
4) 在您的应用程序代理(AppDelegate.m)中找到以下方法
- (void)applicationWillTerminate:(UIApplication *)application
并添加以下行代码
[[RTSessionManager defaultManager] endTheSession];
5) 在您的应用程序代理(AppDelegate.m)中找到以下方法
(void)applicationDidEnterBackground:(UIApplication *)application
并添加以下行代码
[[RTSessionManager defaultManager] endTheSession];
在目标的viewController.m中添加以下两个属性
@property (nonatomic,assign) CGFloat heightOfScreen;
@property (nonatomic,assign) CGFloat widthOfScreen;
以及以下方法(此方法将使用任何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) 将以下文件导入到您的viewController中
#import "RTAdView.h"
2) 在 ViewController.m 接口中
@interface ViewController ()
@end
添加以下属性
@property (nonatomic,strong) RTAdView *topBanner;
3) 将以下行添加到您的视图控制器中以显示广告
[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) 将以下文件导入到您的viewController中
#import "RTAdView.h"
2) 在 ViewController.m 接口中
@interface ViewController ()
@end
添加以下属性
@property (nonatomic,strong) RTAdView *bottomBanner;
3) 将以下行添加到您的视图控制器中以显示广告
[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];
说明1:横幅的大小和位置是固定的,任何修改都将导致它们从视图中移除。
说明2:隐藏 adView 将导致删除它。相反,请使用以下方法。
[self.adView removeTheAd];
在目标的viewController.m中添加以下两个属性
@property (nonatomic,assign) CGFloat heightOfScreen;
@property (nonatomic,assign) CGFloat widthOfScreen;
以及以下方法(此方法将使用任何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) 将以下文件导入到您的viewController中
#import "RTAdView.h"
2) 在 ViewController.m 接口中
@interface ViewController ()
@end
添加以下属性
@property (nonatomic,strong) RTAdView *ad;
3) 将以下行添加到您的视图控制器
[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
添加以下属性
@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];
说明1:原生广告可以放置在屏幕内部任何位置。将广告放置在屏幕边界之外将导致删除广告。(这也适用于设备方向改变后)
说明2:原生广告必须使用以下纵横比(4:1 , 3:2)初始化。
*在此可以找到将原生广告添加到表格视图的指南。
说明3:隐藏 adView 将导致删除它。相反,请使用以下方法
[self.adView removeTheAd];
音频广告将播放音频文件。
#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];
此方法是音频广告播放完毕后调用的
-(void)RedTroopsAudioAdFinished:(NSNotification *) notification {
NSLog(@"Finished");
[[NSNotificationCenter defaultCenter]removeObserver:self name:AVPlayerItemDidPlayToEndTimeNotification object:self.playerItem];
}
**您可以在此链接中找到生成证书并将其与 RedTroops 集成的指南。
1) 将以下文件导入到您的应用程序代理 AppDelegate.m
#import "RTNotificationManager.h"
2) 在您的应用程序代理(AppDelegate.m)中找到以下方法
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
并添加以下行代码
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];
}
*注意:此代码段处理 iOS 8 及早期版本的推送通知。如果您仅针对 iOS 8,可以将第一个 if 语句的第一部分添加。
3) 在您的应用程序代理(AppDelegate.m)中找到以下方法
-(void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData*)deviceToken
并添加以下行代码
[[RTSessionManager defaultManager] registerDeviceToken:deviceToken];
4) 在您的应用程序代理(AppDelegate.m)中找到以下方法
-(void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo
并添加以下行代码
[UIApplication sharedApplication].applicationIconBadgeNumber = [[[userInfo objectForKey:@"aps"] objectForKey: @"badgecount"] intValue];
[[RTNotificationManager defaultManager]startProcessingNotificationPayload:userInfo];
5) 在您的应用程序代理(AppDelegate.m)中找到以下方法
-(void)application:(UIApplication *)application didFailToRegisterForRemoteNotificationsWithError:(NSError *)error
并添加以下行代码
NSLog(@"4:%@", error.localizedDescription);
**请记住:在 redtroop.com 上创建应用程序后,有2个选项(开发和生产)。
开发是在您的应用程序仍在开发中且尚未出现在 AppStore 的情况下。Apple 开发中心的证书仍然是开发证书。
生产是当您的应用程序出现在 AppStore 时。Apple 开发中心的证书必须是生产证书。
常见日志错误
点击这里
如果您需要任何帮助或更多信息,请访问: RedTroops 文档