-
-
Save melty710/8ead4413ed03d01373b6 to your computer and use it in GitHub Desktop.
iOS Tapjoy Rewarded Video
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Sample Rewarded Video callback code for managing rewards | |
- (void)rewardedVideoAdWillDisappearForAdUnitID:(NSString *)adUnitID { | |
// Best Practice: If using Tapjoy's managed currency service, we recommend calling getCurrencyBalance as often as possible | |
// so the user’s balance is always up-to-date. | |
[Tapjoy getCurrencyBalanceWithCompletion:^(NSDictionary *parameters, NSError *error) { | |
if (!error) { | |
// Update the currency balance in the UI | |
NSLog(@"getCurrencyBalance returned %@: %d", parameters[@"currencyName"], [parameters[@"amount"] intValue]); | |
} | |
}]; | |
} | |
- (void)rewardedVideoAdShouldRewardForAdUnitID:(NSString *)adUnitID reward:(MPRewardedVideoReward *)reward { | |
if (reward.amount != @(kMPRewardedVideoRewardCurrencyAmountUnspecified)) { | |
// If using Tapjoy's managed currency service, tell Tapjoy to award the user the reward amount specified by MoPub | |
// http://dev.tapjoy.com/virtual-currency/managed-currency/ | |
[Tapjoy awardCurrency:[reward.amount intValue]]; | |
// If using a different currency managing system, tell that system to award the user the reward amount specified by MoPub | |
// For Tapjoy rewards, you should have received a postback directly to your currency server using the callbackUrl specified on your Tapjoy currency | |
// http://dev.tapjoy.com/virtual-currency/non-managed-currency/ | |
} | |
} | |
////////// | |
// Sample AppDelegate code for setting up earned currency notifications when using Tapjoy-managed currency | |
- (void)applicationDidBecomeActive:(UIApplication *)application | |
{ | |
// If using Tapjoy managed currency, add an observer to be notified when a user has successfully earned currency. | |
// http://dev.tapjoy.com/virtual-currency/managed-currency/ | |
[[NSNotificationCenter defaultCenter] addObserver:self | |
selector:@selector(showEarnedCurrencyAlert:) | |
name:TJC_CURRENCY_EARNED_NOTIFICATION | |
object:nil]; | |
// Best Practice: If using Tapjoy's managed currency service, we recommend calling getCurrencyBalance as often as possible | |
// so the user’s balance is always up-to-date. | |
[Tapjoy getCurrencyBalanceWithCompletion:^(NSDictionary *parameters, NSError *error) { | |
if (!error) { | |
// Update the currency balance in the UI | |
NSLog(@"getCurrencyBalance returned %@: %d", parameters[@"currencyName"], [parameters[@"amount"] intValue]); | |
} | |
}]; | |
} | |
- (void)applicationWillResignActive:(UIApplication *)application | |
{ | |
// Remove this to prevent the possibility of multiple redundant notifications. | |
[[NSNotificationCenter defaultCenter] removeObserver:self name:TJC_CURRENCY_EARNED_NOTIFICATION object:nil]; | |
} | |
- (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]; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment