Register Register Member Login Member Login Member Login Forgot Password ??
PHP , ASP , ASP.NET, VB.NET, C#, Java , jQuery , Android , iOS , Windows Phone



Clound SSD Virtual Server

iOS/iPhone AD BannerView (iAd Framework)

iOS/iPhone AD BannerView (iAd Framework) ในการที่เราสร้าง App บน iPhone หรือ iPad เพื่อให้คนได้ดาวน์โหลด App ที่อยู่บน App Store ไปใช้ ทาง Apple เองก็ได้สร้างช่องทางสำหรับการสร้างรายได้ของ App ต่าง ๆ ด้วยการติด Banner โฆษณา ในตำแหน่งต่าง ๆ ของ App โดย Banner จะเป็นในรูปแบบของ กรอบสีเหลี่ยม ขนาดไม่สูงมาก ซึ่งเราอาจจะพบเห็นได้ในบาง App ที่เป็นพวก Free App ต่าง ๆ โดย Banner นี้เมื่อผู้ใช้ได้ทำการคลิก ก็จะเปิด Popup ซึ่งเป็นหน้า View เปล่า ๆ ขึ้นมา 1 หน้า และก็จะแสดงรายละเอียดต่าง ๆ ของ Ad นั้น ๆ (สำหรับรายได้ต่อคลิกนั้น อันนี้ผมไม่มีข้อมูล)

iOS/iPhone AD BannerView (iAd Framework)

iOS/iPhone AD BannerView (iAd Framework)


AD BannerView

ตัวอย่าง App ของ Thairath LITE ที่ติด AD BannerView โฆษณาหารายได้


ในการที่จะสร้าง Ad โฆษณา Banner นั้นเราจะใช้ Object ที่มีชื่อว่า AD BannerView ซึ่งจะทำงานร่วมกับ iAd Framework ส่วนวิธีการนั้น ไม่ได้ยากอะไรมากมาย ลองมาดูตัวอย่างการสร้าง Banner กับ AD BannerView ด้วย iAd Framework

iOS/iPhone AD BannerView (iAd Framework)

เริ่มต้นด้วยการสร้าง Application แบบ Single View Application แบบง่าย ๆ

iOS/iPhone AD BannerView (iAd Framework)

เลือกและไม่เลือกรายการดังรูป

iOS/iPhone AD BannerView (iAd Framework)

ตอนนี้หน้าจอ View ยังว่าง ๆ

iOS/iPhone AD BannerView (iAd Framework)

คลิกที่ Application หลัก

iOS/iPhone AD BannerView (iAd Framework)

เลื่อนมายังตำแหน่งของ Framework Libraries ให้คลิกที่เครื่องหมายบวก (+)

iOS/iPhone AD BannerView (iAd Framework)

ค้นหา Framework ที่มีชื่อว่า iAd ซึ่งเราจะพบกับ iAd Framework ให้ทำการ Add รายการ Framework นี้เข้ามาใน Project








iOS/iPhone AD BannerView (iAd Framework)

รายการ Framework ถูกเพิ่มเข้ามาใน Project เรียบร้อยแล้ว

iOS/iPhone AD BannerView (iAd Framework)

กลับมาที่หน้าจอ View ให้ลาก AD BannerView มาไว้บนหน้าจอ View

iOS/iPhone AD BannerView (iAd Framework)

ใน Class ของ .h ให้ทำการ #import <iAd/iAd.h> และ Delegate ตัว ADBannerViewDelegate และประกาศตัวแปรดังรูป และก็เชื่อม IBOutlet ให้เรียบร้อยด้วย

iOS/iPhone AD BannerView (iAd Framework)

กลับมาในหน้าจอ View และ AD BannerView ให้คลิกขวาที่ AD BannerView และทำการเชื่อม delegate กับ File's Owner จากนั้น ให้เขียน Code ดังนี้

