// Import the SDK header file and declare that you are implementing
// the FBNativeAdDelegate protocol:
#import <FBAudienceNetwork/FBAudienceNetwork.h>
@interface MyViewController : UIViewController <FBNativeAdDelegate>
// Other code might go here...
@end
// Add a function in your View Controller that initializes the FBNAtiveAd
// and request an ad to load:
- (void)showNativeAd
{
FBNativeAd *nativeAd =
[[FBNativeAd alloc] initWithPlacementID:@"841988475951113_841992455950715"];
nativeAd.delegate = self;
[nativeAd loadAd];
}
// Now that you have added the code to load the ad, add the following
// functions to handle loading failures and to construct the ad once
// it has loaded:
- (void)nativeAdDidLoad:(FBNativeAd *)nativeAd
{
NSString *titleForAd = nativeAd.title;
NSString *bodyTextForAd = nativeAd.body;
FBAdImage *coverImage = nativeAd.coverImage;
FBAdImage *iconForAd = nativeAd.icon;
NSString *socialContextForAd = nativeAd.socialContext;
struct FBAdStarRating appRatingForAd = nativeAd.starRating;
NSString *titleForAdButton = nativeAd.callToAction;
// Add code here to create a custom UIView that uses the ad properties
// For example:
UIView *nativeAdView = [[UIView alloc]initWithFrame:adFrame];
UILabel *titleLabel = [[UILabel alloc] initWithFrame:titleFrame];
titleLabel.text = titleForAd;
[nativeAdView addSubview:titleLabel];
...
// Add the ad to the view hierarchy
[self.view addSubview:nativeAdView];
// Register the native ad view and its view controller with the
// native ad instance
[nativeAd registerViewForInteraction:nativeAdView withViewController:self];
}
- (void)nativeAd:(FBNativeAd *)nativeAd didFailWithError:(NSError *)error
{
NSLog(@"Ad failed to load with error: %@", error);
}
// the FBNativeAdDelegate protocol:
#import <FBAudienceNetwork/FBAudienceNetwork.h>
@interface MyViewController : UIViewController <FBNativeAdDelegate>
// Other code might go here...
@end
// Add a function in your View Controller that initializes the FBNAtiveAd
// and request an ad to load:
- (void)showNativeAd
{
FBNativeAd *nativeAd =
[[FBNativeAd alloc] initWithPlacementID:@"841988475951113_841992455950715"];
nativeAd.delegate = self;
[nativeAd loadAd];
}
// Now that you have added the code to load the ad, add the following
// functions to handle loading failures and to construct the ad once
// it has loaded:
- (void)nativeAdDidLoad:(FBNativeAd *)nativeAd
{
NSString *titleForAd = nativeAd.title;
NSString *bodyTextForAd = nativeAd.body;
FBAdImage *coverImage = nativeAd.coverImage;
FBAdImage *iconForAd = nativeAd.icon;
NSString *socialContextForAd = nativeAd.socialContext;
struct FBAdStarRating appRatingForAd = nativeAd.starRating;
NSString *titleForAdButton = nativeAd.callToAction;
// Add code here to create a custom UIView that uses the ad properties
// For example:
UIView *nativeAdView = [[UIView alloc]initWithFrame:adFrame];
UILabel *titleLabel = [[UILabel alloc] initWithFrame:titleFrame];
titleLabel.text = titleForAd;
[nativeAdView addSubview:titleLabel];
...
// Add the ad to the view hierarchy
[self.view addSubview:nativeAdView];
// Register the native ad view and its view controller with the
// native ad instance
[nativeAd registerViewForInteraction:nativeAdView withViewController:self];
}
- (void)nativeAd:(FBNativeAd *)nativeAd didFailWithError:(NSError *)error
{
NSLog(@"Ad failed to load with error: %@", error);
}