Android DeveloperDeveloperFeaturedGoogle DevelopersiOS DeveloperMobile TechnologyNewbie

ทำเงินบน แอพฯ iPhone และ iPad ด้วยการติดตั้ง AdMob SDK

อีกหนึ่งเรื่องที่มีคนสอบถามกันมามากเลยคือเรื่องของการติด Admob ของ Google เพื่อทำเงินผ่านแอพพลิเคชันของเราครับอันที่จริง Admob นั้นมีวิธีการบอกอย่างละเอียดนะครับว่า ทำตาม Step 1-2-3 ก็เสร็จแล้ว แค่เข้าไปเปิดอ่าน แต่พอมานั่งนึกดูโปรแกรมเมอร์จบใหม่คนไทย หรือเด็กนักศึกษาที่เริ่มเขียนโปรแกรมเป็นแล้วก็ยังสอบถามวิธีการติดเจ้า Admob นี่มาไม่ขาดสายครับ ก็เลยกลายเป็นว่าถ้าต้องการ Tutorial ภาษาไทยก็จะทำให้แล้วกัน

ก็มาเจาะจงที่ iOS ก่อนเลยนะครับ สำหรับ Android มีโครงการจะเริ่มพัฒนาครับ แต่ใช้เวลาเขียน Tutorial ชาติกว่าแน่ๆ เพราะมันช้าหน่วงเหลือหลายกับเครื่องของผม

เริ่มต้นสำหรับคนอยากทำเงินบน Admob
ก็เข้าไปที่ เว็บไซต์ http://www.admob.com ครับ เข้าระบบด้วย Google Account ไปเลยก็ได้ครับ

Screen Shot 2557-04-08 at 11.06.27 AM

ไปที่เมนู Site & Campaign ครับ เลือก Add Site ณ ที่นี้ผมเลือก iPhone App ก่อน ใส่ข้อมูลเค้าไป ถ้ายังไม่มี App Store URL ก็เว้นไว้ก่อนได้ค่อยมาใส่ทีหลัง ทำตาม Step ไปครับจนกว่าจะเสร็จไม่ยากหรอก อ่านสักนิด

Screen Shot 2557-04-08 at 11.11.22 AM

เข้า Sites & Apps

Screen Shot 2557-04-08 at 11.11.48 AM

เลือก iPhone App

Screen Shot 2557-04-08 at 11.12.09 AM

ได้ Publisher ID มาแล้ว

Screen Shot 2557-04-08 at 11.16.00 AM

ต่อมาเรามาทำการ Integrate เจ้า Admob ครับ ให้สร้าง Single View Application เปล่าๆ ขึ้นมาครับ

ไปที่ URL https://developers.google.com/mobile-ads-sdk/download#downloadios

Screen Shot 2557-04-08 at 11.27.20 AM

ตรวจสอบให้ดีว่าเป็น Tab ที่เขียนว่า “iOS” หรือเปล่า
ทำการดาวน์โหลด SDK ตัวล่าสุดของ Admob ครับ ทำการแตกไฟล์ออกมาซะ

กลับไปที่ Project ของเราอีกครั้ง คลิกขวาที่ Project เราเลือก Add Files to “…” ครับ

add_to_project_1

เลือกไฟล์จาก Folder Admob SDK เราตามรูปครับ จะ Copy items ก็ได้หรือไม่ก็ได้

add_to_project_2-1

ไปที่ Build Phase ครับ เลือก framework เข้าไปตามนี้

  • AdSupport
  • AudioToolbox
  • AVFoundation
  • CoreGraphics
  • CoreTelephony
  • MessageUI
  • StoreKit
  • SystemConfiguration

Screen Shot 2557-04-08 at 2.48.56 PM

ไปที่ Build Setting ของ Project ค้นหา Other Linker Flags ครับ ถ้าพบแล้วเพิ่ม -ObjC เข้าไป ตามรูป

linker-ios

เปิด ViewContoller.h ขึ้นมาครับ ทำการ Import GADBannerView.h เข้าไป

#import "GADBannerView.h"

@interface ViewController : UIViewController {
// Declare one as an instance variable
GADBannerView *bannerView_;
}
@end

ต่อมาก็กลับมาที่ ViewController.m ครับ เพิ่มคำสั่งนี้ใน viewDidLoad()

#import "ViewController.h"

@implementation BViewController

- (void)viewDidLoad {
[super viewDidLoad];

// Create a view of the standard size at the top of the screen.
// Available AdSize constants are explained in GADAdSize.h.
bannerView_ = [[GADBannerView alloc] initWithAdSize:kGADAdSizeBanner];

// Specify the ad unit ID.
bannerView_.adUnitID = MY_BANNER_UNIT_ID;

// Let the runtime know which UIViewController to restore after taking
// the user wherever the ad goes and add it to the view hierarchy.
bannerView_.rootViewController = self;
[self.view addSubview:bannerView_];

// Initiate a generic request to load it with an ad.
[bannerView_ loadRequest:[GADRequest request]];
}

@end

แทนค่า MY_BANNER_UNIT_ID ด้วย @“รหัส Publisher ID ” จาก Admob ลอง Run ดูถ้าไม่ผิดพลาดอะไรก็จะได้ตามตัวอย่างนี้ครับ

Screen Shot 2557-04-08 at 3.05.30 PM

เอาไปลองศึกษากันดูนะครับ https://developers.google.com/mobile-ads-sdk/docs/admob/fundamentals#ios

มันง่ายมากเลยครับ เห็นไหม

Comment หรือ ขอบคุณสักหน่อยก็ดีนะครับ 😀

Asst. Prof. Banyapon Poolsawas

อาจารย์ประจำสาขาวิชาการออกแบบเชิงโต้ตอบ และการพัฒนาเกม วิทยาลัยครีเอทีฟดีไซน์ & เอ็นเตอร์เทนเมนต์เทคโนโลยี มหาวิทยาลัยธุรกิจบัณฑิตย์ ผู้ก่อตั้ง บริษัท Daydev Co., Ltd, (เดย์เดฟ จำกัด)

Related Articles

Back to top button
Game & Mobile Development AR VR XR
Privacy Overview

This website uses cookies so that we can provide you with the best user experience possible. Cookie information is stored in your browser and performs functions such as recognising you when you return to our website and helping our team to understand which sections of the website you find most interesting and useful.

Adblock Detected

เราตรวจพบว่าคุณใช้ Adblock บนบราวเซอร์ของคุณ,กรุณาปิดระบบ Adblock ก่อนเข้าอ่าน Content ของเรานะครับ, ถือว่าช่วยเหลือกัน