版本 3.1.7
这是TapIt!移动广告网络的iOS SDK。详情请访问http://tapit.com/并注册。
要安装,将TapIt.framework和其他TapIt.bundle文件拖入Xcode项目。
以下框架是必需的
SystemConfiguration.framework
QuartsCore.framework
CoreTelephony.framework
MessageUI.framework
EventKit.framework
EventKitUI.framework
CoreMedia.framework
AVFoundation.framework
MediaPlayer.framework
AudioToolbox.framework
AdSupport.framework - enable support for IDFA
StoreKit.framework - enable use of SKStoreProductViewController, displays app store ads without leaving your app
CoreLocation.framework - Optional *
*注意:CoreLocation是可选的,用于地理定位广告。Apple要求您的应用应有很好的理由启用位置服务... 如果位置不是您的应用核心功能,Apple将拒绝您的应用。
您已完成设置!
//In your AppDelegate.m file:
#import <TapIt/TapItAppTracker.h>
...
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
TapItAppTracker *appTracker = [TapItAppTracker sharedAppTracker];
[appTracker reportApplicationOpen];
return YES;
}
// in your .h file
#import <TapIt/TapItBannerAdView.h>
@property (retain, nonatomic) TapItBannerAdView *tapitAd;
...
// in your .m file
#import <TapIt/TapIt.h>
...
// init banner and add to your view
self.tapitAd = [[TapItBannerAdView alloc] initWithFrame:CGRectMake(0, 0, 320, 50)];
[self.view addSubview:self.tapitAd];
// kick off banner rotation!
[self.tapitAd startServingAdsForRequest:[TapItRequest requestWithAdZone:@"*YOUR ZONE ID*"]];
...
// We don't want to show ads any more...
[self.tapitAd hide];
[self.tapitAd cancelAds];
完整的示例,请参阅https://github.com/tapit/TapIt-iOS-SDK/blob/master/TapIt-iOS-Sample/BannerAdController.m
模态显示
// in your .h file
#import <TapIt/TapIt.h>
...
@property (retain, nonatomic) TapItInterstitialAd *interstitialAd;
...
// in your .m file
// init and load interstitial
self.interstitialAd = [[[TapItInterstitialAd alloc] init] autorelease];
self.interstitialAd.delegate = self; // notify me of the interstitial's state changes
TapItRequest *request = [TapItRequest requestWithAdZone:@"*YOUR ZONE ID*"];
[self.interstitialAd loadInterstitialForRequest:request];
...
- (void)tapitInterstitialAdDidLoad:(TapItInterstitialAd *)interstitialAd {
// Ad is ready for display... show it!
[self.interstitialAd presentFromViewController:self];
}
完整的示例,请参阅https://github.com/tapit/TapIt-iOS-SDK/blob/master/TapIt-iOS-Sample/InterstitialController.m
包含在页面导航中
@property (retain, nonatomic) TapItInterstitialAd *interstitialAd;
...
// init and load interstitial
self.interstitialAd = [[[TapItInterstitialAd alloc] init] autorelease];
TapItRequest *request = [TapItRequest requestWithAdZone:@"*YOUR ZONE ID*"];
[self.interstitialAd loadInterstitialForRequest:request];
...
// if interstitial is ready, show
if( self.interstitialAd.isLoaded ) {
[self.interstitialAd presentInView:self.view];
}
请参阅VideoInterstitialViewController.h和VideoInterstitialViewController.m文件中的示例视频广告集成代码。您可以在iOS SDK包的TapIt-iOS-Sample目录中找到VideoInterstitialViewController。
在从服务器请求视频广告时,需要实例化TVASTAdsRequest对象并指定其zoneId参数。此参数对于成功检索广告是必需的。
// Create an adsRequest object and request ads from the ad server with your own kZoneIdVideo
TVASTAdsRequest *request = [TVASTAdsRequest requestWithAdZone:kZoneIdVideo;
[self.videoAd requestAdsWithRequestObject:request];
如果您想指定请求的视频广告类型,请使用以下调用。
TVASTAdsRequest *request = [TVASTAdsRequest requestWithAdZone:kZoneIdVideo];
[self.videoAd requestAdsWithRequestObject:request andVideoType:TapItVideoTypeMidroll];
实质上,代码中需要包含以下内容:注意:以下使用了自动引用计数,因此不会显示任何对象释放。
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view.
self.videoAd = [[TapItVideoInterstitialAd alloc] init];
self.videoAd.delegate = self;
// Optional... override the presentingViewController (defaults to the delegate)
//self.videoAd.presentingViewController = self;
[self requestAds];
}
- (void)requestAds {
// Create an adsRequest object and request ads from the ad server with your own kZoneIdVideo
TVASTAdsRequest *request = [TVASTAdsRequest requestWithAdZone:kZoneIdVideo];
[self.videoAd requestAdsWithRequestObject:request];
//If you want to specify the type of video ad you are requesting, use the call below.
//[self.videoAd requestAdsWithRequestObject:request andVideoType:TapItVideoTypeMidroll];
}
- (void)tapitVideoInterstitialAdDidFinish:(TapItVideoInterstitialAd *)videoAd {
NSLog(@"Override point for resuming your app's content.");
[self.videoAd unloadAdsManager];
}
- (void)viewDidUnload {
[self.videoAd unloadAdsManager];
[super viewDidUnload];
}
- (void)tapitVideoInterstitialAdDidLoad:(TapItVideoInterstitialAd *)videoAd {
NSLog(@"We received an ad... now show it.");
[self.videoAd playVideoFromAdsManager];
}
- (void)tapitVideoInterstitialAdDidFail:(TapItVideoInterstitialAd *)videoAd withErrorString:(NSString *)error {
NSLog(@"%@", error);
}
// in your .h file
#import <TapIt/TapItNativeAdManager.h>
@interface MyViewController : UIViewController <TapItNativeAdDelegate>
@property (nonatomic, retain) TapItNativeAdManager *tiNativeManager;
...
// in your .m file
#import <TapIt/TapIt.h>
...
tiNativeManager = [[TapItNativeAdManager alloc] init];
tiNativeManager.delegate = self;
TapItRequest *request = [TapItRequest requestWithAdZone:*YOUR ZONE ID* andCustomParameters:params];
[tiNativeManager getAdsForRequest:request withRequestedNumberOfAds:10];
...
- (void)tapitNativeAdManagerDidLoad:(TapItNativeAdManager *)nativeAdManager {
TapItNativeAd *newAd = [nativeAdManager.allNativeAds objectAtIndex:0];
// Get data from `newAd` and add fields to your view
...
UILabel *titleLabel = [[UILabel alloc] init];
[titleLabel setFrame:CGRectMake(10,50,300,20)];
titleLabel.backgroundColor=[UIColor clearColor];
titleLabel.textColor=[UIColor blackColor];
titleLabel.userInteractionEnabled=YES;
titleLabel.text = newAd.adTitle;
[self.view addSubview:titleLabel];
[titleLabel release];
...
// Add a touch recognizer to native element(s) to enable landing page access
UITapGestureRecognizer *tapGestureRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(labelTapped)];
tapGestureRecognizer.numberOfTapsRequired = 1;
[titleLabel addGestureRecognizer:tapGestureRecognizer];
// Log the native ad impression
[nativeAdManager logNativeAdImpression:newAd];
}
- (void)labelTapped {
TapItNativeAd *newAd = [tiNativeManager.allNativeAds objectAtIndex:0];
[tiNativeManager nativeAdWasTouched:newAd];
}
- (void)tapitNativeAdManager:(TapItNativeAdManager *)nativeAdManager didFailToReceiveAdWithError:(NSError *)error {
NSLog(@"Native Ad Manager failed to load with the following error: %@", error.localizedDescription);
}
...
完整的示例,请参阅https://github.com/tapit/TapIt-iOS-SDK/blob/master/TapIt-iOS-Sample/NativeAdViewController.m
如果您想启用地理位置定位,请在AppDelegate中监听位置更新
@property (retain, nonatomic) CLLocationManager *locationManager;
...
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
TapItAppTracker *appTracker = [TapItAppTracker sharedAppTracker];
[appTracker reportApplicationOpen];
// start listening for location updates
self.locationManager = [[CLLocationManager alloc] init];
self.locationManager.delegate = self;
// iOS 8 check
if ([self.locationManager respondsToSelector:@selector(requestWhenInUseAuthorization)]) {
[self.locationManager requestWhenInUseAuthorization];
}
[self.locationManager startUpdatingLocation];
}
...
- (void)applicationDidEnterBackground:(UIApplication *)application
{
// Stop monitoring location when done to conserve battery life
[self.locationManager stopMonitoringSignificantLocationChanges];
}
...
- (void)applicationDidBecomeActive:(UIApplication *)application
{
// Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
[self.locationManager startMonitoringSignificantLocationChanges];
}
...
- (void)applicationWillTerminate:(UIApplication *)application
{
// Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
[self.locationManager stopMonitoringSignificantLocationChanges];
}
...
然后,在您的广告请求中执行以下操作
TapItRequest *request = [TapItRequest requestWithAdZone:*YOUR ZONE ID*];
AppDelegate *myAppDelegate = (AppDelegate *)([[UIApplication sharedApplication] delegate]);
[request updateLocation:myAppDelegate.locationManager.location];
如果您想自定义用户点击广告时出现的内嵌浏览器控制器的外观,请按照以下说明操作
pwAdsToolbarBgColor,其值为以RGBA格式表示的颜色(例如,橙色为
255 149 0 1)。
pwAdsToolbarTintColor,其值为以RGBA格式表示的颜色(例如,蓝色为
0 0 255 1)。
如果您想自定义横幅广告中的关闭按钮的外观,请按照以下说明操作
pwCustomClose.png。
pwCustomClose.png图像添加到您的Xcode项目中。