Please make sure you have read the guidelines before doing an implementation!

Concept

We provide a generic view containing all the information needed to create your own Sashimi ad.
The list of the available properties is available in the header of the AFAdSDKSashimiView class.
You can check the API reference for a more friendly interface.

To give you an idea of the possibilities, our own template formats are subclasses of AFAdSDKSashimiView.

Just like the template formats, the custom views are tappable and will trigger the SKStoreProductViewController.

Create your subclass of Sashimi

In order to implement your own Sashimi view, you will need to subclass AFAdSDKSashimiView:

#import "AFAdSDKSashimiView.h"

@interface MySashimiView : AFAdSDKSashimiView

@end
#import "MySashimiView.h"

@implementation MySashimiView

// Your implementation goes here.

@end

Create your custom view programmatically

In the implementation file of this class you must implement the -sashimiIsReadyForInitialization method in which you will create your design elements. This is basically the moment which indicates you that the advertised information are ready:

@interface MySashimiView ()

// Title label of the advertised application.
@property (nonatomic, strong) UILabel *titleLabel;

// Etc...

@end

@implementation MySashimiView

- (void)sashimiIsReadyForInitialization {

    // Title label.
    self.titleLabel = [[UILabel alloc] init];
    self.titleLabel.text = self.title;
    self.titleLabel.backgroundColor = [UIColor whiteColor];
    self.titleLabel.font = [UIFont fontWithName:@"Helvetica-Bold" size:14.0];
    self.titleLabel.minimumFontSize = 11.0;
    self.titleLabel.adjustsFontSizeToFitWidth = YES;
    self.titleLabel.textColor = [UIColor blackColor];
    [self addSubview:self.titleLabel];

    // Etc...
}

@end
If you don't create and instantiate your subviews in the -sashimiIsReadyForInitialization method, there are risks your sashimi view will be broken.

And do not forget to layout your subviews in the -layoutSubviews method:

- (void)layoutSubviews {

    CGSize titleSize;
    CGRect titleFrame;

    // Title frame.
    titleSize = [self.titleLabel.text sizeWithFont:self.titleLabel.font];
    titleFrame = CGRectMake(10.0, 10.0, CGRectGetWidth(self.bounds) - 20.0, titleSize.height);
    titleFrame = CGRectIntegral(titleFrame);
    self.titleLabel.frame = titleFrame;

    // Etc...

}

Create your custom view using Interface Builder

It is also possible to create the user interface and layout of the custom Sashimi using Interface Builder.


Steps


  1. Create a subclass of the Sashimi like explained above (let's say MySashimiView), but you can skip the creation of UI elements and their layout (as it will be handled in IB)
  2. Create a XIB for the user interface of the Sashimi with Xcode, and set MySashimiView as the custom class (or the name you choose)
  3. Connect the outlets between the XIB objects and the properties of your class MySashimiView
  4. Don't forget to assign the values in the method sashimiIsReadyForInitialization
- (void)sashimiIsReadyForInitialization {

    // title
    [self.titleLabel setText:self.title];

    // Etc...

}

Notes


  • If you are using a XIB, you'll have to use a specific method to count the number of available ads (+numberOfSashimiAdsAvailableForNibName:), and get the sashimi view (+sashimiViewForNibName:withController:andError:)
  • You can find an example in the demo projects!

Correctly resize the Ad Badge

Since version 2.5.1, the Ad Badge has a size which can vary depending the device language. If you use the default size of the view, you don't need to do anything. But if you want to use a bigger version of the badge, or if you use IB, then you'll have to calculate the proper size of the view.

How to calculate the correct size of the badge?

Please use the method sizeThatFits: to get the proper size of the Ad Badge.

CGRect badgeFrame = CGRectZero;
badgeFrame.size = [self.badgeView sizeThatFits:CGSizeMake(80.0, 33.0)];

Display your sashimi

Before anything make sure your walked through these required steps before starting the integration of Sashimi.

Imports

The first thing you need to do is to import the required classes:

// Required for Appsfire advertising.
#import "AppsfireAdSDK.h"

// Your custom Sashimi class.
#import "MySashimiView.h"

Calculate how many ads are available

Before getting any Sashimi ads, you need to check how many ads are available for the format you want. For instance in this case, you need to check how many ads are available for your custom MySashimiView class you will need to do something like this:

NSUInteger sashimiCustomAdsCount = [AppsfireAdSDK numberOfSashimiAdsAvailableForSubclass:[MySashimiView class] forZone:@"ZONE_ID"];

ZONE_ID is the zone ID for your Sashimi (in-stream) ads as provided by Appsfire.

If you use Interface Builder to build your Custom Sashimi (XIB), you must use +numberOfSashimiAdsAvailableForNibName: at this stage.

Get a Sashimi ad

When the returned count is not 0 then you know you can get a Sashimi view. Getting a Sashimi view is done per format basis and for instance if you need a minimal Sashimi view you can do so with the following lines of code:

NSError *error;
MySashimiView *mySashimiView;

// Get Sashimi view
mySashimiView = [AppsfireAdSDK sashimiViewForSubclass:[MySashimiView class] forZone:@"ZONE_ID" withController:[UIApplication sharedApplication].keyWindow.rootViewController andError:&error];

// Before using this view make sure the returned view is not `nil` and that there is not error.
if (mySashimiView != nil && error == nil) {

    // You can safely use the view

}

If you use Interface Builder to build your Custom Sashimi (XIB), you must use +sashimiViewForNibName:forZone:withController:andError: at this stage.

When you have got your Sashimi view you are ready to add it to a UIView as a subview. For instance you can add it into a UITableViewCell:
However we recommend you to subclass an UITableViewCell or an UICollectionViewCell to better handle the layout.

// Adding the Sashimi view into the `contentView` of the cell.
[cell.contentView addSubview:sashimiMinimalView];

Use the delegate

A delegate method let you know once some ads are available.
We recommend you to use it for a ideal implementation.

Be sure to:

  • Set the delegate via [AppsfireAdSDK setDelegate:object]
  • Check how many Sashimi ads are available for the format you need!

- (void)sashimiAdsRefreshedAndAvailable {

    NSLog(@"Sashimi ads were received");

    // check if a sashimi ad is available for the format
    NSUInteger sashimiCustomAdsCount = [AppsfireAdSDK numberOfSashimiAdsAvailableForSubclass:[MySashimiView class] forZone:@"ZONE_ID"];
    NSLog(@"Number of Sashimi Minimal ads received:%lu", (unsigned long)sashimiCustomAdsCount);

}

If you use Interface Builder to build your Custom Sashimi (XIB), you must use +numberOfSashimiAdsAvailableForNibName:forZone at this stage.

For a complete example of integration, refer to the demo project dedicated to the Sashimi format.
You can find it in the Xcode package of our SDK in examples/ folder.