Hướng dẫn tích hợp quảng cáo Startapp vào ứng dụng IOS.

abtranbn
26/3/2015 11:1Phản hồi: 7
Hướng dẫn tích hợp quảng cáo Startapp vào ứng dụng IOS.
Đây là bài viết để anh em add quảng cáo StartApp vô ứng dụng IOS nhằm tăng gia sản xuát thêm cho các anh em. Theo cảm nhận của mình StartApp vừa đơn giản quảng cáo đẹp mà năng suất lại cao.
1, Đầu tiên anh em vô https://portal.startapp.com/signup để đăng ký.



Sau khi đăng ký thì anh em đăng nhập vô.


2, Anh em vô My Applications Click vô mục Add New App





điền thông tin link app (nếu có), tiếp đến tên app. Chọn Platform là iOS, điền thông tin app, maturity cuối cùng là nhấn vô button add app.
Sau đó anh em sẽ có app id đồng thời anh em download SDK của startapp. (Anh em lựa chọn sdk cho app của mình là in app hay unity, cocos2d hay cocos2dx tuỳ theo app anh em.) Ở đây mình chọn in app.


Có 1 project ví dụ của startapp đã add cho anh em tham khảo.
https://github.com/StartApp-SDK/StartApp-InApp-iOS-Example-App/archive/master.zip

sau khi download sdk về thì giải nén ra ta đưa vô project
Startapp có mấy kiểu quảng cáo: Splash Ads là kiểu quảng cáo khi mở ứng dụng, cái này có ecpm cao nhất.


Quảng cáo



Đối với các bạn code Objective C có document đây thì để add:
1. các bạn mở project cần add bằng xcode lên và chuột phải project chọn Add Files to "tên project của bạn" (hoặc kéo thư mục sdk vừa download về vô trực tiếp project của bạn.)



2. Chọn file StartApp.framework vs StartApp.bundle



3. Vô project->application target -> Build Phases-> "Link Binary with Libraries" chọn thêm các framwork:
CoreTelephony.framework

Quảng cáo


SystemConfiguration.framework
CoreGraphics.framework
StoreKit.framework
AdSupport.framework
QuartzCore.framework
libz.dylib





Tiếp đến các bạn cần thêm vô file AppDelegate.m
trong

- (BOOL)application😔UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
Code:
#import <StartApp/StartApp.h>

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    // initialize the SDK with your appID and devID
    STAStartAppSDK* sdk = [STAStartAppSDK sharedInstance];
    sdk.devID = @"your developer id";
    sdk.appID = @"your app Id";

    return YES;
}
các bạn cần thay thế id vs app id mà các bạn được cung cấp khi các bạn đăng ký ở trên nhé."your developer id",your app Id".

Để hiển thị quảng cáo Splash Ads lúc đầu thì các bạn add tiếp
[sdk showSplashAd];
vô trên được như sau:

Code:
#import <StartApp/StartApp.h>

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    // initialize the SDK with your appID and devID
    STAStartAppSDK* sdk = [STAStartAppSDK sharedInstance];
    sdk.appID = @"your app Id";
    sdk.devID = @"your developer id";

    [sdk showSplashAd];  // display the splash screen

    return YES;
}
Để hiển thị quảng cáo Interstitial Ads các bạn mở file
ViewController.h của các bẩn và thêm vô
#import <StartApp/StartApp.h>
STAStartAppAd* startAppAd;
được như sau:
Code:
#import <StartApp/StartApp.h>

@interface YourViewController : UIViewController
{
    STAStartAppAd* startAppAd;    // ADD THIS LINE
} 
tiếp trong viewdidload các bạn thêm:
[super viewDidLoad];
startAppAd = [[STAStartAppAd alloc] init];
và trong viewDidAppear thêm:
[startAppAd loadAd];
còn trong dealloc(nếu có) thêm:
[startAppAd release];
ta được như sau:
Code:
- (void)viewDidLoad {
    [super viewDidLoad];
    startAppAd = [[STAStartAppAd alloc] init];
}

