{"__v":36,"_id":"5640d891d4b2e00d00bb3d48","category":{"project":"5429beef1163360800ed31fa","version":"5429beef1163360800ed31fd","_id":"566f85ca7820960d00c3b93d","pages":[],"__v":0,"sync":{"url":"","isSync":false},"reference":false,"createdAt":"2015-12-15T03:15:22.182Z","from_sync":false,"order":3,"slug":"integrating-for-apps","title":"Integrating for Apps"},"parentDoc":null,"project":"5429beef1163360800ed31fa","user":"563b4a20dfa1282b000dd262","version":{"__v":21,"_id":"5429beef1163360800ed31fd","project":"5429beef1163360800ed31fa","createdAt":"2014-09-29T20:19:59.904Z","releaseDate":"2014-09-29T20:19:59.904Z","categories":["5429beef1163360800ed31fe","55e74e1f5d36b32b002563fa","55e7500a73169617001f2e86","55e76b8196131b2f00bf4b72","55e89569cdbb8a350096df9c","55f8935eb089b71700a8364e","55f8a67d3bb4bb0d0022d093","55f9dbefc7ef770d00d9bf6d","5601c21a22ecf60d002b27b3","5601c21ff12aee0d001bb06e","5601c2256c7b610d00280db5","5601c22c22ecf60d002b27b4","5603738d0c78b00d0039af47","5626f70bfcbbc621004ebf52","566f7a1ae144ab0d00e9732f","566f85ca7820960d00c3b93d","56708ce43a32d20d00c45cbf","56708d436995210d003aad8e","5736471abe10a9200030732c","57a82c7aff9bd30e00a6f1c1","591b8500e3992319007190f4"],"is_deprecated":false,"is_hidden":false,"is_beta":false,"is_stable":true,"codename":"","version_clean":"1.0.0","version":"1.0"},"updates":[],"next":{"pages":[],"description":""},"createdAt":"2015-11-09T17:32:01.975Z","link_external":false,"link_url":"","githubsync":"","sync_unique":"","hidden":false,"api":{"results":{"codes":[]},"settings":"","auth":"required","params":[],"url":""},"isReference":false,"order":0,"body":"Welcome to AdsNative iOS SDK wiki! Please check out the **Getting Started** section below before integrating your app with the SDK.\n[block:api-header]\n{\n  \"type\": \"basic\",\n  \"title\": \"Getting Started\"\n}\n[/block]\nThis section details the process of including your iOS application with the AdsNative SDK along with setting up framework dependencies.\n\nThe basic integration steps are as follows\n\n  * Download the AdsNative SDK\n  * Include the SDK into your xcode project and setup dependencies\n  * Integrate one of the supported Native Ad formats\n\n**Download the AdsNative SDK** \n\nThe AdsNative iOS SDK is distributed as a framework which you must download and incorporate into your xcode project. Click [**here**](https://github.com/picatcha/adsnative-sdk-ios/archive/master.zip) to download the AdsNative SDK.\n\n**Include the SDK into your xcode project and setup dependencies**\n\nThe following instructions assume you've downloaded the AdsNativeSDK.framework which is to be included into your project.\n\nDrag the downloaded AdsNativeSDK.framework build into your Frameworks folder of the project (be sure to check the \"Copy items into destination group's folder\" option). If the Frameworks folder isn't present, create one by right clicking the project and selecting \"New Group\" with the name \"Frameworks\".\nAdd the following frameworks to your project. To do this, click on your application's target, then click on Build Phases and expand the Link Binary With Libraries group.\nThe AdsNative SDK requires you to add the following frameworks into your xcode project.\n\n  * Foundation.framework\n  * UIKit.framework\n  * SystemConfiguration.framework\n  * CoreLocation.framework\n  * CoreGraphics.framework\n  * AdSupport.framework (Optional)\n  * StoreKit.framework (Optional)\n\n*The Optional frameworks are needed if you are targeting iOS versions below 6.0*\n\n**Integrate one of the supported Native Ad formats**\n\nAdsNative supports the following ad formats\n\n  * [**Content Stream Ads**](http://dev.adsnative.com/docs/ios-sdk#content-stream-ad-placement) - These are ads that appear as a part of a content stream. For iOS, we support the UITableView and UICollectionView layouts. This is the recommended way of integrating with AdsNative, as it provides caching and image pre-loading out of the box.\n  * [**Single Native Ad/Manual Integration**](http://dev.adsnative.com/docs/ios-sdk#standard-integration) - If you have a custom requirement or would like to stitch the native ad assets yourself, AdsNative SDK supports this by requesting a single native ad\n\n**Additional Configuration for iOS 9**\nOne of the changes that have come in with iOS 9 is App Transport Security (ATS). ATS basically requires apps to make network connections only over SSL. This is the default behaviour for iOS 9 and currently the AdsNative SDK doesn't support this. To build apps against iOS 9, ATS needs to be disabled to ensure that the AdsNative SDK works correctly. To disable ATS, add the following to your app plist (info.plist) \n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"<key>NSAppTransportSecurity</key>\\n<dict>\\n    <key>NSAllowsArbitraryLoads</key>\\n    <true/>\\n</dict>\",\n      \"language\": \"xml\"\n    }\n  ]\n}\n[/block]\n**Integrating Other Networks**\nIf you wish to add other networks for mediation, [**click here**](http://dev.adsnative.com/docs/ios-sdk#integrating-other-networks) to know how to do this.\n[block:api-header]\n{\n  \"type\": \"basic\",\n  \"title\": \"Content Stream Ad Placement\"\n}\n[/block]\nThe following section details the steps to be followed when placing ads in a content stream, i.e., either a UITableView or a UICollectionView. Native ad integration into a content stream can be completed in 3 steps.\n\n  * Create and define the layout for your ad\n  * Place and load ads into your content stream\n  * Replace the UITableView and UICollectionView methods with its AdsNative ('an_') counterparts\n\nTo know how to render native ad assets on a view, [**click here**](http://dev.adsnative.com/docs/ios-sdk#defining-ad-layouts).\n\nLoad Ads into a content stream\n\nDepending on which type of stream you want to load native ads into, see one of the below links.\n\n  * [**Table View Integration**](http://dev.adsnative.com/docs/ios-sdk#table-view-integration)\n  * [**Collection View Integration**](http://dev.adsnative.com/docs/ios-sdk#collection-view-integration) \n[block:api-header]\n{\n  \"type\": \"basic\",\n  \"title\": \"Table View Integration\"\n}\n[/block]\nThis section details how to place native ads into a table view using the AdsNative SDK. The AdsNative SDK handles image caching and metrics (impressions, clicks) tracking so all you have to do is figure out how, when, and where to display ads.\n\n**Prerequisites**\nBefore going through this section, you'll need to go through the [**Getting Started**](http://dev.adsnative.com/docs/ios-sdk#getting-started) section followed by the [**Content Stream Ad Placement**](http://dev.adsnative.com/docs/ios-sdk#content-stream-ad-placement) section.\n\n**Place Ads in a Table View**\nThe AdsNative SDK lets you place ads into a table view using the ANTableViewAdPlacer class. It handles requesting ads and placing ads into your table view class.\n\nWhen an instance of ANTableViewAdPlacer is initialised with a table view, it takes the table view's data source and delegate and wraps it in order to insert ads and adjust the positions of your regular content cells.\n\nIn your UITableView class's view controller's viewDidLoad method\n\n1. Specify Your Ad Positions and Ad Request Targeting information\n\nNOTE: This step is optional and may be ignored.\n\nBefore making a native ad request, you need to tell the ANTableViewAdPlacer what type of ad positions you've opted for, i.e., server or client positions. If you've specified ad positions on the AdsNative UI, then initialise a server positions object.\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"ANServerAdPositions *serverAdPositions = \\n\\t\\t\\t\\t\\t\\t\\t\\t\\t\\t[[ANServerAdPositions alloc] init];\",\n      \"language\": \"objectivec\"\n    }\n  ]\n}\n[/block]\nYou may further choose to specify ad request targeting information. Check out [**Ad Positions**](http://dev.adsnative.com/docs/ios-sdk#ad-positions) and [**Ad Request Targeting**](http://dev.adsnative.com/docs/ios-sdk#ad-request-targeting), for more information.\n\n2. Initialise an ANTableViewAdPlacer class\n\nAn object of ANTableViewAdPlacer has to be created with the following params -\n\n  * Table View: The UITableView class that you have to load ads into.\n  * View Controller: The View Controller for the UITableView class (typically 'self').\n  * Ad Positions: The positions object which specifies whether client or server side ad positions are used.\n  * defaultAdRenderingClass: The UIView subclass which implements the ANAdRendering protocol. This is the class into which Native Ad Assets will be rendered into.\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"self.placer = [ANTableViewAdPlacer placerWithTableView:self.tableView viewController:self adPositions:serverAdPositions defaultAdRenderingClass:[SampleAdView class]]; \",\n      \"language\": \"objectivec\"\n    }\n  ]\n}\n[/block]\n\nAlternatively, if server positions is specified, you can ignore create a positions object and initialise your ANTableViewAdPlacer in the following manner.\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"self.placer = [ANTableViewAdPlacer placerWithTableView:self.tableView viewController:self defaultAdRenderingClass:[SampleAdView class]];\",\n      \"language\": \"objectivec\"\n    }\n  ]\n}\n[/block]\n3. Load Ads For Your Table View\n\nThe penultimate step is to call the loadAdsForAdUnitId of the ANTableViewAdPlacer using the newly created instance. This method requires a string which is the AdUnitId that you get while registering an account on our AdsNative dashboard.\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"[self.placer loadAdsForAdUnitID::::at:::\\\"AdUnitId\\\"];\",\n      \"language\": \"objectivec\"\n    }\n  ]\n}\n[/block]\n4. Replace UITableView methods with 'an_' counterparts\n\nIn order to account for the ad placements in your table view, you have to replace UITableView method calls with their 'an_' counterparts. Everything else is handled by us.\n\nSo, instead of:\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"[self.tableView selectRowAtIndexPath:myIndexPath];\",\n      \"language\": \"objectivec\"\n    }\n  ]\n}\n[/block]\nUse:\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"[self.tableView an_selectRowAtIndexPath:myIndexPath];\",\n      \"language\": \"objectivec\"\n    }\n  ]\n}\n[/block]\nAll this does is make adjustments to the NSIndexPath to account for the ads in your stream.\n\nImportant Note: Failing to make these replacements will lead to problems with your row positions be out of sync with your table view. All UITableView methods must be prefixed with 'an_' like shown in the example above.\n\n**Sample Code** \n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"ANServerAdPositions *serverAdPositions = [[ANServerAdPositions alloc] init];\\n\\n//The defaultRenderingClass can be switched dynamically by specifying it in the AdsNative UI\\nself.placer = [ANTableViewAdPlacer placerWithTableView:self.tableView viewController:self adPositions:serverAdPositions defaultAdRenderingClass:[SampleAdView class]];\\n\\n[self.placer loadAdsForAdUnitID:@\\\"AdUnitId\\\"];\",\n      \"language\": \"objectivec\"\n    }\n  ]\n}\n[/block]\n\n[block:api-header]\n{\n  \"type\": \"basic\",\n  \"title\": \"Collection View Integration\"\n}\n[/block]\nThis section details how to place native ads into a collection view using the AdsNative SDK. The AdsNative SDK handles image caching and metrics (impressions, clicks) tracking so all you have to do is figure out how, when, and where to display ads.\n\n**Prerequisites**\nBefore going through this section, you'll need to go through the [**Getting Started**](http://dev.adsnative.com/docs/ios-sdk#getting-started) section followed by the [**Content Stream Ad Placement**](http://dev.adsnative.com/docs/ios-sdk#content-stream-ad-placement) section.\n\n**Place Ads in a Collection View**\n\nThe AdsNative SDK lets you place ads into a collection view using the ANCollectionViewAdPlacer class. It handles requesting ads and placing ads into your collection view class.\n\nWhen an instance of ANCollectionViewAdPlacer is initialised with a collection view, it takes the collection view's data source and delegate and wraps it in order to insert ads and adjust the positions of your regular content cells.\n\nIn your UICollectionView feeds view controller's viewDidLoad method\n\n1. Specify Your Ad Positions and Ad Request Targeting information\n\nNOTE: This step is optional and may be ignored.\n\nBefore making a native ad request, you need to tell the ANCollectionViewAdPlacer what type of ad positions you've opted for, i.e., server or client positions. If you've specified ad positions on the AdsNative UI, then initialise a server positions object.\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"ANServerAdPositions *serverAdPositions = \\n\\t\\t\\t\\t\\t\\t\\t\\t\\t\\t[[ANServerAdPositions alloc] init];\",\n      \"language\": \"objectivec\"\n    }\n  ]\n}\n[/block]\nYou may further choose to specify ad request targeting information. Check out [**Ad Positions**](http://dev.adsnative.com/docs/ios-sdk#ad-positions) and [**Ad Request Targeting**](http://dev.adsnative.com/docs/ios-sdk#ad-request-targeting), for more information.\n\n2. Initialise an ANCollectionViewAdPlacer class\n\nAn object of ANCollectionViewAdPlacer has to be created with the following params\n\n  * Collection View: The UICollectionView class that you have to load ads into.\n  * View Controller: The View Controller for the UICollectionView class (typically 'self').\n  * Ad Positions: The positions object which specifies whether client or server side ad positions are used.\n  * defaultAdRenderingClass: The UIView subclass which implements the ANAdRendering protocol. This is the class into which Native Ad Assets will be rendered into.\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"self.placer = [ANCollectionViewAdPlacer placerWithCollectionView:self.collectionView viewController:self adPositions:serverAdPositions defaultAdRenderingClass:[SampleAdView class]];\",\n      \"language\": \"objectivec\"\n    }\n  ]\n}\n[/block]\nAlternatively, if server positions is specified, you can ignore create a positions object and initialise your ANCollectionViewAdPlacer in the following manner.\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"self.placer = [ANCollectionViewAdPlacer placerWithCollectionView:self.collectionView viewController:self defaultAdRenderingClass:[SampleAdView class]];\",\n      \"language\": \"objectivec\"\n    }\n  ]\n}\n[/block]\n3. Load Ads For Your Collection View\n\nThe penultimate step is to call the loadAdsForAdUnitId of the ANCollectionViewAdPlacer using the newly created instance. This method requires a string which is the AdUnitId that you get while registering an account on our AdsNative dashboard.\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"[self.placer loadAdsForAdUnitID:@\\\"AdUnitId\\\"];\",\n      \"language\": \"objectivec\"\n    }\n  ]\n}\n[/block]\n4. Replace UICollectionView methods with 'an_' counterparts\n\nIn order to account for the ad placements in your collection view, you have to replace UICollectionView method calls with their 'an_' counterparts. Everything else is handled by us.\n\nSo, instead of:\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"[self.collectionView selectItemAtIndexPath:myIndexPath];\",\n      \"language\": \"objectivec\"\n    }\n  ]\n}\n[/block]\nUse:\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"[self.collectionView an_selectItemAtIndexPath:myIndexPath];\",\n      \"language\": \"objectivec\"\n    }\n  ]\n}\n[/block]\nAll this does is make adjustments to the NSIndexPath to account for the ads in your stream.\n\nImportant Note: Failing to make these replacements will lead to problems with your row positions be out of sync with your collection view. All UICollectionView methods must be prefixed with 'an_' like shown in the example above.\n\n**Sample Code** \n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"ANServerAdPositions *serverAdPositions = [[ANServerAdPositions alloc] init];\\n\\n//The defaultRenderingClass can be switched dynamically by specifying it in the AdsNative UI\\nself.placer = [ANCollectionViewAdPlacer placerWithCollectionView:self.collectionView viewController:self adPositions:serverAdPositions defaultAdRenderingClass:[SampleAdView class]];\\n\\n[self.placer loadAdsForAdUnitID:@\\\"AdUnitId\\\"];\",\n      \"language\": \"objectivec\"\n    }\n  ]\n}\n[/block]\n\n[block:api-header]\n{\n  \"type\": \"basic\",\n  \"title\": \"Standard Integration\"\n}\n[/block]\n This section details how to request and load a single native ad using the AdsNative SDK. If you plan to load native ads into a UITableView or a UICollectionView, we recommend following Table View Integration or Collection View Integration.\n\n**Prerequisites**\nBefore going through this section, you'll need to go through the [**Getting Started**](http://dev.adsnative.com/docs/ios-sdk#getting-started) section.\n\n**Load A Single Native Ad**\n\nIn your View Controllers viewDidLoad method\n\n1. Create and instance of ANNativeAd\nYou need to create an instance of ANNativeAd with the AdUnitId obtained after creating an account on the AdsNative UI.\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"ANNativeAd *nativeAd = [[ANNativeAd alloc] initWithAdUnitId:@\\\"ADIDUNIT\\\"];\\nnativeAd.delegate = self;\",\n      \"language\": \"objectivec\"\n    }\n  ]\n}\n[/block]\n2. Request for a Native Ad\nRequest the AdsNative SDK for a native ad instance by calling its loadAd method\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"[nativeAd loadAd];\",\n      \"language\": \"objectivec\"\n    }\n  ]\n}\n[/block]\n3. Implement the delegate methods\nA delegate of ANNativeAd will have to implement the following methods\n\nRequired methods\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"- (void)nativeAdDidLoad:(ANNativeAd *)nativeAd;\\n- (void)nativeAd:(ANNativeAd *)nativeAd didFailWithError:(NSError *)error;\",\n      \"language\": \"objectivec\"\n    }\n  ]\n}\n[/block]\nOptional methods\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"- (void)nativeAdDidRecordImpression;\\n- (void)nativeAdDidClick;\",\n      \"language\": \"objectivec\"\n    }\n  ]\n}\n[/block]\n4. Render Native Ad in the nativeAdDidLoad: method\n\nOnce your native ad is loaded, you have to render it into a view. The AdsNative SDK allows you to do this in one of two ways.\n\n1. Create And Define your Ad Rendering Layout (Recommended)\n\nCreate a UIView subclass the conforms to the ANAdRendering protocol. Click here for details on how to do this.\n\nCreate an adView by calling the following method\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"UIView * adView = [nativeAd renderNativeAdWithController:self defaultRenderingClass:[YourAdView class]];\",\n      \"language\": \"objectivec\"\n    }\n  ]\n}\n[/block]\nAdd the view to your parent view container\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"[self.adViewContainer addSubview:adView];\",\n      \"language\": \"objectivec\"\n    }\n  ]\n}\n[/block]\n\n**Sample Code** \n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"- (void)nativeAdDidLoad:(ANNativeAd *)nativeAd {\\nUIView * adView = [nativeAd renderNativeAdWithController:self defaultRenderingClass:[NativeAdView class]];\\n\\n[adView setFrame:self.adViewContainer.frame];\\n\\n[self.adViewContainer addSubview:adView];\\n}\",\n      \"language\": \"objectivec\"\n    }\n  ]\n}\n[/block]\n\n2. Stitch your ad view yourself\n\nThe AdsNative SDK allows you to stitch your ad view by yourself. You can retrieve individual native ad assets by using the nativeAssets property of the ANNative Ad object. It is a dictionary of ad assets with the following keys.\n\n* kNativeTitleKey - The Native Ad Title\n* kNativeTextKey - The Native Ad Text (or description)\n* kNativeIconImageKey - The Icon Image Url as string\n* kNativeMainImageKey - The Main (or Cover) Image Url as string\n* kNativeCTATextKey - The Click Through Action Text\n* kNativeStarRatingKey - The ad star rating \n\nFor example, to get the native ad title\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"NSString *adTitle = [nativeAd.nativeAssets objectForKey:kNativeCTATitleKey];\",\n      \"language\": \"objectivec\"\n    }\n  ]\n}\n[/block]\nOnce you've created your ad view, you need to register that view with the AdsNative SDK for metrics tracking.\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"[nativeAd registerNativeAdWithController:self forView:adView];\",\n      \"language\": \"objectivec\"\n    }\n  ]\n}\n[/block]\n**Sample Code** \n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"- (void)nativeAdDidLoad:(ANNativeAd *)nativeAd {\\nUIView *adView = [[UIView alloc] init];\\n\\n//Create subviews for adView and add it to adView\\n...\\n//Set the adView frame\\n[adView setFrame:self.adViewContainer.frame];\\n\\n//Register ad view for clicks and impression tracking\\n[nativeAd registerNativeAdWithController:self forView:adView];\\n\\n[self.adViewContainer addSubview:adView];\\n}\",\n      \"language\": \"objectivec\"\n    }\n  ]\n}\n[/block]\n\n[block:api-header]\n{\n  \"type\": \"basic\",\n  \"title\": \"Ad Positions\"\n}\n[/block]\nAd positions are basically placement for your ads in a content stream (be it a table view or a collection view). The AdsNative SDK requires two values for ad positioning into a content stream - the set of fixed positions where an ad should appear, and a repeating interval of ads which repeats after the last given fixed position.\n\nThere are two ways to define ad positions.\n\n**1. Dynamically through the AdsNative UI (Server Positions) - Recommended**\nThe AdsNative SDK fetches the positioning information that has been setup on the AdsNative UI. This approach of setting ad positions is recommended as you can change the ad positioning anytime on the UI without having to update your application.\n\nNo extra integration steps need to be followed for this. This is the default ad positioning that the SDK adopts.\n\n**2. Hard code positions into your app (Client Positions)**\nIf you choose to hardcode the position of the ads in your stream, you can do so by specifying ad positions in your application.\n\nCreate an ANClientPositions object.\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"ANClientAdPositions *positions = [ANClientAdPositions positioning];\",\n      \"language\": \"objectivec\"\n    }\n  ]\n}\n[/block]\nSpecify the fixed positions that you want your ads to appear. This is optional.\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"[positions addFixedIndexPath:[NSIndexPath indexPathForRow:1 inSection:0]];\",\n      \"language\": \"objectivec\"\n    }\n  ]\n}\n[/block]\n\nSpecify the repeating interval for the ads. The repeating interval must be greater than 1.\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"[positions enableRepeatingPositionsWithInterval:5];\",\n      \"language\": \"objectivec\"\n    }\n  ]\n}\n[/block]\nNote that the repeating interval starts loading ads only after the last fixed position ad.\n[block:api-header]\n{\n  \"type\": \"basic\",\n  \"title\": \"Ad Request Targeting\"\n}\n[/block]\n**Keywords**\n*(Applicable only for direct sales campaigns)*\nWhile requesting for a native ad, you can pass keywords based on which your ad request can be processed. Keywords are typically used to target ad campaigns at specific user segments. They should be formatted as an array of strings (e.g. of keywords -\"social\",\"music\").\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"ANAdRequestTargeting *targeting = [ANAdRequestTargeting targeting];\\nNSMutableArray *keywords = [[NSMutableArray alloc] init];\\n[keywords addObject:@\\\"social\\\"];\\n[keywords addObject:@\\\"music\\\"];\\ntargeting.keywords = keywords;\",\n      \"language\": \"objectivec\"\n    }\n  ]\n}\n[/block]\nNote: Make sure you pass this targeting object while calling the load ads method.\n\n**Location**\n\nThe AdsNative SDK automatically fetches the users location for better targeted ads. The location is not fetched if the user has not authorised the app for location services. If you, however, wish to disallow AdsNative SDK to fetch location, you can do it by setting setEnableLocationUpdates property to NO.\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"[[AdsNativeSDK sharedInstance] setEnableLocationUpdates:NO];\",\n      \"language\": \"objectivec\"\n    }\n  ]\n}\n[/block]\nYou may also choose to pass the location yourself.\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"ANAdRequestTargeting *targeting = [ANAdRequestTargeting targeting];\\ntargeting.location = yourCLLocationObject;\",\n      \"language\": \"objectivec\"\n    }\n  ]\n}\n[/block]\nNote: Make sure you pass this targeting object while calling the load ads method.\n[block:api-header]\n{\n  \"type\": \"basic\",\n  \"title\": \"Defining Ad Layouts\"\n}\n[/block]\nThis section details how to create and define your native ad layouts and the steps to render it onto your ad view. It also details what is, and how to use dynamic layout switching.\n\n**Create and define the layout for your ad**\n\nTo render your native ad onto a view, the view must be a subclass of UIView and conform to the ANAdRendering protocol.\n\nThe ANAdRendering protocol has one required method layoutAdAssets:. It is where the SDK returns a Native Ad object which is to be used to render the ad. A native ad contains the following assets.\n\n  * Title\n  * Text (Description)\n  * Call To Action Text\n  * Sponsored Text\n  * Icon Image URL\n  * Main Image URL\n  \nThe ANNativeAd object contains methods to render your native ad into the respective views. The following example details the same.\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"//SampleAdView.h\\n @interface SampleAdView : UIView <ANAdRendering>\\n\\n @property (strong, nonatomic) IBOutlet UILabel *titleLabel;\\n @property (strong, nonatomic) IBOutlet UILabel *mainTextLabel;\\n @property (strong, nonatomic) IBOutlet UIButton *callToActionButton;\\n @property (strong, nonatomic) IBOutlet UIImageView *iconImageView;\\n @property (strong, nonatomic) IBOutlet UIImageView *mainImageView;\\n @property (strong, nonatomic) IBOutlet UILabel *sponsoredText;\\n\\n//SampleAdView.m\\n @implementation SampleAdView\\n\\n ...\\n\\n - (void)layoutAdAssets:(ANNativeAd *)adObject\\n {\\n     [adObject loadTitleIntoLabel:self.titleLabel];\\n     [adObject loadTextIntoLabel:self.mainTextLabel];\\n     [adObject loadCallToActionTextIntoButton:self.callToActionButton];\\n     [adObject loadIconIntoImageView:self.iconImageView];\\n     [adObject loadSponsoredTagIntoLabel:self.sponsoredText];\\n     [adObject loadImageIntoImageView:self.mainImageView];\\n }\\n\\n //Optional Method: To be used in case you want to change the height of a table or collection view\\n + (CGSize)sizeWithMaximumWidth:(CGFloat)maximumWidth\\n {\\n     return CGSizeMake(maximumWidth, height);\\n }\\n\\n // Optional Method\\n // You MUST implement this method if SampleAdView uses a nib\\n + (NSString *)nibForAd\\n {\\n     return @\\\"SampleAdView\\\";\\n }\\n @end\",\n      \"language\": \"objectivec\"\n    }\n  ]\n}\n[/block]\nNOTE: The optional method sizeWithMaximumWidth for the ANAdRendering protocol are for TableView and CollectionView integrations. It should not be for single native ad integrations. A frame has to be separately set for Single Ad integrations.\n\n**Video Ads**\n\nAdsNative SDK supports showing video assets in-line with autoplay. To enable this you need to use **UIView** to define the asset, instead of **UIImageView**. Inline Video is usually shown in place of main image.\n\nCall to **loadImageIntoImageView** below\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"[adObject loadImageIntoImageView:self.mainImage];\",\n      \"language\": \"objectivec\"\n    }\n  ]\n}\n[/block]\nneeds to be replaced with **loadMediaIntoView**\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"[adObject loadMediaIntoView:self.mediaView]; // mediaView should be object of UIView\",\n      \"language\": \"objectivec\"\n    }\n  ]\n}\n[/block]\n**Dynamic Layout Switching**\n\nThe AdsNative SDK allows you to switch between different ad views (ad layouts) at runtime using the AdsNative dashboard.\n\nTo use dynamic layout switching, you need to create all the possible layouts that you may want to switch to in your application. The steps to create a layout (UIView subclass) have been detailed above.\n\nOnce you've created all your layout classes, you can switch between them by passing the rendering class name in the dashboard.\n\nImportant Note: For single native ad integrations, dynamic layout switching works only when you pass the renderingClass as param, i.e, it does not work if you decide to stitch the native ad assets on your own.\n\n**Backup Layouts**\n\nAdsNative SDK may sometimes serve ads without icon image. If you are using icon image in one of your layouts, it will be blank in such cases. To counter this, SDK has a feature built-in to fallback automatically into a backup layout (if defined). To make use of backup layouts, you need to define the UIView subclass that is your rendering view class with the same name as your original UIView subclass with \"Backup\" prefix added to it. For example, if your original view class is named as \"YourAdView\" then your backup layout should be named as \"BackupYourAdView\".\n\n**Integrating Other Networks**\n\n  * If you wish to add 3rd Party Ad Networks for mediation, [**click here**](https://dev.adsnative.com/v1.0/docs/ios-sdk-demand-partner-integration) to know how to do this.","excerpt":"","slug":"ios-sdk","type":"basic","title":"iOS SDK"}
Welcome to AdsNative iOS SDK wiki! Please check out the **Getting Started** section below before integrating your app with the SDK. [block:api-header] { "type": "basic", "title": "Getting Started" } [/block] This section details the process of including your iOS application with the AdsNative SDK along with setting up framework dependencies. The basic integration steps are as follows * Download the AdsNative SDK * Include the SDK into your xcode project and setup dependencies * Integrate one of the supported Native Ad formats **Download the AdsNative SDK** The AdsNative iOS SDK is distributed as a framework which you must download and incorporate into your xcode project. Click [**here**](https://github.com/picatcha/adsnative-sdk-ios/archive/master.zip) to download the AdsNative SDK. **Include the SDK into your xcode project and setup dependencies** The following instructions assume you've downloaded the AdsNativeSDK.framework which is to be included into your project. Drag the downloaded AdsNativeSDK.framework build into your Frameworks folder of the project (be sure to check the "Copy items into destination group's folder" option). If the Frameworks folder isn't present, create one by right clicking the project and selecting "New Group" with the name "Frameworks". Add the following frameworks to your project. To do this, click on your application's target, then click on Build Phases and expand the Link Binary With Libraries group. The AdsNative SDK requires you to add the following frameworks into your xcode project. * Foundation.framework * UIKit.framework * SystemConfiguration.framework * CoreLocation.framework * CoreGraphics.framework * AdSupport.framework (Optional) * StoreKit.framework (Optional) *The Optional frameworks are needed if you are targeting iOS versions below 6.0* **Integrate one of the supported Native Ad formats** AdsNative supports the following ad formats * [**Content Stream Ads**](http://dev.adsnative.com/docs/ios-sdk#content-stream-ad-placement) - These are ads that appear as a part of a content stream. For iOS, we support the UITableView and UICollectionView layouts. This is the recommended way of integrating with AdsNative, as it provides caching and image pre-loading out of the box. * [**Single Native Ad/Manual Integration**](http://dev.adsnative.com/docs/ios-sdk#standard-integration) - If you have a custom requirement or would like to stitch the native ad assets yourself, AdsNative SDK supports this by requesting a single native ad **Additional Configuration for iOS 9** One of the changes that have come in with iOS 9 is App Transport Security (ATS). ATS basically requires apps to make network connections only over SSL. This is the default behaviour for iOS 9 and currently the AdsNative SDK doesn't support this. To build apps against iOS 9, ATS needs to be disabled to ensure that the AdsNative SDK works correctly. To disable ATS, add the following to your app plist (info.plist) [block:code] { "codes": [ { "code": "<key>NSAppTransportSecurity</key>\n<dict>\n <key>NSAllowsArbitraryLoads</key>\n <true/>\n</dict>", "language": "xml" } ] } [/block] **Integrating Other Networks** If you wish to add other networks for mediation, [**click here**](http://dev.adsnative.com/docs/ios-sdk#integrating-other-networks) to know how to do this. [block:api-header] { "type": "basic", "title": "Content Stream Ad Placement" } [/block] The following section details the steps to be followed when placing ads in a content stream, i.e., either a UITableView or a UICollectionView. Native ad integration into a content stream can be completed in 3 steps. * Create and define the layout for your ad * Place and load ads into your content stream * Replace the UITableView and UICollectionView methods with its AdsNative ('an_') counterparts To know how to render native ad assets on a view, [**click here**](http://dev.adsnative.com/docs/ios-sdk#defining-ad-layouts). Load Ads into a content stream Depending on which type of stream you want to load native ads into, see one of the below links. * [**Table View Integration**](http://dev.adsnative.com/docs/ios-sdk#table-view-integration) * [**Collection View Integration**](http://dev.adsnative.com/docs/ios-sdk#collection-view-integration) [block:api-header] { "type": "basic", "title": "Table View Integration" } [/block] This section details how to place native ads into a table view using the AdsNative SDK. The AdsNative SDK handles image caching and metrics (impressions, clicks) tracking so all you have to do is figure out how, when, and where to display ads. **Prerequisites** Before going through this section, you'll need to go through the [**Getting Started**](http://dev.adsnative.com/docs/ios-sdk#getting-started) section followed by the [**Content Stream Ad Placement**](http://dev.adsnative.com/docs/ios-sdk#content-stream-ad-placement) section. **Place Ads in a Table View** The AdsNative SDK lets you place ads into a table view using the ANTableViewAdPlacer class. It handles requesting ads and placing ads into your table view class. When an instance of ANTableViewAdPlacer is initialised with a table view, it takes the table view's data source and delegate and wraps it in order to insert ads and adjust the positions of your regular content cells. In your UITableView class's view controller's viewDidLoad method 1. Specify Your Ad Positions and Ad Request Targeting information NOTE: This step is optional and may be ignored. Before making a native ad request, you need to tell the ANTableViewAdPlacer what type of ad positions you've opted for, i.e., server or client positions. If you've specified ad positions on the AdsNative UI, then initialise a server positions object. [block:code] { "codes": [ { "code": "ANServerAdPositions *serverAdPositions = \n\t\t\t\t\t\t\t\t\t\t[[ANServerAdPositions alloc] init];", "language": "objectivec" } ] } [/block] You may further choose to specify ad request targeting information. Check out [**Ad Positions**](http://dev.adsnative.com/docs/ios-sdk#ad-positions) and [**Ad Request Targeting**](http://dev.adsnative.com/docs/ios-sdk#ad-request-targeting), for more information. 2. Initialise an ANTableViewAdPlacer class An object of ANTableViewAdPlacer has to be created with the following params - * Table View: The UITableView class that you have to load ads into. * View Controller: The View Controller for the UITableView class (typically 'self'). * Ad Positions: The positions object which specifies whether client or server side ad positions are used. * defaultAdRenderingClass: The UIView subclass which implements the ANAdRendering protocol. This is the class into which Native Ad Assets will be rendered into. [block:code] { "codes": [ { "code": "self.placer = [ANTableViewAdPlacer placerWithTableView:self.tableView viewController:self adPositions:serverAdPositions defaultAdRenderingClass:[SampleAdView class]]; ", "language": "objectivec" } ] } [/block] Alternatively, if server positions is specified, you can ignore create a positions object and initialise your ANTableViewAdPlacer in the following manner. [block:code] { "codes": [ { "code": "self.placer = [ANTableViewAdPlacer placerWithTableView:self.tableView viewController:self defaultAdRenderingClass:[SampleAdView class]];", "language": "objectivec" } ] } [/block] 3. Load Ads For Your Table View The penultimate step is to call the loadAdsForAdUnitId of the ANTableViewAdPlacer using the newly created instance. This method requires a string which is the AdUnitId that you get while registering an account on our AdsNative dashboard. [block:code] { "codes": [ { "code": "[self.placer loadAdsForAdUnitID:@\"AdUnitId\"];", "language": "objectivec" } ] } [/block] 4. Replace UITableView methods with 'an_' counterparts In order to account for the ad placements in your table view, you have to replace UITableView method calls with their 'an_' counterparts. Everything else is handled by us. So, instead of: [block:code] { "codes": [ { "code": "[self.tableView selectRowAtIndexPath:myIndexPath];", "language": "objectivec" } ] } [/block] Use: [block:code] { "codes": [ { "code": "[self.tableView an_selectRowAtIndexPath:myIndexPath];", "language": "objectivec" } ] } [/block] All this does is make adjustments to the NSIndexPath to account for the ads in your stream. Important Note: Failing to make these replacements will lead to problems with your row positions be out of sync with your table view. All UITableView methods must be prefixed with 'an_' like shown in the example above. **Sample Code** [block:code] { "codes": [ { "code": "ANServerAdPositions *serverAdPositions = [[ANServerAdPositions alloc] init];\n\n//The defaultRenderingClass can be switched dynamically by specifying it in the AdsNative UI\nself.placer = [ANTableViewAdPlacer placerWithTableView:self.tableView viewController:self adPositions:serverAdPositions defaultAdRenderingClass:[SampleAdView class]];\n\n[self.placer loadAdsForAdUnitID:@\"AdUnitId\"];", "language": "objectivec" } ] } [/block] [block:api-header] { "type": "basic", "title": "Collection View Integration" } [/block] This section details how to place native ads into a collection view using the AdsNative SDK. The AdsNative SDK handles image caching and metrics (impressions, clicks) tracking so all you have to do is figure out how, when, and where to display ads. **Prerequisites** Before going through this section, you'll need to go through the [**Getting Started**](http://dev.adsnative.com/docs/ios-sdk#getting-started) section followed by the [**Content Stream Ad Placement**](http://dev.adsnative.com/docs/ios-sdk#content-stream-ad-placement) section. **Place Ads in a Collection View** The AdsNative SDK lets you place ads into a collection view using the ANCollectionViewAdPlacer class. It handles requesting ads and placing ads into your collection view class. When an instance of ANCollectionViewAdPlacer is initialised with a collection view, it takes the collection view's data source and delegate and wraps it in order to insert ads and adjust the positions of your regular content cells. In your UICollectionView feeds view controller's viewDidLoad method 1. Specify Your Ad Positions and Ad Request Targeting information NOTE: This step is optional and may be ignored. Before making a native ad request, you need to tell the ANCollectionViewAdPlacer what type of ad positions you've opted for, i.e., server or client positions. If you've specified ad positions on the AdsNative UI, then initialise a server positions object. [block:code] { "codes": [ { "code": "ANServerAdPositions *serverAdPositions = \n\t\t\t\t\t\t\t\t\t\t[[ANServerAdPositions alloc] init];", "language": "objectivec" } ] } [/block] You may further choose to specify ad request targeting information. Check out [**Ad Positions**](http://dev.adsnative.com/docs/ios-sdk#ad-positions) and [**Ad Request Targeting**](http://dev.adsnative.com/docs/ios-sdk#ad-request-targeting), for more information. 2. Initialise an ANCollectionViewAdPlacer class An object of ANCollectionViewAdPlacer has to be created with the following params * Collection View: The UICollectionView class that you have to load ads into. * View Controller: The View Controller for the UICollectionView class (typically 'self'). * Ad Positions: The positions object which specifies whether client or server side ad positions are used. * defaultAdRenderingClass: The UIView subclass which implements the ANAdRendering protocol. This is the class into which Native Ad Assets will be rendered into. [block:code] { "codes": [ { "code": "self.placer = [ANCollectionViewAdPlacer placerWithCollectionView:self.collectionView viewController:self adPositions:serverAdPositions defaultAdRenderingClass:[SampleAdView class]];", "language": "objectivec" } ] } [/block] Alternatively, if server positions is specified, you can ignore create a positions object and initialise your ANCollectionViewAdPlacer in the following manner. [block:code] { "codes": [ { "code": "self.placer = [ANCollectionViewAdPlacer placerWithCollectionView:self.collectionView viewController:self defaultAdRenderingClass:[SampleAdView class]];", "language": "objectivec" } ] } [/block] 3. Load Ads For Your Collection View The penultimate step is to call the loadAdsForAdUnitId of the ANCollectionViewAdPlacer using the newly created instance. This method requires a string which is the AdUnitId that you get while registering an account on our AdsNative dashboard. [block:code] { "codes": [ { "code": "[self.placer loadAdsForAdUnitID:@\"AdUnitId\"];", "language": "objectivec" } ] } [/block] 4. Replace UICollectionView methods with 'an_' counterparts In order to account for the ad placements in your collection view, you have to replace UICollectionView method calls with their 'an_' counterparts. Everything else is handled by us. So, instead of: [block:code] { "codes": [ { "code": "[self.collectionView selectItemAtIndexPath:myIndexPath];", "language": "objectivec" } ] } [/block] Use: [block:code] { "codes": [ { "code": "[self.collectionView an_selectItemAtIndexPath:myIndexPath];", "language": "objectivec" } ] } [/block] All this does is make adjustments to the NSIndexPath to account for the ads in your stream. Important Note: Failing to make these replacements will lead to problems with your row positions be out of sync with your collection view. All UICollectionView methods must be prefixed with 'an_' like shown in the example above. **Sample Code** [block:code] { "codes": [ { "code": "ANServerAdPositions *serverAdPositions = [[ANServerAdPositions alloc] init];\n\n//The defaultRenderingClass can be switched dynamically by specifying it in the AdsNative UI\nself.placer = [ANCollectionViewAdPlacer placerWithCollectionView:self.collectionView viewController:self adPositions:serverAdPositions defaultAdRenderingClass:[SampleAdView class]];\n\n[self.placer loadAdsForAdUnitID:@\"AdUnitId\"];", "language": "objectivec" } ] } [/block] [block:api-header] { "type": "basic", "title": "Standard Integration" } [/block] This section details how to request and load a single native ad using the AdsNative SDK. If you plan to load native ads into a UITableView or a UICollectionView, we recommend following Table View Integration or Collection View Integration. **Prerequisites** Before going through this section, you'll need to go through the [**Getting Started**](http://dev.adsnative.com/docs/ios-sdk#getting-started) section. **Load A Single Native Ad** In your View Controllers viewDidLoad method 1. Create and instance of ANNativeAd You need to create an instance of ANNativeAd with the AdUnitId obtained after creating an account on the AdsNative UI. [block:code] { "codes": [ { "code": "ANNativeAd *nativeAd = [[ANNativeAd alloc] initWithAdUnitId:@\"ADIDUNIT\"];\nnativeAd.delegate = self;", "language": "objectivec" } ] } [/block] 2. Request for a Native Ad Request the AdsNative SDK for a native ad instance by calling its loadAd method [block:code] { "codes": [ { "code": "[nativeAd loadAd];", "language": "objectivec" } ] } [/block] 3. Implement the delegate methods A delegate of ANNativeAd will have to implement the following methods Required methods [block:code] { "codes": [ { "code": "- (void)nativeAdDidLoad:(ANNativeAd *)nativeAd;\n- (void)nativeAd:(ANNativeAd *)nativeAd didFailWithError:(NSError *)error;", "language": "objectivec" } ] } [/block] Optional methods [block:code] { "codes": [ { "code": "- (void)nativeAdDidRecordImpression;\n- (void)nativeAdDidClick;", "language": "objectivec" } ] } [/block] 4. Render Native Ad in the nativeAdDidLoad: method Once your native ad is loaded, you have to render it into a view. The AdsNative SDK allows you to do this in one of two ways. 1. Create And Define your Ad Rendering Layout (Recommended) Create a UIView subclass the conforms to the ANAdRendering protocol. Click here for details on how to do this. Create an adView by calling the following method [block:code] { "codes": [ { "code": "UIView * adView = [nativeAd renderNativeAdWithController:self defaultRenderingClass:[YourAdView class]];", "language": "objectivec" } ] } [/block] Add the view to your parent view container [block:code] { "codes": [ { "code": "[self.adViewContainer addSubview:adView];", "language": "objectivec" } ] } [/block] **Sample Code** [block:code] { "codes": [ { "code": "- (void)nativeAdDidLoad:(ANNativeAd *)nativeAd {\nUIView * adView = [nativeAd renderNativeAdWithController:self defaultRenderingClass:[NativeAdView class]];\n\n[adView setFrame:self.adViewContainer.frame];\n\n[self.adViewContainer addSubview:adView];\n}", "language": "objectivec" } ] } [/block] 2. Stitch your ad view yourself The AdsNative SDK allows you to stitch your ad view by yourself. You can retrieve individual native ad assets by using the nativeAssets property of the ANNative Ad object. It is a dictionary of ad assets with the following keys. * kNativeTitleKey - The Native Ad Title * kNativeTextKey - The Native Ad Text (or description) * kNativeIconImageKey - The Icon Image Url as string * kNativeMainImageKey - The Main (or Cover) Image Url as string * kNativeCTATextKey - The Click Through Action Text * kNativeStarRatingKey - The ad star rating For example, to get the native ad title [block:code] { "codes": [ { "code": "NSString *adTitle = [nativeAd.nativeAssets objectForKey:kNativeCTATitleKey];", "language": "objectivec" } ] } [/block] Once you've created your ad view, you need to register that view with the AdsNative SDK for metrics tracking. [block:code] { "codes": [ { "code": "[nativeAd registerNativeAdWithController:self forView:adView];", "language": "objectivec" } ] } [/block] **Sample Code** [block:code] { "codes": [ { "code": "- (void)nativeAdDidLoad:(ANNativeAd *)nativeAd {\nUIView *adView = [[UIView alloc] init];\n\n//Create subviews for adView and add it to adView\n...\n//Set the adView frame\n[adView setFrame:self.adViewContainer.frame];\n\n//Register ad view for clicks and impression tracking\n[nativeAd registerNativeAdWithController:self forView:adView];\n\n[self.adViewContainer addSubview:adView];\n}", "language": "objectivec" } ] } [/block] [block:api-header] { "type": "basic", "title": "Ad Positions" } [/block] Ad positions are basically placement for your ads in a content stream (be it a table view or a collection view). The AdsNative SDK requires two values for ad positioning into a content stream - the set of fixed positions where an ad should appear, and a repeating interval of ads which repeats after the last given fixed position. There are two ways to define ad positions. **1. Dynamically through the AdsNative UI (Server Positions) - Recommended** The AdsNative SDK fetches the positioning information that has been setup on the AdsNative UI. This approach of setting ad positions is recommended as you can change the ad positioning anytime on the UI without having to update your application. No extra integration steps need to be followed for this. This is the default ad positioning that the SDK adopts. **2. Hard code positions into your app (Client Positions)** If you choose to hardcode the position of the ads in your stream, you can do so by specifying ad positions in your application. Create an ANClientPositions object. [block:code] { "codes": [ { "code": "ANClientAdPositions *positions = [ANClientAdPositions positioning];", "language": "objectivec" } ] } [/block] Specify the fixed positions that you want your ads to appear. This is optional. [block:code] { "codes": [ { "code": "[positions addFixedIndexPath:[NSIndexPath indexPathForRow:1 inSection:0]];", "language": "objectivec" } ] } [/block] Specify the repeating interval for the ads. The repeating interval must be greater than 1. [block:code] { "codes": [ { "code": "[positions enableRepeatingPositionsWithInterval:5];", "language": "objectivec" } ] } [/block] Note that the repeating interval starts loading ads only after the last fixed position ad. [block:api-header] { "type": "basic", "title": "Ad Request Targeting" } [/block] **Keywords** *(Applicable only for direct sales campaigns)* While requesting for a native ad, you can pass keywords based on which your ad request can be processed. Keywords are typically used to target ad campaigns at specific user segments. They should be formatted as an array of strings (e.g. of keywords -"social","music"). [block:code] { "codes": [ { "code": "ANAdRequestTargeting *targeting = [ANAdRequestTargeting targeting];\nNSMutableArray *keywords = [[NSMutableArray alloc] init];\n[keywords addObject:@\"social\"];\n[keywords addObject:@\"music\"];\ntargeting.keywords = keywords;", "language": "objectivec" } ] } [/block] Note: Make sure you pass this targeting object while calling the load ads method. **Location** The AdsNative SDK automatically fetches the users location for better targeted ads. The location is not fetched if the user has not authorised the app for location services. If you, however, wish to disallow AdsNative SDK to fetch location, you can do it by setting setEnableLocationUpdates property to NO. [block:code] { "codes": [ { "code": "[[AdsNativeSDK sharedInstance] setEnableLocationUpdates:NO];", "language": "objectivec" } ] } [/block] You may also choose to pass the location yourself. [block:code] { "codes": [ { "code": "ANAdRequestTargeting *targeting = [ANAdRequestTargeting targeting];\ntargeting.location = yourCLLocationObject;", "language": "objectivec" } ] } [/block] Note: Make sure you pass this targeting object while calling the load ads method. [block:api-header] { "type": "basic", "title": "Defining Ad Layouts" } [/block] This section details how to create and define your native ad layouts and the steps to render it onto your ad view. It also details what is, and how to use dynamic layout switching. **Create and define the layout for your ad** To render your native ad onto a view, the view must be a subclass of UIView and conform to the ANAdRendering protocol. The ANAdRendering protocol has one required method layoutAdAssets:. It is where the SDK returns a Native Ad object which is to be used to render the ad. A native ad contains the following assets. * Title * Text (Description) * Call To Action Text * Sponsored Text * Icon Image URL * Main Image URL The ANNativeAd object contains methods to render your native ad into the respective views. The following example details the same. [block:code] { "codes": [ { "code": "//SampleAdView.h\n @interface SampleAdView : UIView <ANAdRendering>\n\n @property (strong, nonatomic) IBOutlet UILabel *titleLabel;\n @property (strong, nonatomic) IBOutlet UILabel *mainTextLabel;\n @property (strong, nonatomic) IBOutlet UIButton *callToActionButton;\n @property (strong, nonatomic) IBOutlet UIImageView *iconImageView;\n @property (strong, nonatomic) IBOutlet UIImageView *mainImageView;\n @property (strong, nonatomic) IBOutlet UILabel *sponsoredText;\n\n//SampleAdView.m\n @implementation SampleAdView\n\n ...\n\n - (void)layoutAdAssets:(ANNativeAd *)adObject\n {\n [adObject loadTitleIntoLabel:self.titleLabel];\n [adObject loadTextIntoLabel:self.mainTextLabel];\n [adObject loadCallToActionTextIntoButton:self.callToActionButton];\n [adObject loadIconIntoImageView:self.iconImageView];\n [adObject loadSponsoredTagIntoLabel:self.sponsoredText];\n [adObject loadImageIntoImageView:self.mainImageView];\n }\n\n //Optional Method: To be used in case you want to change the height of a table or collection view\n + (CGSize)sizeWithMaximumWidth:(CGFloat)maximumWidth\n {\n return CGSizeMake(maximumWidth, height);\n }\n\n // Optional Method\n // You MUST implement this method if SampleAdView uses a nib\n + (NSString *)nibForAd\n {\n return @\"SampleAdView\";\n }\n @end", "language": "objectivec" } ] } [/block] NOTE: The optional method sizeWithMaximumWidth for the ANAdRendering protocol are for TableView and CollectionView integrations. It should not be for single native ad integrations. A frame has to be separately set for Single Ad integrations. **Video Ads** AdsNative SDK supports showing video assets in-line with autoplay. To enable this you need to use **UIView** to define the asset, instead of **UIImageView**. Inline Video is usually shown in place of main image. Call to **loadImageIntoImageView** below [block:code] { "codes": [ { "code": "[adObject loadImageIntoImageView:self.mainImage];", "language": "objectivec" } ] } [/block] needs to be replaced with **loadMediaIntoView** [block:code] { "codes": [ { "code": "[adObject loadMediaIntoView:self.mediaView]; // mediaView should be object of UIView", "language": "objectivec" } ] } [/block] **Dynamic Layout Switching** The AdsNative SDK allows you to switch between different ad views (ad layouts) at runtime using the AdsNative dashboard. To use dynamic layout switching, you need to create all the possible layouts that you may want to switch to in your application. The steps to create a layout (UIView subclass) have been detailed above. Once you've created all your layout classes, you can switch between them by passing the rendering class name in the dashboard. Important Note: For single native ad integrations, dynamic layout switching works only when you pass the renderingClass as param, i.e, it does not work if you decide to stitch the native ad assets on your own. **Backup Layouts** AdsNative SDK may sometimes serve ads without icon image. If you are using icon image in one of your layouts, it will be blank in such cases. To counter this, SDK has a feature built-in to fallback automatically into a backup layout (if defined). To make use of backup layouts, you need to define the UIView subclass that is your rendering view class with the same name as your original UIView subclass with "Backup" prefix added to it. For example, if your original view class is named as "YourAdView" then your backup layout should be named as "BackupYourAdView". **Integrating Other Networks** * If you wish to add 3rd Party Ad Networks for mediation, [**click here**](https://dev.adsnative.com/v1.0/docs/ios-sdk-demand-partner-integration) to know how to do this.