OMIDJavaScriptSessionService

Objective-C

@interface OMIDJavaScriptSessionService : NSObject <WKScriptMessageHandler>

Swift

class OMIDJavaScriptSessionService : NSObject, WKScriptMessageHandler

Service supporting ad sessions managed (started/finished) via JavaScript Session Client APIs by providing native-layer measurement signals. If the JS Session Client is running in a web view, an instance of this service must be initialized with the web view before starting or finishing ad sessions using JS APIs. Only one instance of this service may be initialized at a time for a given web view; to reuse a web view the current instance must be torn down (see tearDownWithCompletion).

  • Initializes an instance of the service.

    Declaration

    Objective-C

    - (nullable instancetype)initWithPartner:(nonnull OMIDPartner *)partner
                                     webView:(nonnull WKWebView *)webView
                                isHTMLAdView:(BOOL)isHTMLAdView
                                       error:(NSError *_Nullable *_Nullable)error;

    Swift

    init(partner: OMIDPartner, webView: WKWebView, isHTMLAdView: Bool) throws

    Parameters

    partner

    Details of the integration partner responsible for ad sessions.

    webView

    The web view responsible for starting/finishing ad sessions via the JS Session Client.

    isHTMLAdView

    Whether the ad is rendered in HTML inside of the provided web view. If true, all ad sessions will be of type “html” and calling setAdView is not required. If false, all ad sessions will be of type “javascript” and setAdView must be called after initialization.

  • Tears down this instance of the service. Calling this method will cause OM SDK to begin a teardown process including finishing all currently active ad sessions measured by this service instance and tearing down communication with the OM SDK’s JavaScript layer running in the web view. This may require up to one second, for example in order to allow verification scripts time to process the sessionFinish event. Once this process has completed, the web view may be torn down or reused for another instance of the service without any adverse effects. If there is no need to tear down or reuse the web view, this method is not required.

    Declaration

    Objective-C

    - (void)tearDownWithCompletion:
        (nonnull void (^)(BOOL, NSError *_Nullable))completionBlock;

    Swift

    func tearDown() async throws -> Bool

    Parameters

    completionBlock

    Invoked by OM SDK after the teardown process has completed, or one second, whichever comes sooner.

  • The native view containing the ad. This property is readonly and must be set using setAdView. If isHTMLAdView was passed as true in initWithPartner, this will equal the web view by default.

    Declaration

    Objective-C

    @property (nonatomic, weak, readonly) UIView *_Nullable adView;

    Swift

    weak var adView: UIView? { get }
  • Sets the native view that contains the ad and is used for viewability tracking. If isHTMLAdView was passed as true in initWithPartner, this method is not required since the ad view will be set to the web view by default.

    Declaration

    Objective-C

    - (BOOL)setAdView:(nullable UIView *)adView
                error:(NSError *_Nullable *_Nullable)error;

    Swift

    func setAdView(_ adView: UIView?) throws

    Parameters

    adView

    The native view.

    Return Value

    Whether the ad view was successfully set.

  • Adds a friendly obstruction which should then be excluded from all ad session viewability calculations. While this instance of OMIDJavaScriptSessionService is running, this friendly obstruction will be added to each ad session started by the integrator via the JS Session Client until the obstruction is removed by calling removeFriendlyObstruction or removeAllFriendlyObstructions.

    Declaration

    Objective-C

    - (BOOL)addFriendlyObstruction:(nonnull UIView *)friendlyObstruction
                           purpose:(OMIDFriendlyObstructionType)purpose
                    detailedReason:(nullable NSString *)detailedReason
                             error:(NSError *_Nullable *_Nullable)error;

    Swift

    func addFriendlyObstruction(_ friendlyObstruction: UIView, purpose: OMIDFriendlyObstructionType, detailedReason: String?) throws

    Parameters

    friendlyObstruction

    The view to be excluded from all ad session viewability calculations.

    purpose

    The purpose of why this obstruction was necessary.

    detailedReason

    An explanation for why this obstruction is part of the ad experience if not already obvious from the purpose. Can be nil. If not nil, must be 50 characters or less and only contain characters A-z, 0-9, or spaces.

    Return Value

    Whether this friendly obstruction was successfully added. If the friendlyObstruction has already been added for this session, this method will return NO with no associated error object. However, if one or more arguments are against requirements, it will return NO with an error object assigned.

  • Removes a registered friendly obstruction from any currently running and future ad sessions measured by this instance of OMIDJavaScriptSessionService.

    Declaration

    Objective-C

    - (void)removeFriendlyObstruction:(nonnull UIView *)friendlyObstruction;

    Swift

    func removeFriendlyObstruction(_ friendlyObstruction: UIView)
  • Removes all registered friendly obstructions from any currently running and future ad sessions measured by this instance of OMIDJavaScriptSessionService.

    Declaration

    Objective-C

    - (void)removeAllFriendlyObstructions;

    Swift

    func removeAllFriendlyObstructions()