Error Handling
When BlueStackSDK encounters an error it fires the failed callback delegate with a BlueStackError
class object.
Error codes
BlueStack SDK reports with following error codes:
Error Code | Constant | Description |
---|---|---|
0 | BlueStackErrorWrongPlacement | This error code represents an error that happened due to loading an ad with wrong placement Id |
-1000 | BlueStackErrorAdServer | An ad server error occurred while loading the ad |
-1001 | BlueStackErrorDataAdServer | The ad response contains wrong data |
-999 | BlueStackErrorSDKUninitialized | This error happens if you try to load an ad before the sdk finishes it's initialization |
-998 | BlueStackErrorCappedRequest | Ad request has been capped |
-997 | BlueStackErrorLockedPlacement | Placement has been locked or already in process by another resource |
-996 | BlueStackErrorBusyFactory | This error will occur if you try to load multiple ads concurrently using same placement Id |
-995 | BlueStackErrorBusy | If the SDK is busy loading one or more ads |
-994 | BlueStackErrorUnallowedBackgroundRequest | When SDK fails to send request while application is on background |
-993 | BlueStackErrorNoAds | This error occurs when there is no ad fill serving the placement Id |
-992 | MAdvertiseErrorInterstitialCooldown | If the time between last interstitial disappear and create Interstitial less than 5s |
-991 | BlueStackErrorAlreadyShownInterstitial | If you try to show an Interstitial ad while there is another Interstitial ad already showing |
-990 | BlueStackErrorRequestTimedOut | Ad fails to load due to the request timed out |
-989 | BlueStackErrorMissingViewController | This will happen if you do not provide root view controller while showing full screen ads and sdk is not able to found the top-most view controller |
-988 | BlueStackErrorUnableToDisplayAd | This error happens when you try to show a full screen ad before it is done loading |
Handling the Error
Following is an example of handling errors for an Banner Ad.
- Objective C
- Swift
- (void)bannerView:(BannerView * _Nonnull)bannerView didFailedToLoadWithError:(NSError * _Nonnull)error {
switch (error.code) {
case BlueStackErrorWrongPlacement:
NSLog(@"Wrong placement Id. %@", error.localizedDescription);
break;
case BlueStackErrorSDKUninitialized:
NSLog(@"BlueStackSDK is not initialized. %@", error.localizedDescription);
break;
default:
NSLog(@"Unhandled error");
break;
}
}
func onFailedToLoad(_ bannerView: BlueStackSDK.BannerView, _ error: any Error) {
guard let error = error as? BlueStackError, let errorCode = BlueStackErrorCode(rawValue: error.code) else { return }
switch errorCode {
case .BlueStackErrorWrongPlacement:
print("Wrong placement Id. \(error.localizedDescription)")
break
case .BlueStackErrorSDKUninitialized:
print("BlueStackSDK is not initialized. \(error.localizedDescription)")
break
default:
print("Unhandled error. \(error.localizedDescription)")
break
}
}