红鹰部队 3.1.0

红鹰部队 3.1.0

测试已测试
语言语言 Obj-CObjective C
许可证 MIT
发布最近发布2015年6月

Nart Shabsough维护。



红鹰部队SDK 3.1.0 for IOS

要求:IOS 6.0以上

入门指南

红鹰部队SDK 3.1.0目前具有以下功能

推送通知。

发送用户花费时间。

4种类型(HTML5/图片/音频)的广告。


,(Cocos2d,(Cocos2d-x)和(Unity)文档可用

在您的项目中配置红鹰部队SDK 3.1.0

按照以下步骤来使您的红鹰部队SDK 3.1.0运行

1) 从这里下载SDK。

2) 将下载的文件(RedTroops.a + include)拖放到您的项目中。

3) 添加以下框架

  • SystemConfiguration.framework
  • QuartzCore.framework
  • CoreGraphics.framework
  • Security.framework
  • MobileCoreServices.framework
  • CoreTelephony.framework

初始设置

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];

红鹰部队提供3种类型的广告

1. 横幅(顶部屏幕横幅 - 底部屏幕横幅)
2. 插页式广告
3. 原生动效

1. 横幅

在添加横幅之前

在目标的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;
        }
    }
}
A. 顶部屏幕横幅

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];



B. 底部屏幕横幅

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];

2. 插屏

在添加插屏之前

在目标的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];

3. 原生广告

  1. 将以下文件导入到您的视图控制器
#import "RTAdView.h"
  1. 在 ViewController.m 接口中
@interface ViewController ()

@end

添加以下属性

@property (nonatomic,strong) RTAdView *adView;
  1. 将以下行添加到您的视图控制器以显示广告
    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];
代码的第二行表示广告将放置在位置(x=100,y=400),大小为(宽度=300,高度=50)。
重要说明

说明1:原生广告可以放置在屏幕内部任何位置。将广告放置在屏幕边界之外将导致删除广告。(这也适用于设备方向改变后)

说明2:原生广告必须使用以下纵横比(4:1 , 3:2)初始化。

*在此可以找到将原生广告添加到表格视图的指南。

说明3:隐藏 adView 将导致删除它。相反,请使用以下方法

 [self.adView removeTheAd];

4. 音频广告

音频广告将播放音频文件。

  1. 将以下文件导入到您的视图控制器
#import "RTAudio.h"
#import <AVFoundation/AVFoundation.h>
  1. 将此对象添加到界面
@property (nonatomic, strong) AVPlayerItem *playerItem;
  1. 添加此内容以播放音频广告
    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 文档