RewardedAd.isReady()
Check if the BZZE Ads SDK has been initialized and is ready to use.
Syntax
JavaScript
RewardedAd.isReady()
Description
The isReady() method checks if RewardedAd.init() has been called successfully and the SDK is ready to load and display ads.
📝 Note:
isReady() checks SDK initialization status, while isAdAvailable() checks if ads are preloaded and ready to show. Both are different checks for different purposes.
Parameters
None
Return Value
Type: boolean
true- SDK is initialized and readyfalse- SDK has not been initialized yet
Examples
Basic Initialization Check
JavaScript
// Check if SDK is ready before using it
if (RewardedAd.isReady()) {
console.log('✅ SDK is initialized and ready');
// Safe to call other SDK methods
RewardedAd.showAd();
} else {
console.log('⚠️ SDK not initialized yet');
// Initialize the SDK first
RewardedAd.init({ /* config */ });
}
Delayed Game Initialization
JavaScript
// Initialize SDK asynchronously
RewardedAd.init({
appId: "YOUR_APP_ID",
apiKey: "YOUR_API_KEY",
userId: "user_123"
});
// Wait for SDK to be ready before starting game
function startGame() {
if (RewardedAd.isReady()) {
console.log('SDK ready, starting game...');
loadGameAssets();
} else {
console.log('Waiting for SDK...');
setTimeout(startGame, 100); // Check again in 100ms
}
}
startGame();
Safe API Wrapper
JavaScript
// Create a safe wrapper for SDK methods
function safeShowAd(options) {
if (!RewardedAd.isReady()) {
console.error('❌ SDK not initialized. Call RewardedAd.init() first.');
return false;
}
if (!RewardedAd.isAdAvailable()) {
console.warn('⚠️ No ads available right now.');
return false;
}
// Everything is ready, show the ad
RewardedAd.showAd(options);
return true;
}
// Usage
safeShowAd({ rewardPreview: '100 coins' });
React Component with Ready Check
JavaScript
import { useState, useEffect } from 'react';
function AdButton() {
const [sdkReady, setSdkReady] = useState(false);
useEffect(() => {
// Check if SDK is ready
const checkReady = () => {
if (RewardedAd.isReady()) {
setSdkReady(true);
} else {
// Check again in 500ms
setTimeout(checkReady, 500);
}
};
checkReady();
}, []);
if (!sdkReady) {
return ⏳ Initializing ads...;
}
return (
);
}
Debug Helper
JavaScript
// Debug function to check SDK status
function debugSDKStatus() {
console.log('=== BZZE Ads SDK Status ===');
console.log('SDK Ready:', RewardedAd.isReady());
if (RewardedAd.isReady()) {
console.log('Ad Available:', RewardedAd.isAdAvailable());
console.log('Preloaded Ads:', RewardedAd.getPreloadedAdCount());
console.log('Cooldown:', RewardedAd.getCooldownRemaining());
console.log('SDK Info:', RewardedAd.getInfo());
} else {
console.log('⚠️ SDK not initialized yet!');
}
console.log('========================');
}
// Call this during development
debugSDKStatus();
Common Use Cases
1. Preventing Premature API Calls
Always check if SDK is ready before calling any other methods:
JavaScript
if (RewardedAd.isReady()) {
const analytics = RewardedAd.getAnalytics();
console.log('Session stats:', analytics);
}
2. Dynamic Feature Unlocking
Enable ad-based features only after SDK is ready:
JavaScript
function unlockAdFeatures() {
if (RewardedAd.isReady()) {
document.getElementById('adRewardButton').style.display = 'block';
document.getElementById('watchAdOption').disabled = false;
}
}
// Check every second until ready
const checkInterval = setInterval(() => {
if (RewardedAd.isReady()) {
unlockAdFeatures();
clearInterval(checkInterval);
}
}, 1000);
Comparison: isReady() vs isAdAvailable()
| Method | Purpose | When it returns true |
|---|---|---|
isReady() |
Check if SDK is initialized | After init() is called successfully |
isAdAvailable() |
Check if ads are preloaded | When at least 1 ad is preloaded and ready |
Best Practices
✅ DO:
- Check
isReady()before calling any SDK methods - Use it to conditionally show UI elements
- Implement retry logic with timeouts
- Log warnings if SDK isn't ready
⚠️ DON'T:
- Call SDK methods without checking readiness first
- Assume the SDK is always ready immediately
- Confuse with
isAdAvailable() - Block your app's startup waiting for SDK
Related Methods
- init() - Initialize the SDK
- isAdAvailable() - Check if ads are ready
- getInfo() - Get SDK information