GPN 3.0.2

GPN 3.0.2

测试已测试
Lang语言 Obj-CObjective C
许可证 Apache 2
发布上次发布2015年6月

AlexL Work MacBook Pro维护。



GPN 3.0.2

使用方法

要运行示例项目,克隆仓库,并在Example目录下首先运行pod install

需求

安装

GPN可以通过CocoaPods获得。要安装它,只需将以下行添加到Podfile中

pod "GPN"

GameHouse推广网络让您可以用智能和控制来驱动应用安装。您可以通过将这个开源SDK集成到您的iOS应用中来参与GPN。也适用于Android。

简单步骤

  1. http://partners.gamehouse.com/gpn/注册GameHouse推广网络。
  2. 注册您的应用,为每个应用获取GPN App ID。
  3. 上传一些营销资产,以使您的应用在其他GPN应用中被推广。
  4. 将此SDK集成到您的应用程序中,以开始显示其他GPN应用的广告。

集成指南

  1. 将"GPN" pod添加到Podfile中。

  2. 在您的应用程序代理中初始化CrossPromotion单例。请确保包含您的App ID

    #import <CrossPromotion.h>
    ...
    - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
    {
        ...    
        [CrossPromotion initializeWithAppId:@"your_app_id"];            
        return YES;
    }
    
  3. 采用CPInterstitialAdViewDelegate协议(通常在UIViewController类的一个子类中)

    #import <CrossPromotion.h>
    
    @interface ViewController () <CPInterstitialAdViewDelegate>
    ...
    @end
    
    @implementation ViewController
    ...
    
    #pragma mark -
    #pragma mark CPInterstitialAdViewDelegate
    
    // Interstitial ad is received: it’s safe to present it now.
    - (void)interstitialAdDidReceive:(CPInterstitialAdView *)adView
    {
        NSLog(@"Interstitial ad received");
    }
    
    //  Interstitial ad is failed to receive.
    - (void)interstitialAdDidFail:(CPInterstitialAdView *)adView withError:(NSError *)error
    {
        NSLog(@"Failed to receive interstitial ad: %@", [error localizedDescription]);
    }
    
    // Interstitial ad will present full screen modal view.
    - (void)interstitialAdWillOpen:(CPInterstitialAdView *)adView
    {
        NSLog(@"Interstitial ad will open");
    }
    
    // Interstitial ad presented full screen modal view. You can pause your game here.
    - (void)interstitialAdDidOpen:(CPInterstitialAdView *)adView
    {
        NSLog(@"Interstitial ad did open");
    }
    
    // Interstitial ad will hide full screen modal view.
    - (void)interstitialAdWillClose:(CPInterstitialAdView *)adView
    {
        NSLog(@"Interstitial ad did close");
    }
    
    // Interstitial ad hided full screen modal view. You can resume your game here.
    - (void)interstitialAdDidClose:(CPInterstitialAdView *)adView
    {
        NSLog(@"Interstitial ad did close");
    }
    
    // Return YES if ad should be destroyed on a low memory warning.
    - (BOOL)interstitialAdShouldDestroyOnLowMemory
    {
        return YES;
    }
    
    // Interstitial ad was destroyed after receiving low memory warning.
    - (void)interstitialAdLowMemoryDidDestroy
    {
        NSLog(@"Interstitial ad is destroyed due to low memory warning");
    }
    ...
    @end
    
  4. 从服务器开始请求插入式广告

    [[CrossPromotion sharedInstance] startRequestingInterstitialsWithDelegate:self]; // enclosing class should adopt CPInterstitialAdViewDelegate protocol
    

    注意:你应该只调用一次 startRequestingInterstitialsWithDelegate:。插屏旋转由SDK自动处理。每次收到新的插屏时都会调用CPInterstitialAdViewDelegate的interstitialAdDidReceive:。只有在网络错误发生并且fire interstitialAdDidFail:withError:时,您才需要调用 startRequestingInterstitialsWithDelegate:。如果收到低内存警告,广告服务可能会停止,但在此情况下,SDK会自动恢复广告服务(当更多内存可用时)。有关更多信息,请参阅“低内存警告”部分。

  5. 每当适当的时候调用“present”方法来显示插入式广告(例如,在关卡之间)。如果广告已完全预加载,则会显示广告。在调用代理的“收到”回调方法后显示插入式广告是安全的

    CPInterstitialResult result = [[CrossPromotion sharedInstance] present];
    if (result != CPInterstitialResultPresented)
    {
        CPDiagnosticMsg(@"Unable to present interstitial ad view");
    }
    

    可能的返回值

    CPInterstitialResultPresented: “present” call succeed: an interstitial ad will be presented fullscreen
    CPInterstitialResultNotPresented: “present” call did not result in showing an ad
    CPInterstitialResultNotPresentedForbidsPosition: interstitial "position" is disabled
    

