chaimPaneth / react-native-jw-media-player

React-Native Android/iOS bridge for JWPlayer SDK (https://www.jwplayer.com/)
MIT License
190 stars 91 forks source link

How to access adTitle and others ad fields #330

Closed felire closed 7 months ago

felire commented 7 months ago

I'd like to access some ad fields when I receive an adEvent, is there a way of doing that here?

- (void)jwplayer:(id<JWPlayer>)player adEvent:(JWAdEvent * _Nonnull)event {
    [super jwplayer:player adEvent:event];
    if (_parentView.onAdEvent) {
        _parentView.onAdEvent(@{@"client": @(event.client), @"type": @(event.type), @"adTitle": @("asd")});
    }
}

I do not know too much of Objective C. But I am not finding a proper way of accessing the fields that should be on JWAdImpression as far as I read.

I'd like to know if there is a way to access to the JWAdImpression NSObject with all of that information from the Event or the Player itself on that function I shared

Please let mek now if there is a way of doing this, thanks!

felire commented 7 months ago

I figured it out, I am gonna make a pr probably:

With this I was able to access to every value I needed:

    JWAdEventKey adClickThroughUrlKey = JWAdEventKeyClickThroughUrl;
    JWAdEventKey adTitleKey = JWAdEventKeyAdTitle;
    JWAdEventKey adPositionKey = JWAdEventKeyAdPosition;
    NSString *position = [event objectForKeyedSubscript:adPositionKey];
    NSString *title = [event objectForKeyedSubscript:adTitleKey];
    NSString *clickThrough = [event objectForKeyedSubscript:adClickThroughUrlKey];