ViewController.h
//
//  ViewController.h
//  ADBannerViewApp
//
//  Created by Weerachai on 12/1/55 BE.
//  Copyright (c) 2555 Weerachai. All rights reserved.
//

#import <UIKit/UIKit.h>
#import <iAd/iAd.h>

@interface ViewController : UIViewController <ADBannerViewDelegate>
{
    BOOL bannerIsVisible;
    
    IBOutlet ADBannerView *adView;
}

@property (nonatomic,assign) BOOL bannerIsVisible;

@end









ViewController.m
//
//  ViewController.m
//  ADBannerViewApp
//
//  Created by Weerachai on 12/1/55 BE.
//  Copyright (c) 2555 Weerachai. All rights reserved.
//

#import "ViewController.h"

@interface ViewController ()

@end

@implementation ViewController

@synthesize bannerIsVisible;

- (void)viewDidLoad
{
    [super viewDidLoad];
	// Do any additional setup after loading the view, typically from a nib.
    
    adView = [[ADBannerView alloc] initWithFrame:CGRectZero];
    CGRect bannerFrame = adView.frame;
    bannerFrame.origin.y = self.view.frame.size.height;
    adView.frame = bannerFrame;
    
    adView.delegate = self;
    adView.requiredContentSizeIdentifiers = [NSSet setWithObjects:ADBannerContentSizeIdentifierPortrait, ADBannerContentSizeIdentifierLandscape, nil];
    
    self.bannerIsVisible=NO;
}

- (void)bannerViewDidLoadAd:(ADBannerView *)banner
{
    if (!self.bannerIsVisible)
    {
        [UIView beginAnimations:@"animateAdBannerOn" context:NULL];
        [UIView commitAnimations];
        self.bannerIsVisible = YES;
    }
}

- (void)bannerView:(ADBannerView *)banner didFailToReceiveAdWithError:(NSError *)error
{
    if (self.bannerIsVisible)
    {
        [UIView beginAnimations:@"animateAdBannerOff" context:NULL];
        [UIView commitAnimations];
        self.bannerIsVisible = NO;
    }
}

- (BOOL)bannerViewActionShouldBegin:(ADBannerView *)banner willLeaveApplication:(BOOL)willLeave
{
    NSLog(@"Banner view is beginning an ad action");
    BOOL shouldExecuteAction = YES;
    if (!willLeave && shouldExecuteAction)
    {
        // stop all interactive processes in the app
        // [video pause];
        // [audio pause];
    }
    return shouldExecuteAction;
}

- (void)bannerViewActionDidFinish:(ADBannerView *)banner
{
    // resume everything you've stopped
    // [video resume];
    // [audio resume];
}


- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration
{
    if (UIInterfaceOrientationIsLandscape(toInterfaceOrientation))
        adView.currentContentSizeIdentifier = ADBannerContentSizeIdentifierPortrait;
    else
        adView.currentContentSizeIdentifier = ADBannerContentSizeIdentifierLandscape;
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (void)dealloc {
    [adView release];
    [super dealloc];
}
@end



อธิบาย Code เพิ่มเติม สำหรับ Code นั้นไม่มีอะไรซับซ้อน เช่น

bannerViewDidLoadAd // method เมื่อ AD BannerView ทำงาน
didFailToReceiveAdWithError // method เมื่อ AD BannerView ทำงานผิดพลาด
bannerViewActionShouldBegin // method เมื่อ AD BannerView ถูกคลิกโดยผู้ใช้
bannerViewActionDidFinish // method เมื่อ AD BannerView ถูกคลิก และสิ้นสุดการทำงาน


Screenshot

iOS/iPhone AD BannerView (iAd Framework)

แสดง AD BannerView บนหน้าจอ View

iOS/iPhone AD BannerView (iAd Framework)

เมื่อคลิกที่ AD BannerView จะแสดง View ที่เป็น Popup ขึ้นมา

iOS/iPhone AD BannerView (iAd Framework)

แสดง AD BannerView และรายละเอียดของโฆษณานั้น ๆ

   
Share


ช่วยกันสนับสนุนรักษาเว็บไซต์ความรู้แห่งนี้ไว้ด้วยการสนับสนุน Source Code 2.0 ของทีมงานไทยครีเอท


ลองใช้ค้นหาข้อมูล


   


Bookmark.   
       
  By : ThaiCreate.Com Team (บทความเป็นลิขสิทธิ์ของเว็บไทยครีเอทห้ามนำเผยแพร่ ณ เว็บไซต์อื่น ๆ)
  Score Rating :  
  Create/Update Date : 2012-12-03 09:28:31 / 2017-03-26 09:43:14
  Download : Download  iOS/iPhone AD BannerView (iAd Framework)
 Sponsored Links / Related

 
iOS/iPhone Collection View and Master Detail (Objective-C, iPhone, iPad)
Rating :

 
iOS/iPhone Page Control (UIPageControl) and ScrollView (UIScrollView) (iPhone, iPad)
Rating :

 
iOS/iPhone Hide Input Keyboard and Validate Text Field (Password, Number, URL, E-Mail, Phone Number)
Rating :

 
iOS/iPhone Table View Show Enable Edit / Delete Cell (Swipe To Delete) (UITableView)
Rating :

 
iOS/iPhone Search Data from Web Server (URL,Website)
Rating :

 
iOS/iPhone Edit Update Data on Web Server (URL,Website)
Rating :

 
iOS/iPhone Delete Remove Data on Web Server (URL,Website)
Rating :

 
iOS/iPhone Register Form and Send Data to Web Server (PHP & MySQL)
Rating :

 
iOS/iPhone Login Username and Password from Web Server (PHP & MySQL)
Rating :


ThaiCreate.Com Forum


Comunity Forum Free Web Script
Jobs Freelance Free Uploads
Free Web Hosting Free Tools

สอน PHP ผ่าน Youtube ฟรี
สอน Android การเขียนโปรแกรม Android
สอน Windows Phone การเขียนโปรแกรม Windows Phone 7 และ 8
สอน iOS การเขียนโปรแกรม iPhone, iPad
สอน Java การเขียนโปรแกรม ภาษา Java
สอน Java GUI การเขียนโปรแกรม ภาษา Java GUI
สอน JSP การเขียนโปรแกรม ภาษา Java
สอน jQuery การเขียนโปรแกรม ภาษา jQuery
สอน .Net การเขียนโปรแกรม ภาษา .Net
Free Tutorial
สอน Google Maps Api
สอน Windows Service
สอน Entity Framework
สอน Android
สอน Java เขียน Java
Java GUI Swing
สอน JSP (Web App)
iOS (iPhone,iPad)
Windows Phone
Windows Azure
Windows Store
Laravel Framework
Yii PHP Framework
สอน jQuery
สอน jQuery กับ Ajax
สอน PHP OOP (Vdo)
Ajax Tutorials
SQL Tutorials
สอน SQL (Part 2)
JavaScript Tutorial
Javascript Tips
VBScript Tutorial
VBScript Validation
Microsoft Access
MySQL Tutorials
-- Stored Procedure
MariaDB Database
SQL Server Tutorial
SQL Server 2005
SQL Server 2008
SQL Server 2012
-- Stored Procedure
Oracle Database
-- Stored Procedure
SVN (Subversion)
แนวทางการทำ SEO
ปรับแต่งเว็บให้โหลดเร็ว


Hit Link
   







Load balance : Server 03
ThaiCreate.Com Logo
© www.ThaiCreate.Com. 2003-2024 All Rights Reserved.
ไทยครีเอทบริการ จัดทำดูแลแก้ไข Web Application ทุกรูปแบบ (PHP, .Net Application, VB.Net, C#)
[Conditions Privacy Statement] ติดต่อโฆษณา 081-987-6107 อัตราราคา คลิกที่นี่