你好,歡迎來到IOS教程網

 Ios教程網 >> IOS編程開發 >> IOS開發綜合 >> APP集成tapjoy積分牆

APP集成tapjoy積分牆

編輯:IOS開發綜合

這邊簡單的寫了一個tapjoy的積分牆Manager類,如果有需要大家可以下載,你只需要在顯示積分牆的地方簡單的調用manager類顯示函數。


[plain]
[[CPTapjoyManager sharedTJManager] showOfferWall]; 

[[CPTapjoyManager sharedTJManager] showOfferWall];
CPTapjoyManager.h頭文件


[plain]
#import <Foundation/Foundation.h> 
#import "TapjoyConnect.h" 
 
#define APP_ID @"fc145b41-7d9b-4942-9d90-6d87162794a5" 
#define APP_SECRET_KEY @"z1cWed53f0ZzRwnOaE3L" 
 
@interface CPTapjoyManager : NSObject<TJCAdDelegate,TJCVideoAdDelegate,TJCViewDelegate,UIAlertViewDelegate> 

    int tapPoints; 
    UIWindow* rootWindow; 

 
 
+(CPTapjoyManager*) sharedTJManager; 
 
 
 
-(void) showOfferWall; 
-(void)showBannerAd; 
-(void)dismissBannerAd; 
 
-(void)showFullScreenAd; 
 
@end 

#import <Foundation/Foundation.h>
#import "TapjoyConnect.h"

#define APP_ID @"fc145b41-7d9b-4942-9d90-6d87162794a5"
#define APP_SECRET_KEY @"z1cWed53f0ZzRwnOaE3L"

@interface CPTapjoyManager : NSObject<TJCAdDelegate,TJCVideoAdDelegate,TJCViewDelegate,UIAlertViewDelegate>
{
    int tapPoints;
    UIWindow* rootWindow;
}


+(CPTapjoyManager*) sharedTJManager;

 

-(void) showOfferWall;
-(void)showBannerAd;
-(void)dismissBannerAd;

-(void)showFullScreenAd;

@end

CPTapjoyManager.m文件


[plain]
#import "CPTapjoyManager.h" 
#import "AppDelegate.h" 
#import "DataManager.h" 
 
 
static CPTapjoyManager * _tjManager; 
 
@implementation CPTapjoyManager 
 
+(CPTapjoyManager *)sharedTJManager 

    if(_tjManager==nil) 
    { 
        _tjManager = [[CPTapjoyManager alloc] init]; 
    } 
    return _tjManager; 

 
 
-(id)init 

    if(self == [super init]) 
    { 
        [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(tjcConnectSuccess:) name:TJC_CONNECT_SUCCESS object:nil]; 
        [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(tjcConnectFail:) name:TJC_CONNECT_FAILED object:nil]; 
         
        [TapjoyConnect requestTapjoyConnect:APP_ID 
                                  secretKey:APP_SECRET_KEY 
                                    options:@{ 
              TJC_OPTION_TRANSITION_EFFECT : @(TJCTransitionExpand), 
                 TJC_OPTION_ENABLE_LOGGING : @(YES), 
             TJC_OPTION_COLLECT_MAC_ADDRESS: @(TJCMacAddressOptionOffWithVersionCheck), 
         // If you are not using Tapjoy Managed currency, you would set your own user ID here. 
         //TJC_OPTON_USER_ID : @"A_UNIQUE_USER_ID" 
         }]; 
         
        //注冊積分牆消息監視 
        [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(offerwallClosed:) name:TJC_VIEW_CLOSED_NOTIFICATION object:nil]; 
         
        //注冊積分查詢、消費監視 
        [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(getTJPoints:) name:TJC_TAP_POINTS_RESPONSE_NOTIFICATION object:nil]; 
        [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(getTJPointsError:) name:TJC_TAP_POINTS_RESPONSE_NOTIFICATION_ERROR object:nil]; 
         
        [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(consumeTJPoints:) name:TJC_SPEND_TAP_POINTS_RESPONSE_NOTIFICATION object:nil]; 
        [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(consumeTJPointsError:) name:TJC_SPEND_TAP_POINTS_RESPONSE_NOTIFICATION_ERROR object:nil]; 
         
        //注冊全屏廣告 
        [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(getTJFullScreenAd:) name:TJC_FULL_SCREEN_AD_RESPONSE_NOTIFICATION object:nil]; 
        [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(fullScreenAdClosed:) name:TJC_VIEW_CLOSED_NOTIFICATION object:nil]; 
 
 
         
    } 
    return self; 

 
//顯示積分牆及獲取積分 
-(void) showOfferWall 

    [TapjoyConnect showOffersWithViewController:[[AppDelegate sharedAppDelegate] rootViewController]]; 
    [TapjoyConnect getTapPoints]; 