- (void) viewDidAppear:(BOOL)animated {
    [super viewDidAppear:animated];
    [startAppAd loadAd];  // Add this line
}

- (void) dealloc {
    // Don't release startAppAd if you are using ARC in your project
    [startAppAd release];  // Add this line
    [super dealloc];
} 
Các bạn cần hiển thị quảng cáo ở đâu thì chỉ cần thêm:
[startAppAd showAd];

Hiển thị quảng cáo banners (Loại này ít tác dụng)



Trong file ViewController.h của các bạn cần thêm như sau:

Code:
#import <UIKit/UIKit.h>
#import <StartApp/StartApp.h>

@interface YourViewController : UIViewController
{
    STABannerView* bannerView;
}
Tiếp đến trong file ViewController.m của các bạn cần thêm vô trong viewDidAppear,dealloc (nếu có)
if (bannerView == nil) {
bannerView = [[STABannerView alloc] initWithSize:STA_AutoAdSize autoOrigin:STAAdOrigin_Top
withView:self.view withDelegate:nil];
[self.view addSubview:bannerView];
}


[bannerView release];

ta được như sau:

Code:
- (void) viewDidAppear:(BOOL)animated {
    [super viewDidAppear:animated];
     if (bannerView == nil) {
        bannerView = [[STABannerView alloc] initWithSize:STA_AutoAdSize autoOrigin:STAAdOrigin_Top   
                                            withView:self.view withDelegate:nil];
        [self.view addSubview:bannerView];
    }
}

- (void) dealloc
{
    // Don't release bannerView if you are using ARC in your project
    [bannerView release];  // Add this line
    [super dealloc];
}
thêm hàm sau vô trong ViewController của các bạn
Code:
- (void) didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation {
    [bannerView didRotateFromInterfaceOrientation:fromInterfaceOrientation];
    [super didRotateFromInterfaceOrientation:fromInterfaceOrientation];  
}

- (void)viewWillTransitionToSize:(CGSize)size withTransitionCoordinator:(id<UIViewControllerTransitionCoordinator>)coordinator {
[bannerView viewWillTransitionToSize:size withTransitionCoordinator:coordinator];
[super viewWillTransitionToSize:size withTransitionCoordinator:coordinator];
}
Đối với các bạn code Swift có document đây thì để quảng cáo vô cũng tương tự như sau:

1. các bạn mở project cần add bằng xcode lên và chuột phải project chọn Add Files to "tên project của bạn" (hoặc kéo thư mục sdk vừa download về vô trực tiếp project của bạn.)



2.Chọn file StartApp.framework vs StartApp.bundle
3. Vô project->application target -> Build Phases-> "Link Binary with Libraries" chọn thêm các framwork:
CoreTelephony.framework
SystemConfiguration.framework
CoreGraphics.framework
StoreKit.framework
AdSupport.framework
QuartzCore.framework
libz.dylib




trong mục "Copy Bundle Resources" các bạn add StartApp.bundle nếu chưa tồn tại.


tiếp đến add file Bridging-Header như sau để dùng được code Objective C:
chuột phải project chọn add new file



chọn iOS->Source->Header File->Next


tên file -Bridging-Header.h”


kiểm tra xem trong "Build Settings" đúng link dẫn file Bridging-Header.h


thêm
#import <StartApp/StartApp.h> vô file Bridging Header.
Bắt tay vào công đoạn chính là add code: vô file AppDelegate.swift được như sau:
Code:
func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: NSDictionary?) -> Bool {
        // initialize the SDK with your appID and devID
        var sdk: STAStartAppSDK = STAStartAppSDK.sharedInstance()
        sdk.appID = "Your App Id"
        sdk.devID = "Your Developer Id"

        return true
    }
các bạn nhớ thay thế id vs app id của các bạn vô "Your App Id" vs "Your Developer Id" nhé.
Để hiển thị quảng cáo Splash Ads lúc đầu thì các bạn add tiếp vô AppDelegate.swift
được như sau:

