YSO Network SDK Help

iOS SDK usage

Initialize

The YsoNetwork.initialize method is used to initialize the YsoNetwork SDK.

Prototype

+ (BOOL) isInitialized; + (void) initializeWithViewController:(UIViewController *_Nonnull) viewController;

Code Example

if ([YsoNetwork isInitialized] == NO) { @try { [YsoNetwork initializeWithViewController:topViewController]; /* mediation logic on sdk initialize success */ } @catch (NSException *exception) { /* mediation logic on sdk initialize fail */ } [YNLog prodInfo: [NSString stringWithFormat:@"YSO Network Adapter SDK %@", ADAPTER_VERSION]]; } else { /* mediation logic on sdk already initialized */ }

Collect Signal

The YsoNetwork.getSignal method is used to collect a signal from the YsoNetwork SDK, typically used for filling the bid request.

Prototype

+ (NSString *_Nonnull) getSignal;

Code Example

[YsoNetwork getSignal];

Usage

Call YsoNetwork.getSignal to retrieve the signal string used to fill the bid request.

Get SDK Version

The YsoNetwork.getSdkVersion method is used to retrieve the version of the YsoNetwork SDK.

Prototype

+ (NSString *_Nonnull) getSdkVersion;

Code Example

[YsoNetwork getSdkVersion];

Usage

Call YsoNetwork.getSdkVersion to get the current SDK version string for logging or display purposes, as well as filling the bid request.

Load Interstitial

The YsoNetwork.interstitialLoad method is used to load an interstitial ad.

Prototype

+ (void) interstitialLoadWithKey:(NSString *_Nonnull)key json:(NSString *_Nonnull)json onLoad:(nonnull void (^)(e_ActionError error))onLoad;

Code Example

[YsoNetwork interstitialLoadWithKey:key json:adResponse onLoad:^(e_ActionError error) { if (error == e_ActionErrorNone) { /* mediation load success logic */ } else { /* mediation load error logic */ } }];

Usage

Call YsoNetwork.interstitialLoad to initiate loading an interstitial ad with the specified key and adResponse. Implement the success and error handling logic within the callback function.

Parameters

  • key: The identifier for the interstitial ad placement created on the YSO Network dashboard.

  • adResponse: The ad response from the bidding process, for example bidResponse.seatbid[0].bid[0].ext.signaldata.

  • onLoad: The error parameter passed to the callback function to indicate success or the type of error that occurred.

Show Interstitial

The YsoNetwork.interstitialShow method is used to display an interstitial ad.

Prototype

+ (void) interstitialShowWithKey:(NSString *_Nonnull)key viewController:(UIViewController *_Nonnull)viewController onDisplay:(nonnull void (^)(YNWebView *_Nullable view))onDisplay onClick:(nonnull void (^)(void))onClick onClose:(nonnull void (^)(bool, bool))onClose;

Code Example

[YsoNetwork interstitialShowWithKey:key viewController:viewController onDisplay:^(YNWebView *view){ /* mediation logic on ad display */ } onClick:^{ /* mediation logic on ad click */ } onClose:^(bool display, bool complete) { if (display == YES) { /* mediation logic on ad successfully closed */ } else { /* mediation logic on ad display error */ } }]

Usage

Call YsoNetwork.interstitialShow to display an interstitial ad with the specified key. Implement the YNManager.ActionDisplay interface to define logic for handling ad display, click, and close events.

Parameters

  • key: The identifier for the interstitial ad placement created on the YSO Network dashboard.

  • viewController: The view controller the ad should render in.

  • onDisplay(YNWebView view): Called when the ad is displayed.

  • onClick(): Called when the ad is clicked.

  • onClose(boolean display, boolean complete): Called when the ad is closed, with parameters indicating if the ad was displayed and if the ad view was fully completed.

Load Rewarded

The YsoNetwork.rewardedLoad method is used to load a rewarded ad.

Prototype

+ (void) rewardedLoadWithKey:(NSString *_Nonnull)key json:(NSString *_Nonnull)json onLoad:(nonnull void (^)(e_ActionError error))onLoad;

Code Example

[YsoNetwork rewardedLoadWithKey:key json:adResponse onLoad:^(e_ActionError error) { if (error == e_ActionErrorNone) { /* mediation load success logic */ } else { /* mediation load error logic */ } }];

Usage

Call YsoNetwork.rewardedLoad to initiate loading a rewarded ad with the specified placementId and adResponse. Implement the success and error handling logic within the callback function.

Parameters

  • key: The identifier for the rewarded ad placement created on the YSO Network dashboard.

  • adResponse: The ad response from the bidding process, for example bidResponse.seatbid[0].bid[0].ext.signaldata.

  • onLoad: The error parameter passed to the callback function to indicate success or the type of error that occurred.

Show Rewarded

The YsoNetwork.rewardedShow method is used to display a rewarded ad.

Prototype

