「IOS SDK Developer Guide」修訂間的差異

出自TAMedia
跳至導覽 跳至搜尋
imported>Wikiuser
(新頁面: == iOS SDK Developer Guide == *SDK相容性 :目前SDK相容於iOS 4.3以上的版本 :*Valid Architectures為armv7及armv7s :*Base SDK為iOS 6.1 :*Compiler為Apple LLVM compiler 4.2 :...)
 
imported>Wikiuser
 
行 1: 行 1:
== iOS SDK Developer Guide ==
===[[Download]]===
*SDK相容性
:目前SDK相容於iOS 4.3以上的版本
:*Valid Architectures為armv7及armv7s
:*Base SDK為iOS 6.1
:*Compiler為Apple LLVM compiler 4.2
:*Xcode為4.6.2版本
*整合至應用程式
:#將libTWMTAMediaView.a (函式檔) 加入iOS Project中
:#將TWMTAMediaView.h (標頭檔) 加入iOS Project中
:#將TWMTAMediaInterstitialView.h (標頭檔) 加入iOS Project中
:#將CloseButton.png (圖檔) 加入iOS Project中
:#確認原本iOS project是否有將CoreTelephony.framework加入, 若無則加入此framework
:#確認原本iOS project是否有將CoreLocation.framework加入, 若無則加入此framework
:#確認原本iOS project是否有將SystemConfiguration.framework加入, 若無則加入此framework
:#在Targets -> Build Setting裡面設定Other Linker Flags為-ObjC(參考http://developer.apple.com/library/mac/#qa/qa1490/_index.html)
:[[檔案:5.png]]
:[[檔案:6.png]]
*展示Banner廣告
:*Include Header
#import "TWMTAMediaView.h"
:*建立廣告版位
_adView = [[TWMTAMediaView alloc] initWithFrame:frame
                                          slotId:@"xxxxxxxxxx"
                                    developerID:@"my_id"
                                      gpsEnabled:YES
                                        testMode:NO];
:::gpsEnabled : GPS開關,可設定是否啟用GPS
:::testMode : 測試開關,可設定是否為測試模式,測試模式中會在console顯示詳細log
:*Implement Delegate
:我們提供四個Callback方法,可以讓你在Banner廣告載入過程接收到對應的通知
@interface TWMTAMediaViewController () <TWMTAMediaViewDelegate>


_adView.delegate = self;
===[[Getting Started]]===


- (void)viewWillLoadAd:(TWMTAMediaView *)view
===[[Banner Ads I]]===
{
    NSLog(@"%@ viewWillLoadAd", view);
}
- (void)viewDidLoadAd:(TWMTAMediaView *)view
{
    NSLog(@"%@ viewDidLoadAd", view);
}
- (void)view:(TWMTAMediaView *)view didFailToReceiveAdWithError:(NSError *)error
{
    NSLog(@"%@ didFailToReceiveAdWithError:%@", view, error.description);
}
- (BOOL)viewActionShouldBegin:(TWMTAMediaView *)view willLeaveApplication:(BOOL)willLeave
{
    NSLog(@"%@ willLeaveApplication:%i", view, willLeave);
    return YES;
}
:*接收廣告
[_adView receiveAd];
:*dealloc
_adView.delegate = nil;
[_adView release];
_adView = nil;
:::建議在廣告呈現的ViewController要release之前,先將_adView.delegate設為nil
*展示Interstitial廣告
:*Include Header
#import "TWMTAMediaInterstitialView.h"
:*建立廣告版位
CGRect frame = CGRectMake(0, 0, [UIScreen mainScreen].applicationFrame.size.width, [UIScreen mainScreen].applicationFrame.size.height);
_interstitialView = [[TWMTAMediaInterstitialView alloc] initWithFrame:frame
                                                                slotId:@"xxxxxxxxxx"
                                                          developerID:@"my_id"
                                                            gpsEnabled:YES
                                                              testMode:NO];
:::gpsEnabled : GPS開關,可設定是否啟用GPS
:::testMode : 測試開關,可設定是否為測試模式,測試模式中會在console顯示詳細log
:*Implement Delegate
@interface TWMTAMediaViewController () <TWMTAMediaInterstitialViewDelegate>


_interstitialView.delegate = self;
===[[Banners Ads II]]===