Code:
func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: NSDictionary?) -> Bool {
        // initialize the SDK with your appID and devID
        var sdk: STAStartAppSDK = STAStartAppSDK.sharedInstance()
        sdk.appID = "Your App Id"
        sdk.devID = "Your Developer Id"

        sdk.showSplashAd()

        return true
    }
Để hiển thị quảng cáo Interstitial Ads các bạn mở file
ViewController.swift của các bẩn và thêm vô được như sau:
Code:
var startAppAd: STAStartAppAd?

override func viewDidLoad() {
        super.viewDidLoad()

        startAppAd = STAStartAppAd()
    }

override func viewDidAppear(animated: Bool) {
        super.viewDidAppear(animated)
        startAppAd!.loadAd()
    }
và các bạn muốn hiển thị quảng cáo ở đâu thì thêm startAppAd!.showAd() vô đó.

Hiển thị quảng cáo banners (Loại này ít tác dụng)
Trong file ViewController.swift của các bạn cần thêm như sau:
Code:
var startAppBanner: STABannerView?
tiếp tục:
Code:
override func viewDidAppear(animated: Bool) {
        super.viewDidAppear(animated)
        if !startAppBanner {
            startAppBanner = STABannerView(size: STA_AutoAdSize, autoOrigin: STAAdOrigin_Bottom, withView: self.view, withDelegate: nil);
            self.view.addSubview(startAppBanner)
        }
    }

override func didRotateFromInterfaceOrientation(fromInterfaceOrientation: UIInterfaceOrientation) {
// notify StartApp auto Banner orientation change
startAppBanner!.didRotateFromInterfaceOrientation(fromInterfaceOrientation)
super.didRotateFromInterfaceOrientation(fromInterfaceOrientation)
}

override func viewWillTransitionToSize(size: CGSize, withTransitionCoordinator coordinator: UIViewControllerTransitionCoordinator) {
// notify StartApp auto Banner orientation change
startAppBannerAuto!.viewWillTransitionToSize(size, withTransitionCoordinator: coordinator)
startAppBannerFixed!.viewWillTransitionToSize(size, withTransitionCoordinator: coordinator)

super.viewWillTransitionToSize(size, withTransitionCoordinator: coordinator)
}

Lưu ý khi các bạn đưa app lên Appstore thì mục quảng cáo apple hỏi các bạn chọn như hình dưới nhé (ko là tạch đó).



goodcode!
các bạn có thắc mắc gì cứ hỏi nhé.
7 bình luận
Chia sẻ

Xu hướng

Bai viet rat hay? cho minh hoi minh lam startapp duoc 1 tuan thi bi khoa account, khong biet nguyen nhan tai sao? co ban nao biet ve van de nay va chia se kinh nghiem cho minh duoc ko?
vnnplus
ĐẠI BÀNG
9 năm
Có bác nào có nhiều app về ios cho em chạy quảng cáo con game bigkool với ạ
Link tải game trên appstore : https://itunes.apple.com/vn/app/id868617615
bài viết hay..mình đã đki và reference theo link c c..😃
add ơi cho mình hỏi làm cái này phải cài itunes nửa hả add . và cái này kiếm tiền ntn hả add
depmakdep
ĐẠI BÀNG
9 năm
một bài viết rất hay, tks bác nhé
em lam may bua nó khoá tai khoan nen chia tay luon chuyen qua chartboost
mình làm mấy bửa no khoá chán chuyển qua chartboost

Xu hướng

Bài mới









  • Chịu trách nhiệm nội dung: Trần Mạnh Hiệp
  • © 2024 Công ty Cổ phần MXH Tinh Tế
  • Địa chỉ: Số 70 Bà Huyện Thanh Quan, P. Võ Thị Sáu, Quận 3, TPHCM
  • Số điện thoại: 02822460095
  • MST: 0313255119
  • Giấy phép thiết lập MXH số 11/GP-BTTTT, Ký ngày: 08/01/2019