+ (void) rewardedShowWithKey:(NSString *_Nonnull)key viewController:(UIViewController *_Nonnull)viewController onDisplay:(nonnull void (^)(YNWebView *_Nullable view))onDisplay onClick:(nonnull void (^)(void))onClick onClose:(nonnull void (^)(bool, bool))onClose;

Code Example

[YsoNetwork rewardedShowWithKey:placementId viewController:viewController onDisplay:^(YNWebView *view){ /* mediation logic on ad display */ } onClick:^{ /* mediation logic on ad click */ } onClose:^(bool display, bool complete) { if (display == YES) { if (complete == YES) { /* mediation logic to reward the user */ } /* mediation logic on ad successfully closed */ } else { /* mediation logic on ad display error */ } }];

Usage

Call YsoNetwork.rewardedShow to display a rewarded ad with the specified placementId. Implement the YNManager.ActionDisplay interface to define logic for handling ad display, click, and close events, including rewarding the user if the ad is watched completely.

Parameters

  • key: The identifier for the rewarded ad placement created on the YSO Network dashboard.

  • viewController: The view controller the ad should render in.

  • onDisplay(YNWebView view): Called when the ad is displayed.

  • onClick(): Called when the ad is clicked.

  • onClose(boolean display, boolean complete): Called when the ad is closed, with parameters indicating if the ad was displayed and if the ad view was fully completed.

Load banner

The YsoNetwork.bannerLoad method is used to load a banner ad.

Prototype

+ (void) bannerLoadWithKey:(NSString *_Nonnull)key json:(NSString *_Nonnull)json onLoad:(nonnull void (^)(e_ActionError error))onLoad;

Code Example

[YsoNetwork bannerLoadWithKey:key json:adResponse onLoad:^(e_ActionError error) { if (error == e_ActionErrorNone) { /* mediation load success logic */ } else { /* mediation load error logic */ } }];

Usage

Call YsoNetwork.bannerLoad to initiate the loading of a banner ad with the specified key and adResponse.

Parameters

  • key: The identifier for the banner ad placement created on the YSO Network dashboard.

  • adResponse: The ad response from the bidding process, for example bidResponse.seatbid[0].bid[0].ext.signaldata.

  • onLoad: The error parameter passed to the callback function to indicate success or the type of error that occurred.

Show Banner

The YsoNetwork.bannerShow method is used to display a banner ad.

Prototype

+ (void) bannerShowWithKey:(NSString *_Nonnull)key viewController:(UIViewController *_Nonnull)viewController onDisplay:(nonnull void (^)(YNWebView *_Nullable view))onDisplay onClick:(nonnull void (^)(void))onClick onClose:(nonnull void (^)(bool, bool))onClose;

Code Example

[YsoNetwork bannerShowWithKey:key viewController:viewController onDisplay:^(YNWebView *view){ /* mediation logic on ad display */ } onClick:^{ /* mediation logic on ad click */ } onClose:^(bool display, bool complete) { if (display == YES) { /* mediation logic on ad successfully closed */ } else { /* mediation logic on ad display error */ } }];

Usage

Call YsoNetwork.bannerShow to display a banner ad with the specified key and the viewController the ad should display in. Implement the three callbacks to define the logic for handling ad display, click, and close events.

Parameters

  • key: The identifier for the banner ad placement created on the YSO Network dashboard.

  • viewController: The view controller the ad should render in.

  • onDisplay(YNWebView view): Called when the ad is displayed.

  • onClick(): Called when the ad is clicked.

  • onClose(boolean display, boolean complete): Called when the ad is closed, with parameters indicating if the ad was displayed and if the ad view was fully completed.

Cleanup

[YsoNetwork destroy];

The YsoNetwork.destroy() method is called to perform cleanup operations. This method is responsible for releasing any resources, closing connections, and performing any other necessary tear down tasks for the YsoNetwork class. It ensures that the network is properly shut down and any associated resources are freed, preventing potential memory leaks and other issues.

Ensure that YsoNetwork.destroy() is called when the network operations are no longer needed, typically during the application's shutdown process or when the network component is being reinitialized.

Error types

  • e_ActionErrorSdkNotInitialized: sdk not initialized

  • e_ActionErrorInvalidRequest: bad request data sent to SDK

  • e_ActionErrorInvalidConfig: invalid ad configuration

  • e_ActionErrorLoad: ad load error

  • e_ActionErrorTimeout: timeout loading the ad

  • e_ActionErrorServer: error in the server response

  • e_ActionErrorInternal: other error

Full example adapter

