SASNativeAd

Objective-C

@interface SASNativeAd : NSObject <NSCopying, NSCoding>

Swift

class SASNativeAd : NSObject, NSCopying, NSCoding

A SASNativeAd represents an ad that will be displayed by the native code of the application.

Note

Contrary to the SASAd object, the SASNativeAd only contains information that needs to be displayed but does not create any view for the actual display: your application is reponsible of the ad rendering.

Required information

  • The title of the ad (required).

    Declaration

    Objective-C

    @property (nonatomic, strong, readonly, nullable) NSString *title;

    Swift

    var title: String? { get }

Optional information

  • The subtitle of the ad.

    Can be used as a short description.

    Declaration

    Objective-C

    @property (nonatomic, strong, readonly, nullable) NSString *subtitle;

    Swift

    var subtitle: String? { get }
  • The body of the ad.

    Can be used as a long description.

    Declaration

    Objective-C

    @property (nonatomic, strong, readonly, nullable) NSString *body;

    Swift

    var body: String? { get }
  • The call to action text of the ad.

    This text represents the action that will be made when the ad is clicked: for instance ‘Open’ or ‘Download’.

    Declaration

    Objective-C

    @property (nonatomic, strong, readonly, nullable) NSString *callToAction;

    Swift

    var callToAction: String? { get }
  • The icon of the ad.

    Declaration

    Objective-C

    @property (nonatomic, strong, readonly, nullable) SASNativeAdImage *icon;

    Swift

    var icon: SASNativeAdImage? { get }
  • The cover image of the ad.

    A cover image is an image that is generally larger that the icon and that will generally be used as a background image.

    Declaration

    Objective-C

    @property (nonatomic, strong, readonly, nullable) SASNativeAdImage *coverImage;

    Swift

    var coverImage: SASNativeAdImage? { get }
  • The ‘sponsored by’ message of the ad.

    Generally contains the brand name of the sponsor.

    Declaration

    Objective-C

    @property (nonatomic, strong, readonly, nullable) NSString *sponsored;

    Swift

    var sponsored: String? { get }
  • The rating between 0-5 of the advertised app / product or SASRatingUndefined if not set.

    Declaration

    Objective-C

    @property (nonatomic, readonly) float rating;

    Swift

    var rating: Float { get }
  • Number of social likes of the advertised app / product or SASLikesUndefined if not set.

    Declaration

    Objective-C

    @property (nonatomic, readonly) int64_t likes;

    Swift

    var likes: Int64 { get }
  • Number of downloads / installs of the advertised app or SASDownloadsUndefined if not set.

    Declaration

    Objective-C

    @property (nonatomic, readonly) int64_t downloads;

    Swift

    var downloads: Int64 { get }
  • The price of of the advertised app / product, value will generally include currency symbol in localized format.

    Declaration

    Objective-C

    @property (nonatomic, strong, readonly, nullable) NSString *price;

    Swift

    var price: String? { get }
  • A dictionary of custom parameters that have been sent by the ad.

    This dictionary can be used to carry additional resources or information. You need a compatible Smart AdServer template to use this feature.

    Declaration

    Objective-C

    @property (nonatomic, strong, readonly, nullable) NSDictionary *extraParameters;

    Swift

    var extraParameters: [AnyHashable : Any]? { get }

Other properties

  • The object that acts as the delegate of the receiving native ad.

    The delegate must adopt the SASNativeAdDelegate protocol.

    Declaration

    Objective-C

    @property (nonatomic, weak, nullable) id<SASNativeAdDelegate> delegate;

    Swift

    weak var delegate: SASNativeAdDelegate? { get set }
  • Indicates whether the native ad has a media to be displayed in a SASNativeAdMediaView.

    Declaration

    Objective-C

    @property (nonatomic, readonly) BOOL hasMedia;

    Swift

    var hasMedia: Bool { get }
  • The aspect ratio of the media (width / height).

    Declaration

    Objective-C

    @property (nonatomic, readonly) float mediaAspectRatio;

    Swift

    var mediaAspectRatio: Float { get }
  • A string which contains useful informations about the ad.

    This string can be sent to Smart’s support to improve bug resolution if the issue is related to a given ad, or can be used with your app crash reporting tool to analyze crash sources.

    Warning

    The string content and format is not guaranted to stay the same: you should avoid parsing it.

    Declaration

    Objective-C

    @property (nonatomic, readonly) NSString *_Nonnull debugString;

    Swift

    var debugString: String { get }

