탭조이 오퍼월 관리형 재화를 사용하여 탭조이 서버에 사용자 재화 잔액을 저장하고 관리합니다.
읽는 시간 3분최근 업데이트: 3달 전
탭조이에서 관리하는 재화를 사용하여 사용자의 가상 재화 잔액을 탭조이 서버에 저장하고 관리할 수 있습니다. 탭조이의 퍼블리셔 SDK를 통합하는 모든 개발자가 이용할 수 있는 이 무료 서비스를 통해, 앱 내에서 재화를 백엔드에 저장할 필요가 없어집니다.
재화 잔액 가져오기
사용자의 현재 가상 재화 잔액을 확인하려면 각 플랫폼별로 안내된 메서드를 사용합니다. 잔액이 정확하게 유지되도록
getCurrencyBalance
를 자주 호출하는 것이 권장되는 베스트 프랙티스입니다. 잔액을 확인하는 일반적인 시점은 다음과 같은 상황입니다.
앱 실행
앱 재개
탭조이 뷰 종료
플레이스먼트 콘텐츠가 사라짐
최적의 결과를 위해 광고 콘텐츠가 종료된 후 약 3.5초 뒤에
getCurrencyBalance
를 호출합니다. 이렇게 하면 보상이 업데이트될 충분한 처리 시간이 확보됩니다. 즉시 잔액을 확인하면 새롭게 획득한 보상이 반영되지 않을 수 있습니다.
재화 잔액 검색
탭조이는 보상을 신속하게 전달하기 위해 최선을 다합니다. 하지만 네트워크 지연이 발생할 수 있으므로 즉시 보상이 보장되지는 않습니다. 사용자들에게 오퍼 보상이 반영되기까지 다소 시간이 걸릴 수 있음을 알려줍니다. 정확성을 유지하려면 정기적으로 잔액을 확인하고, 다음과 같은 주요 앱 이벤트가 발생할 때 확인하십시오.
앱 실행
앱 재개
레벨 사이
스토어 로딩 전
재화 잔액을 조회하려면 다음 플랫폼별 메서드를 참고하십시오.
iOS 디바이스에서 현재 가상 재화 잔액을 확인하려면 다음 메서드를 사용합니다.
// This method requests the tapjoy server for current virtual currency of the user.//Get currency[Tapjoy getCurrencyBalanceWithCompletion:^(NSDictionary *parameters, NSError *error) { if (error) { //Show error message NSLog(@"getCurrencyBalance error: %@", [error localizedDescription]); } else { //Update currency value of your app NSLog(@"getCurrencyBalance returned %@: %d", parameters[@"currencyName"], [parameters[@"amount"] intValue]); }}];
완료 블록은
currencyName
에 재화 이름,
amount
에 사용자의 총 잔액을 반환합니다. 구현 세부 사항은 SDK 패키지의 샘플 애플리케이션을 참고하십시오.
Android 디바이스에서 현재 가상 재화 잔액을 확인하려면 다음 메서드를 사용합니다.
Tapjoy.getCurrencyBalance(new TJGetCurrencyBalanceListener(){ @Override public void onGetCurrencyBalanceResponse(String currencyName, int balance) { Log.i(TAG, "getCurrencyBalance returned " + currencyName + ":" + balance); } @Override public void onGetCurrencyBalanceResponseFailure(String error) { Log.i("Tapjoy", "getCurrencyBalance error: " + error); } });
onGetCurrencyBalanceResponse
콜백에서 결과값을 받고
onGetCurrencyBalanceResponseFailure
에서 오류 정보를 받습니다. 앱 시작과 재개 시
getCurrencyBalance
를 호출하여 정확도를 유지합니다. spend와 award 콜백도 전체 잔액을 반환하며, 앱 업데이트에 활용할 수 있습니다.
마지막 잔액 확인 이후 재화를 획득하면 사용자에게 알림을 제공합니다. 알림을 설정하려면 다음 섹션의 플랫폼별 명령어를 사용합니다.
iOS 디바이스에서 획득한 재화를 감지하려면 알림 관찰자를 추가합니다.
// Set the notification observer for earned-currency-notification. It's recommended that this be placed within the applicationDidBecomeActive method.[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(showEarnedCurrencyAlert:) name:TJC_CURRENCY_EARNED_NOTIFICATION object:nil];// In the following method, you can set a custom message or use the default UIAlert to inform the user that they just earned some currency.- (void)showEarnedCurrencyAlert:(NSNotification*)notifyObj{ NSNumber *currencyEarned = notifyObj.object; int earnedNum = [currencyEarned intValue]; NSLog(@"Currency earned: %d", earnedNum); // Pops up a UIAlert notifying the user that they have successfully earned some currency. // This is the default alert, so you may place a custom alert here if you choose to do so. [Tapjoy showDefaultEarnedCurrencyAlert]; // This is a good place to remove this notification since it is undesirable to have a pop-up alert more than once per app run. [[NSNotificationCenter defaultCenter] removeObserver:self name:TJC_CURRENCY_EARNED_NOTIFICATION object:nil];}
사용자가 가상 재화를 획득할 때마다(예: 오퍼를 통해) 알림을 받으려면 다음 방법으로 획득한 재화 리스너를 설정합니다.
// Get notifications whenever Tapjoy currency is earned. Tapjoy.setEarnedCurrencyListener(new TJEarnedCurrencyListener() { @Override public void onEarnedCurrency(String currencyName, int amount) { Log.i("Tapjoy", "You've just earned " + amount + " " + currencyName); } });
TapjoyAIR.addEventListener(TJEarnedCurrencyEvent.EARNED_CURRENCY, tapjoyEarnedCurrencyEventHandler); private function tapjoyEarnedCurrencyEventHandler(event:TJEarnedCurrencyEvent):void { trace("You can notify user's here that they've just earned " + event.amount + " " + event.currencyName); }
지정한
earned in the TJEarnedCurrencyEvent.EARNED_CURRENCY
핸들러에서 재화 관련 알림을 받게 되며
TJEarnedCurrencyEvent object
가 전달됩니다. 이 오브젝트에는
currencyName
및
amount
등록 정보가 포함되어 있습니다.
탭조이 관리형 재화 지출
사용자의 가상 재화를 일정 금액 사용하려면 다음 섹션에 자세히 안내된 플랫폼별 메서드를 호출합니다.
// This method call will deduct 10 virtual currencies from the user's total.[Tapjoy spendCurrency:10 completion:^(NSDictionary *parameters, NSError *error) { if (error) { NSLog(@"spendCurrency error: %@", [error localizedDescription]); } else { NSLog(@"spendCurrency returned %@: %d", parameters[@"currencyName"], [parameters[@"amount"] intValue]); }}];
완료 블록에서 재화 잔액에 대한 알림을 받게 되며, 파라미터
currencyName
는 재화 이름을 제공하고,
amount
는 사용자의 잔액을 제공합니다.
Tapjoy.spendCurrency(10, new TJSpendCurrencyListener() { @Override public void onSpendCurrencyResponse(String currencyName, int balance) { Log.i("Tapjoy", currencyName + ": " + balance); } @Override public void onSpendCurrencyResponseFailure(String error) { Log.i("Tapjoy", "spendCurrency error: " + error); } });
지정한
TJSpendCurrencyListener
의
onSpendCurrencyResponse(String currencyName, int balance)