//顯示banner廣告 
-(void)showBannerAd 

    [TapjoyConnect getDisplayAdWithDelegate:self]; 
    

-(void)dismissBannerAd 

    [[TapjoyConnect getDisplayAdView] removeFromSuperview]; 
    rootWindow = nil; 

//顯示全屏廣告 
-(void)showFullScreenAd 

    [TapjoyConnect getFullScreenAd]; 
 

#pragma mark Tapjoy Connect Observer Method 
 
//連接監視函數 
-(void)tjcConnectSuccess:(NSNotification*)notifyObj 

    NSLog(@"Tapjoy connect Succeeded"); 

 
 
- (void)tjcConnectFail:(NSNotification*)notifyObj 

    NSLog(@"Tapjoy connect Failed"); 

 
//積分牆監視函數 
-(void)offerwallClosed:(NSNotification*)notifyObj 

    NSLog(@"Offerwall closed"); 

 
//積分 
//獲取監視函數 
-(void)getTJPoints:(NSNotification*)notifyObj 

    NSLog(@"獲取Tapjoy積分成功!"); 
    tapPoints = [(NSNumber*)notifyObj.object intValue]; 
     
    //if(tapPoints<=0)return; 
    UIAlertView * alView= nil; 
    if(tapPoints>0) 
    { 
         alView=[[[UIAlertView alloc] initWithTitle:@"Attention" 
                                               message:[NSString stringWithFormat:@"You still have %d Tapjoy points. Do you want to exchange them to coins?",tapPoints] 
                                               delegate:self 
                                             cancelButtonTitle:@"Cancel" otherButtonTitles:@"OK", nil] autorelease]; 
        [alView show]; 
    } 
    /*else 
    { 
        alView =[[[UIAlertView alloc] initWithTitle:@"Attention" 
                                                          message:[NSString stringWithFormat:@"You have no Tapjoy points. Go ahead to earn more!"] 
                                                         delegate:nil 
                                                cancelButtonTitle:@"OK" otherButtonTitles:nil, nil] autorelease]; 
    } 
     
    [alView show];*/ 

-(void)getTJPointsError:(NSNotification*)notifyObj 

    NSLog(@"獲取Tapjoy積分失敗!"); 

 
//消費監視函數 
-(void)consumeTJPoints:(NSNotification*)notifyObj 

    NSLog(@"Tapjoy積分消費成功!"); 
    [DataManager shareManager].coins = [DataManager shareManager].coins + tapPoints; 
    UIAlertView * alView =[[[UIAlertView alloc] initWithTitle:@"Congratulations" 
                                                      message:[NSString stringWithFormat:@"You get %d coins successfully!",tapPoints] 
                                                     delegate:nil 
                                            cancelButtonTitle:@"OK" otherButtonTitles:nil, nil] autorelease]; 
    [alView show]; 

-(void)consumeTJPointsError:(NSNotification*)notifyObj 

     NSLog(@"Tapjoy積分消費失敗!"); 
    /* 
    UIAlertView * alView =[[[UIAlertView alloc] initWithTitle:@"Bad News" 
                                                      message:[NSString stringWithFormat:@"Your Tapjoy virtual currency fail to change to coins,now still has %d Tapjoy virtual currency!", tapPoints] 
                                                     delegate:nil 
                                            cancelButtonTitle:@"Cancel" otherButtonTitles:nil, nil] autorelease]; 
    [alView show];*/ 

 
//全屏廣告監視函數 
-(void)getTJFullScreenAd:(NSNotification*)notifyObj 

    [TapjoyConnect showFullScreenAd]; 

//全屏廣告退出函數 
-(void)fullScreenAdClosed:(NSNotification*)notifyObj 

    NSLog(@"Fullscreen Ad closed"); 

 
#pragma mark Tapjoy Display Ads Delegate Methods 
 
- (void)didReceiveAd:(TJCAdView*)adView 

    NSLog(@"Tapjoy Display Ad Received"); 
     
    if(rootWindow == nil) 
    { 
        rootWindow = [[AppDelegate sharedAppDelegate] window]; 
        [rootWindow addSubview:adView]; 
    } 
     

 
 
- (void)didFailWithMessage:(NSString*)msg 

    NSLog(@"No Tapjoy Display Ads available"); 

 
 
- (NSString*)adContentSize 

    return TJC_DISPLAY_AD_SIZE_320X50; 

 
 
- (BOOL)shouldRefreshAd 

    return YES; 

 
 
#pragma mark Tapjoy Video Ad Delegate Methods 
 
- (void)videoAdBegan 

    NSLog(@"Tapjoy Video Ad Began Playing"); 

 
 
- (void)videoAdClosed 

    NSLog(@"Tapjoy Video Ad View Closed"); 

 
 