Util methods

  • Returns the recommanded height to display the native ad media in a given container, according to the media aspect ratio.

    If no media exists, this method will return 0.

    If ‘container’ is nil, the height returned will be the optimal height for a fullscreen width.

    Declaration

    Objective-C

    - (CGFloat)optimalMediaViewHeightForContainer:(nullable UIView *)container;

    Swift

    func optimalMediaViewHeight(forContainer container: UIView?) -> CGFloat

    Parameters

    container

    The container in which the ad media will be displayed (if nil, the current window will be used instead).

    Return Value

    The optimized height for the mediaview.

  • Returns the recommanded height to display the native ad media in a given width, according to the media aspect ratio.

    If no media exists, this method will return 0.

    Declaration

    Objective-C

    - (CGFloat)optimalMediaViewHeightForWidth:(CGFloat)width;

    Swift

    func optimalMediaViewHeight(forWidth width: CGFloat) -> CGFloat

    Parameters

    width

    The width of the container in which the ad media will be displayed (if nil, the current window will be used instead).

    Return Value

    The optimized height for a given width.

  • Returns the recommanded height to display the native cover image in a given container, according to the cover image aspect ratio.

    If no cover image exists, this method will return 0.

    If ‘container’ is nil, the height returned will be the optimal height for a fullscreen width.

    Declaration

    Objective-C

    - (CGFloat)optimalCoverViewHeightForContainer:(nullable UIView *)container;

    Swift

    func optimalCoverViewHeight(forContainer container: UIView?) -> CGFloat

    Parameters

    container

    The container in which the ad cover image will be displayed (if nil, the current window will be used instead).

    Return Value

    The optimized height for the cover image.

  • Returns the recommanded height to display the native ad cover image in a given width, according to the cover image aspect ratio.

    If no cover image exists, this method will return 0.

    Declaration

    Objective-C

    - (CGFloat)optimalCoverViewHeightForWidth:(CGFloat)width;

    Swift

    func optimalCoverViewHeight(forWidth width: CGFloat) -> CGFloat

    Parameters

    width

    The width of the container in which the ad cover image will be displayed (if nil, the current window will be used instead)

    Return Value

    The optimized height for a given width

View registering

  • Registers the view that will be used for viewability tracking and tappable views that will be used as click target in your native ad.

    Note

    You MUST register at least one view for each displayed native ad otherwise the impression will not be registered.

    Declaration

    Objective-C

    - (void)registerView:(nonnull UIView *)view
                    tappableViews:(nonnull NSArray *)views
        modalParentViewController:
            (nonnull UIViewController *)modalParentViewController;

    Swift

    func register(_ view: UIView, tappableViews views: [Any], modalParentViewController: UIViewController)

    Parameters

    view

    A view that will be registered as main view and used for viewability tracking.

    views

    An array of views that will be registered as click target.

    modalParentViewController

    The view controller that will be used if the ad needs to open a modal view or a store controller.

  • Convenient method to register only one view as click target and viewability tracking.

    Note

    You MUST register at least one view for each displayed native ad otherwise the impression will not be registered.

    Declaration

    Objective-C

    - (void)registerView:(nonnull UIView *)view
        modalParentViewController:
            (nonnull UIViewController *)modalParentViewController;

    Swift

    func register(_ view: UIView, modalParentViewController: UIViewController)

    Parameters

    view

    A view that will be registered as click target and used for viewability tracking.

    modalParentViewController

    The view controller that will be used if the ad needs to open a modal view or a store controller.

  • Unregisters all views that are currently being used as click target.

    Declaration

    Objective-C

    - (void)unregisterViews;

    Swift

    func unregisterViews()