Tapjoyオファーウォール広告実装方法 - glossom-dev/AdfurikunSDK-iOS GitHub Wiki
アドフリくん管理画面で広告枠の追加をする際に、バナー種類「オファーウォール」を選択します。
追加した広告枠の設定画面に入り、「オファーウォール利用申請」を選択する事でTapjoyオファーウォールの広告枠が発行されます。
Tapjoy SDKの導入、オファーウォール広告表示の実装を行います。詳細は、Tapjoyのドキュメントを参考にして下さい。
また、サーバ間の成果通知の実装については、こちらを参考にして下さい。
※ 本ドキュメントの動作確認TapjoySDKバージョン: 13.4.1
Tapjoy を利用する場合には、Podfile に下記のように付け加えます
pod 'TapjoySDK'
「File > Add Packages Dependancies」を開きます。 上部右の検索バーに以下レポジトリ をペーストし、「Add Package」を選択します。
https://github.com/Tapjoy/swift-packages.git
Tapjoy connect をアプリに実装します。 これにより、アプリからTapjoy SDK を"起動"します。 Tapjoy SDK Keyはアドフリくん管理画面で発行された「sdk_key」を使用して下さい。 Tapjoy connect関数の呼び出しは、アプリケーションのデリゲートファイルの application:didFinishLaunchingWithOptions メソッドで呼び出して下さい。
実装例
Swift
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
NotificationCenter.default.addObserver(self, selector: #selector(AppDelegate.tjcConnectSuccess(notif:)), name: NSNotification.Name(rawValue: TJC_CONNECT_SUCCESS), object: nil)
NotificationCenter.default.addObserver(self, selector: #selector(AppDelegate.tjcConnectFail(notif:)), name: NSNotification.Name(rawValue: TJC_CONNECT_FAILED), object: nil)
NotificationCenter.default.addObserver(self, selector: #selector(AppDelegate.tjcConnectWarning(notif:)), name: NSNotification.Name(rawValue: TJC_CONNECT_WARNING), object: nil)
// Tapjoy デバッグモードを ON に
Tapjoy.setDebugEnabled(true) //開発用途にのみ有効にします。 パブリッシュする前に必ず無効にして下さい。
Tapjoy.connect("Tapjoy SDK Key")
return true
}
@objc func tjcConnectSuccess(notif: NSNotification) {
NSLog("Tapjoy connect succeeded")
}
@objc func tjcConnectFail(notif: NSNotification) {
if let error = notif.userInfo?[TJC_CONNECT_USER_INFO_ERROR] as? NSError {
let code = error.code
let message = error.localizedDescription
if let underlyingError = error.userInfo[NSUnderlyingErrorKey] as? NSError {
let underlyingErrorMessage = "\nUnderlying Error: \(underlyingError.code) - \(underlyingError.localizedDescription)"
NSLog(underlyingErrorMessage);
}
}
}
@objc func tjcConnectWarning(notif: NSNotification) {
var message = "Tapjoy Connect Warning"
if let error = notif.userInfo?[TJC_CONNECT_USER_INFO_ERROR] as? NSError {
message.append("\nError: \(error.code) - \(error.localizedDescription)")
if let underlyingError = error.userInfo[NSUnderlyingErrorKey] as? NSError {
message.append("\nUnderlying Error: \(underlyingError.code) - \(underlyingError.localizedDescription)")
}
}
}
Objective-C
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(tjcConnectSuccess:) name:TJC_CONNECT_SUCCESS object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(tjcConnectFail:) name:TJC_CONNECT_FAILED object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(tjcConnectWarning:) name:TJC_CONNECT_WARNING object:nil];
// Tapjoy デバッグモードを ON に
[Tapjoy setDebugEnabled:YES]; // 開発用途にのみ有効にします。 パブリッシュする前に必ず無効にして下さい。
[Tapjoy connect:@"Tapjoy SDK Key"];
return YES;
}
- (void)tjcConnectSuccess:(NSNotification *)notifyObj
{
NSLog(@"Tapjoy connect succeeded");
}
- (void)tjcConnectFail:(NSNotification *)notifyObj
{
NSError *error = notifyObj.userInfo[TJC_CONNECT_USER_INFO_ERROR];
NSInteger code = error.code;
NSString *message = error.localizedDescription;
NSString *underlyingErrorMessage = underlyingError != nil ? [NSString stringWithFormat:@" - %li %@", underlyingError.code, underlyingError.localizedDescription] : @"";
NSLog(@"%@", underlyingErrorMessage);
}
- (void)tjcConnectWarning:(NSNotification *)notifyObj
{
NSError *error = notifyObj.userInfo[TJC_CONNECT_USER_INFO_ERROR];
NSError *underlyingError = error.userInfo[NSUnderlyingErrorKey];
}
コンパイルを行い、アプリを実行して下さい。 実装が正しい場合は下記のようなログが出力されます。
2020-01-29 16:01:55.422 Storyteller Roller[25869:1433019] [TJLog level: 4] Connect success with type:0
ファイル先頭で TJPlacement.h をインポートします。
Swift
// ブリッジング ヘッダーによりインポートは自動的に行われています。
Objective-C
#import <Tapjoy/TJPlacement.h>
TJPlacementクラスにプレイスメント名を指定して初期化してインスタンスを作成します。 プレイスメント名はアドフリくん管理画面で発行された「placement_id」を使用して下さい。 また、デリゲートを実装してコールバックを受け取れます(以下で説明します)。
Swift
let p = TJPlacement(name: "プレイスメント名", delegate: self)
p?.requestContent()
Objective-C
TJPlacement *p = [TJPlacement placementWithName:@"プレイスメント名" delegate:self];
[p requestContent];
※ コンテンツをリクエストする前に、Tpajoy connectコールが成功しているようにして下さい。 TJC_CONNECT_SUCCESS通知を受ける前にコンテンツをリクエストしないようにして下さい。
コンテンツリクエストのステータスのフィードバックを得るには、下記の TJPlacementDelegate のメソッドを実装します。
Swift
func requestDidSucceed(_ placement: TJPlacement!) {} // プレイスメント送信自体が成功した時にコールされます。表示する広告有無ではありません。
func requestDidFail(_ placement: TJPlacement!, error: Error!) {}
func contentIsReady(_ placement: TJPlacement!) {} //コンテンツが表示可能になって時にコールされます。
func contentDidAppear(_ placement: TJPlacement!) {}
func contentDidDisappear(_ placement: TJPlacement!) {}
Objective-C
- (void)requestDidSucceed:(TJPlacement*)placement{} // プレイスメント送信自体が成功した時にコールされます。表示する広告の有無ではありません。
- (void)requestDidFail:(TJPlacement*)placement error:(NSError*)error{}
- (void)contentIsReady:(TJPlacement*)placement{} //コンテンツが表示可能になって時にコールされます。
- (void)contentDidAppear:(TJPlacement*)placement{}
- (void)contentDidDisappear:(TJPlacement*)placement{}
コンテンツを表示するには、show メソッドを呼び出します。
Swift
if (p.isContentReady) {
p.showContent(with: nil)
} else {
//handle situation where there is no content to show, or it has not yet downloaded.
}
Objective-C
if (p.isContentReady) {
[p showContentWithViewController: nil];
}
else {
//handle situation where there is no content to show, or it has not yet downloaded.
}