#import "YsoNetworkMediationAdapter.h" #import <YsoNetwork/YsoNetwork.h> #define ADAPTER_VERSION @"1.0.0.0.0" @implementation YsoNetworkMediationAdapter #pragma mark - MediationAdapter Methods - (void)initialize { if ([YsoNetwork isInitialized] == NO) { @try { [YsoNetwork initializeWithViewController:[ALUtils topViewControllerFromKeyWindow]]; /* mediation logic on sdk initialize success */ } @catch (NSException *exception) { /* mediation logic on sdk initialize fail */ } [YNLog prodInfo: [NSString stringWithFormat:@"YSO Network Adapter SDK %@", ADAPTER_VERSION]]; } else { /* mediation logic on sdk already initialized */ } } - (NSString *)SDKVersion { return [YsoNetwork getSdkVersion]; } - (NSString *)adapterVersion { return ADAPTER_VERSION; } - (void)destroy { [YsoNetwork destroy]; } + (AdapterError *)ActionErrorToAdapterError:(e_ActionError)error { [YNLog info:@"ActionErrorToAdapterError"]; switch (error) { case e_ActionErrorSdkNotInitialized: return AdapterError.notInitialized; case e_ActionErrorInvalidRequest: return AdapterError.badRequest; case e_ActionErrorInvalidConfig: return AdapterError.invalidConfiguration; case e_ActionErrorLoad: return AdapterError.invalidLoadState; case e_ActionErrorServer: return AdapterError.serverError; case e_ActionErrorInternal: default: return AdapterError.internalError; } } #pragma mark - Signal Collection - (void)collectSignalWithDelegate:(id<SignalCollectionDelegate>)delegate { [delegate didCollectSignal: [YsoNetwork getSignal]]; } #pragma mark - Interstitial - (void)loadInterstitialAdForParameters:(id<AdapterResponseParameters>)parameters andNotify:(id<InterstitialAdapterDelegate>)delegate { [YsoNetwork interstitialLoadWithKey:[parameters key] json:[parameters adResponse] onLoad:^(e_ActionError error) { if (error == e_ActionErrorNone) { [delegate didLoadInterstitialAd]; } else { [delegate didFailToLoadInterstitialAdWithError: [YsoNetworkMediationAdapter ActionErrorToAdapterError:error]]; } }]; } - (void)showInterstitialAdForParameters:(id<AdapterResponseParameters>)parameters viewController:(UIViewController *_Nonnull)viewController andNotify:(id<InterstitialAdapterDelegate>)delegate { [YsoNetwork interstitialShowWithKey:[parameters key] viewController:viewController onDisplay:^(YNWebView *view){ [delegate didDisplayInterstitialAd]; } onClick:^{ [delegate didClickInterstitialAd]; } onClose:^(bool display, bool complete) { if (display == YES) { [delegate didHideInterstitialAd]; } else { [delegate didFailToDisplayInterstitialAdWithError:AdapterError.adNotReady]; } }]; } #pragma mark - Rewarded - (void)loadRewardedAdForParameters:(id<AdapterResponseParameters>)parameters andNotify:(id<RewardedAdapterDelegate>)delegate { [YsoNetwork rewardedLoadWithKey:[parameters key] json:[parameters adResponse] onLoad:^(e_ActionError error) { if (error == e_ActionErrorNone) { [delegate didLoadRewardedAd]; } else { [delegate didFailToLoadRewardedAdWithError: [YsoNetworkMediationAdapter ActionErrorToAdapterError:error]]; } }]; } - (void)showRewardedAdForParameters:(id<AdapterResponseParameters>)parameters viewController:(UIViewController *_Nonnull)viewController andNotify:(id<RewardedAdapterDelegate>)delegate { [YsoNetwork rewardedShowWithKey:[parameters key] viewController:viewController onDisplay:^(YNWebView *view){ [delegate didDisplayRewardedAd]; } onClick:^{ [delegate didClickRewardedAd]; } onClose:^(bool display, bool complete) { if (display == YES) { if (complete == YES) { [delegate didRewardUserWithReward]; } [delegate didHideRewardedAd]; } else { [delegate didFailToDisplayRewardedAdWithError:AdapterError.adNotReady]; } }]; } - (void)loadAdViewAdForParameters:(id<AdapterResponseParameters>)parameters adFormat:(AdFormat *)adFormat viewController:(UIViewController *_Nonnull)viewController andNotify:(id<AdViewAdapterDelegate>)delegate { [YsoNetwork bannerLoadWithKey:[parameters key] json:[parameters adResponse] onLoad:^(e_ActionError error) { if (error == e_ActionErrorNone) { [YsoNetwork bannerShowWithKey:[parameters key] viewController:viewController onDisplay:^(YNWebView *view){ [delegate didLoadAdForAdView:view]; [delegate didDisplayAdViewAd]; } onClick:^{ [delegate didClickAdViewAd]; } onClose:^(bool display, bool complete) { if (display == YES) { [delegate didHideAdViewAd]; } else { [delegate didFailToDisplayAdViewAdWithError:AdapterError.adNotReady]; } }]; } else { [delegate didFailToLoadAdViewAdWithError: [YsoNetworkMediationAdapter ActionErrorToAdapterError:error]]; } }]; } @end
Last modified: 26 July 2024