- (void)interstitialViewWillLoadAd:(TWMTAMediaInterstitialView *)view
===[[Interstitial Ads]]===
{
 
    NSLog(@"%@ interstitialViewWillLoadAd", view);
===[[Integration with AdMob Mediation]]===
}
- (void)interstitialViewDidLoadAd:(TWMTAMediaInterstitialView *)view
{
    NSLog(@"%@ interstitialViewDidLoadAd", view);
    [_interstitialView showAd:self.view];
}
- (void)interstitialView:(TWMTAMediaInterstitialView *)view didFailToReceiveAdWithError:(NSError *)error
{
      NSLog(@"%@ interstitialViewdidFailToReceiveAdWithError:%@", view, error.description);
}
- (BOOL)interstitialViewActionShouldBegin:(TWMTAMediaInterstitialView *)view willLeaveApplication:(BOOL)willLeave
{
    NSLog(@"%@ interstitialViewwillLeaveApplication:%i", view, willLeave);
    return YES;
}
- (void)interstitialViewWillDisappear:(TWMTAMediaInterstitialView *)view
{
    NSLog(@"%@ interstitialViewWillDisappear", view);
}
- (void)interstitialViewDidDisappear:(TWMTAMediaInterstitialView *)view
{
    NSLog(@"%@ interstitialViewDidDisappear", view);
}
:*接收廣告
[_interstitialView receiveAd];
:::注意:目前Interstitial廣告有相同版位ID在同一台裝置上,每天只會展示一次廣告的限制
:*dealloc
_interstitialView.delegate = nil;
[_interstitialView release];
_interstitialView = nil;
:::建議在廣告呈現的ViewController要release之前,將_interstitialView.delegate設為nil
*與Google AdMob整合
:*一般Banner廣告
::首先將SDK整合至專案中,接著參考https://developers.google.com/mobile-ads-sdk/training/mediation/custom-events/,先設定好Custom Event,最後,在專案中加入Custom Event需要的Class,其中Custom Event的Class Name需要和下面Sample的Class Name保持一致。
#import "TWMTAMediaCustomView.h"
#import "GADCustomEventBanner.h"
#import "GADCustomEventBannerDelegate.h"
#import "TWMTAMediaView.h"
@interface TWMTAMediaCustomView () <GADCustomEventBanner, TWMTAMediaViewDelegate>
{
    TWMTAMediaView *adView;
}
@end
@implementation TWMTAMediaCustomView
@synthesize delegate;
- (void)requestBannerAd:(GADAdSize)adSize
              parameter:(NSString *)serverParameter
                  label:(NSString *)serverLabel
                request:(GADCustomEventRequest *)customEventRequest  {
   
    CGRect frame = CGRectMake(0, 0, adSize.size.width, adSize.size.height);
    adView = [[TWMTAMediaView alloc] initWithFrame:CGRectMake(0, 0, 320, 50)
                                            slotId:serverParameter
                                        developerID:@""
                                        gpsEnabled:YES
                                          testMode:NO];
    adView.delegate = self;
    [adView receiveAd];
}
- (void)viewWillLoadAd:(TWMTAMediaView *)view
{
    NSLog(@"%@ viewWillLoadAd", view);
    [self.delegate customEventBanner:self didReceiveAd:view];
}
- (void)viewDidLoadAd:(TWMTAMediaView *)view
{
    NSLog(@"%@ viewDidLoadAd", view);
    [self.delegate customEventBanner:self didReceiveAd:view];
}
- (void)view:(TWMTAMediaView *)view didFailToReceiveAdWithError:(NSError *)error
{
    NSLog(@"%@ didFailToReceiveAdWithError:%@", view, error.description);
    [self.delegate customEventBanner:self didFailAd:error];
}
- (BOOL)viewActionShouldBegin:(TWMTAMediaView *)view willLeaveApplication:(BOOL)willLeave
{
    NSLog(@"%@ willLeaveApplication:%i", view, willLeave);
    [self.delegate customEventBannerWillLeaveApplication:self];
    return YES;
}
@end
:*Interstitial廣告
#import "TWMTAMediaCustomInterstitialView.h"
#import "GADCustomEventInterstitial.h"
#import "GADCustomEventInterstitialDelegate.h"
#import "TWMTAMediaInterstitialView.h"
@interface TWMTAMediaCustomInterstitialView () <GADCustomEventInterstitial, TWMTAMediaInterstitialViewDelegate>
{
    TWMTAMediaInterstitialView *adView;
}
@end
@implementation TWMTAMediaCustomInterstitialView
@synthesize delegate;
- (void)requestInterstitialAdWithParameter:(NSString *)serverParameter
                                      label:(NSString *)serverLabel
                                    request:(GADCustomEventRequest *)customEventRequest {
   
    CGRect frame = CGRectMake(0, 0, [UIScreen mainScreen].applicationFrame.size.width, [UIScreen mainScreen].applicationFrame.size.height);
    adView = [[TWMTAMediaInterstitialView alloc] initWithFrame:frame
                                                        slotId:serverParameter
                                                    developerID:@""
                                                    gpsEnabled:YES
                                                      testMode:NO];
    adView.delegate = self;
    [adView receiveAd];
}
- (void)presentFromRootViewController:(UIViewController *)rootViewController {
    CGRect frame = CGRectMake(0, 0, 0, 0);
    frame.size.width = [UIScreen mainScreen].applicationFrame.size.width;
    frame.size.height = [UIScreen mainScreen].applicationFrame.size.height;
    adView.frame = frame;
    [rootViewController.view addSubview:adView];
    [rootViewController.view bringSubviewToFront:adView];
}
- (void)interstitialViewWillLoadAd:(TWMTAMediaInterstitialView *)view
{
    NSLog(@"%@ interstitialViewWillLoadAd", view);
    [self.delegate customEventInterstitial:self didReceiveAd:view];
}
- (void)interstitialViewDidLoadAd:(TWMTAMediaInterstitialView *)view
{
    NSLog(@"%@ interstitialViewDidLoadAd", view);
    [self.delegate customEventInterstitial:self didReceiveAd:view];
}
- (void)interstitialView:(TWMTAMediaInterstitialView *)view didFailToReceiveAdWithError:(NSError *)error
{
    NSLog(@"%@ interstitialViewdidFailToReceiveAdWithError:%@", view, error.description);
    [self.delegate customEventInterstitial:self didFailAd:error];
}
- (BOOL)interstitialViewActionShouldBegin:(TWMTAMediaInterstitialView *)view willLeaveApplication:(BOOL)willLeave
{
    NSLog(@"%@ interstitialViewwillLeaveApplication:%i", view, willLeave);
    [self.delegate customEventInterstitialWillLeaveApplication:self];
    return YES;
}
- (void)interstitialViewWillDisappear:(TWMTAMediaInterstitialView *)view
{
    NSLog(@"%@ interstitialViewWillDisappear", view);
    [self.delegate customEventInterstitialWillDismiss:self];
}
- (void)interstitialViewDidDisappear:(TWMTAMediaInterstitialView *)view
{
    NSLog(@"%@ interstitialViewDidDisappear", view);
    [self.delegate customEventInterstitialDidDismiss:self];
}
@end

於 2014年1月28日 (二) 03:07 的最新修訂