预告片视频横幅模式

如果您想在横幅模式下的竖屏应用程序中播放视频预告片

  1. 在应用程序设置中启用横幅方向

    Check “Landscape Left” and “Landscape Right” button on the “Summary” tab of your app target settings.  
    -or-  
    Add “Landscape (left home button)” and “Landscape (right home button)” to the “Supported interface orientations” on the “Info” tab of your app target settings.  
    
  2. 将您的UIViewController(s)的首选方向设置为横幅

    #pragma mark -
    #pragma mark Interface Orientations
    
    // iOS 6.0+
    - (NSUInteger)supportedInterfaceOrientations
    {
        return UIInterfaceOrientationMaskPortrait;
    }
    
    // pre iOS 6.0
    -(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)orientation
    {
        if (orientation == UIInterfaceOrientationPortrait)
            return YES;
    
        return NO;
    }
    

广告位置

如果您想在游戏的不同位置定义不同的广告行为,您可以在调用 "present" 方法时包含一个可选的参数字典来传递 "position" 参数。例如

NSDictionary *params = @{ "position" : "startup" };
CPInterstitialResult result = [[CrossPromotion sharedInstance] presentWithParams:params];
if (result != CPInterstitialResultPresented)
{
    CPDiagnosticMsg(@"Unable to present interstitial ad view");
}

目前,我们只能识别三个位置值

  • 启动
  • 横幅广告
  • 试用结束

如果您想定义其他位置,请与我们联系。

低内存警告

GPN SDK 会监听低内存警告通知,并在发生低内存情况时停止投放广告以尽可能释放内存。您可以通过实现 CPInterstitialAdViewDelegate 的可选方法来影响其行为

    - (BOOL)interstitialAdShouldDestroyOnLowMemory; 

由于低内存可能会使您的应用崩溃,您应该自行承担风险。默认情况下,广告投放会停止,并且会调用可选的 CPInterstitialAdViewDelegate 的方法

    - (void)interstitialAdLowMemoryDidDestroy;

注意 当可用内存更多时,广告投放将自动恢复:您不需要调用 startRequestingInterstitialsWithDelegate: 方法。

可选广告参数

每个广告请求都可以包含一组可选参数。为了添加它们,您应该实现 CPInterstitialAdViewDelegate 的可选方法

    - (NSDictionary *)interstitialAdParams
    {
        return @{ <key1> : <value1>, <key2> : <value2>, ... };
    }

跟踪内购

GPN 可以观察内购活动以改进广告定位(例如,对已通过内购产生收益的用户显示更少的广告,或对愿意花钱的用户显示更多广告)。按照以下步骤启用此功能

  1. 如上所述初始化 GPN。(确保您在添加 SKPaymentTransactionObserver 之前已经完成了此操作。)

  2. 注册您的 SKPaymentTransactionObserver

    [[SKPaymentQueue defaultQueue] addTransactionObserver:observer];
    
  3. 将您的购买注册到 GPN

    - (void)paymentQueue:(SKPaymentQueue *)queue updatedTransactions:(NSArray *)transactions
    {
        for (SKPaymentTransaction *transaction in transactions)
        {
            switch (transaction.transactionState)
            {
                case SKPaymentTransactionStatePurchased:
                    [[CrossPromotion sharedInstance] queueTransaction:transaction];
                    ...
                    [[SKPaymentQueue defaultQueue] finishTransaction:transaction];
                    break;
                case SKPaymentTransactionStateFailed:
                    ...
                    break;
            }
        }
    }
    

作者

游戏 House,[email protected]

许可

GPN 提供的许可协议是 Apache License,Version 2.0。有关更多信息,请参阅 LICENSE 文件。