- (void)videoAdError:(NSString *)errorMsg 

    NSLog(@"Tapjoy Video Ad Error: %@", errorMsg); 

 
 
 
#pragma mark Tapjoy View Delegate Methods 
 
- (void)viewWillAppearWithType:(int)viewType 

    NSLog(@"Tapjoy viewWillAppearWithType: %d", viewType); 

 
 
- (void)viewDidAppearWithType:(int)viewType 

    NSLog(@"Tapjoy viewDidAppearWithType: %d", viewType); 
     

 
 
- (void)viewWillDisappearWithType:(int)viewType 

    NSLog(@"Tapjoy viewWillDisappearWithType: %d", viewType); 

 
 
- (void)viewDidDisappearWithType:(int)viewType 

    NSLog(@"Tapjoy viewDidDisappearWithType: %d", viewType); 

 
 
#pragma mark UIAlertViewDelegate 
 
-(void)alertView:(UIAlertView *)alertView didDismissWithButtonIndex:(NSInteger)buttonIndex { 
    if( buttonIndex == 1) { 
        [TapjoyConnect spendTapPoints:tapPoints]; 
    } 

 
@end 

#import "CPTapjoyManager.h"
#import "AppDelegate.h"
#import "DataManager.h"


static CPTapjoyManager * _tjManager;

@implementation CPTapjoyManager

+(CPTapjoyManager *)sharedTJManager
{
    if(_tjManager==nil)
    {
        _tjManager = [[CPTapjoyManager alloc] init];
    }
    return _tjManager;
}


-(id)init
{
    if(self == [super init])
    {
        [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(tjcConnectSuccess:) name:TJC_CONNECT_SUCCESS object:nil];
        [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(tjcConnectFail:) name:TJC_CONNECT_FAILED object:nil];
       
        [TapjoyConnect requestTapjoyConnect:APP_ID
                                  secretKey:APP_SECRET_KEY
                                    options:@{
              TJC_OPTION_TRANSITION_EFFECT : @(TJCTransitionExpand),
                 TJC_OPTION_ENABLE_LOGGING : @(YES),
             TJC_OPTION_COLLECT_MAC_ADDRESS: @(TJCMacAddressOptionOffWithVersionCheck),
         // If you are not using Tapjoy Managed currency, you would set your own user ID here.
         //TJC_OPTON_USER_ID : @"A_UNIQUE_USER_ID"
         }];
       
        //注冊積分牆消息監視
        [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(offerwallClosed:) name:TJC_VIEW_CLOSED_NOTIFICATION object:nil];
       
        //注冊積分查詢、消費監視
        [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(getTJPoints:) name:TJC_TAP_POINTS_RESPONSE_NOTIFICATION object:nil];
        [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(getTJPointsError:) name:TJC_TAP_POINTS_RESPONSE_NOTIFICATION_ERROR object:nil];
       
        [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(consumeTJPoints:) name:TJC_SPEND_TAP_POINTS_RESPONSE_NOTIFICATION object:nil];
        [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(consumeTJPointsError:) name:TJC_SPEND_TAP_POINTS_RESPONSE_NOTIFICATION_ERROR object:nil];
       
        //注冊全屏廣告
        [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(getTJFullScreenAd:) name:TJC_FULL_SCREEN_AD_RESPONSE_NOTIFICATION object:nil];
        [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(fullScreenAdClosed:) name:TJC_VIEW_CLOSED_NOTIFICATION object:nil];


       
    }
    return self;
}

//顯示積分牆及獲取積分
-(void) showOfferWall
{
    [TapjoyConnect showOffersWithViewController:[[AppDelegate sharedAppDelegate] rootViewController]];
    [TapjoyConnect getTapPoints];
}
//顯示banner廣告
-(void)showBannerAd
{
    [TapjoyConnect getDisplayAdWithDelegate:self];
  
}
-(void)dismissBannerAd
{
    [[TapjoyConnect getDisplayAdView] removeFromSuperview];
    rootWindow = nil;
}
//顯示全屏廣告
-(void)showFullScreenAd
{
    [TapjoyConnect getFullScreenAd];

}
#pragma mark Tapjoy Connect Observer Method

//連接監視函數
-(void)tjcConnectSuccess:(NSNotification*)notifyObj
{
 NSLog(@"Tapjoy connect Succeeded");
}


- (void)tjcConnectFail:(NSNotification*)notifyObj
{
 NSLog(@"Tapjoy connect Failed");
}

//積分牆監視函數
-(void)offerwallClosed:(NSNotification*)notifyObj
{
    NSLog(@"Offerwall closed");
}

//積分
//獲取監視函數
-(void)getTJPoints:(NSNotification*)notifyObj
{
    NSLog(@"獲取Tapjoy積分成功!");
    tapPoints = [(NSNumber*)notifyObj.object intValue];
   
    //if(tapPoints<=0)return;
    UIAlertView * alView= nil;
    if(tapPoints>0)
    {
         alView=[[[UIAlertView alloc] initWithTitle:@"Attention"
                                               message:[NSString stringWithFormat:@"You still have %d Tapjoy points. Do you want to exchange them to coins?",tapPoints]
                                               delegate:self
                                             cancelButtonTitle:@"Cancel" otherButtonTitles:@"OK", nil] autorelease];
        [alView show];
    }
    /*else
    {
        alView =[[[UIAlertView alloc] initWithTitle:@"Attention"
                                                          message:[NSString stringWithFormat:@"You have no Tapjoy points. Go ahead to earn more!"]
                                                         delegate:nil
                                                cancelButtonTitle:@"OK" otherButtonTitles:nil, nil] autorelease];
    }
   
    [alView show];*/
}
-(void)getTJPointsError:(NSNotification*)notifyObj
{
    NSLog(@"獲取Tapjoy積分失敗!");
}

//消費監視函數
-(void)consumeTJPoints:(NSNotification*)notifyObj
{
    NSLog(@"Tapjoy積分消費成功!");
    [DataManager shareManager].coins = [DataManager shareManager].coins + tapPoints;
    UIAlertView * alView =[[[UIAlertView alloc] initWithTitle:@"Congratulations"
                                                      message:[NSString stringWithFormat:@"You get %d coins successfully!",tapPoints]
                                                     delegate:nil
                                            cancelButtonTitle:@"OK" otherButtonTitles:nil, nil] autorelease];
    [alView show];
}
-(void)consumeTJPointsError:(NSNotification*)notifyObj
{
     NSLog(@"Tapjoy積分消費失敗!");
    /*
    UIAlertView * alView =[[[UIAlertView alloc] initWithTitle:@"Bad News"
                                                      message:[NSString stringWithFormat:@"Your Tapjoy virtual currency fail to change to coins,now still has %d Tapjoy virtual currency!", tapPoints]
                                                     delegate:nil
                                            cancelButtonTitle:@"Cancel" otherButtonTitles:nil, nil] autorelease];
    [alView show];*/
}

//全屏廣告監視函數
-(void)getTJFullScreenAd:(NSNotification*)notifyObj
{
    [TapjoyConnect showFullScreenAd];
}
//全屏廣告退出函數
-(void)fullScreenAdClosed:(NSNotification*)notifyObj
{
    NSLog(@"Fullscreen Ad closed");
}

#pragma mark Tapjoy Display Ads Delegate Methods

- (void)didReceiveAd:(TJCAdView*)adView
{
 NSLog(@"Tapjoy Display Ad Received");
   
    if(rootWindow == nil)
    {
        rootWindow = [[AppDelegate sharedAppDelegate] window];
        [rootWindow addSubview:adView];
    }
   
}


- (void)didFailWithMessage:(NSString*)msg
{
 NSLog(@"No Tapjoy Display Ads available");
}


- (NSString*)adContentSize
{
 return TJC_DISPLAY_AD_SIZE_320X50;
}


- (BOOL)shouldRefreshAd
{
 return YES;
}


#pragma mark Tapjoy Video Ad Delegate Methods

- (void)videoAdBegan
{
 NSLog(@"Tapjoy Video Ad Began Playing");
}


- (void)videoAdClosed
{
 NSLog(@"Tapjoy Video Ad View Closed");
}


- (void)videoAdError:(NSString *)errorMsg
{
 NSLog(@"Tapjoy Video Ad Error: %@", errorMsg);
}

 

#pragma mark Tapjoy View Delegate Methods

- (void)viewWillAppearWithType:(int)viewType
{
 NSLog(@"Tapjoy viewWillAppearWithType: %d", viewType);
}


- (void)viewDidAppearWithType:(int)viewType
{
 NSLog(@"Tapjoy viewDidAppearWithType: %d", viewType);
   
}


- (void)viewWillDisappearWithType:(int)viewType
{
 NSLog(@"Tapjoy viewWillDisappearWithType: %d", viewType);
}


- (void)viewDidDisappearWithType:(int)viewType
{
 NSLog(@"Tapjoy viewDidDisappearWithType: %d", viewType);
}


#pragma mark UIAlertViewDelegate

-(void)alertView:(UIAlertView *)alertView didDismissWithButtonIndex:(NSInteger)buttonIndex {
    if( buttonIndex == 1) {
        [TapjoyConnect spendTapPoints:tapPoints];
    }
}

@end

  1. 上一頁:
  2. 下一頁:
蘋果刷機越獄教程| IOS教程問題解答| IOS技巧綜合| IOS7技巧| IOS8教程
Copyright © Ios教程網 All Rights Reserved