NativeAdView
utilise FBMediaView
pour créer une annonce. Maintenant, dans votre View Controller tête de fichier déclarer protocole FBNativeAdDelegate ainsi que Déclarez et connecter les variables d'instance à votre .XIB UI:
@import FBAudienceNetwork; // import Audience Network module
@interface MyViewController : UIViewController <FBNativeAdDelegate>
// Other code might go here...
@property (weak, nonatomic) IBOutlet UIImageView *adIconImageView;
@property (weak, nonatomic) IBOutlet UILabel *adTitleLabel;
@property (weak, nonatomic) IBOutlet UILabel *adBodyLabel;
@property (weak, nonatomic) IBOutlet UIButton *adCallToActionButton;
@property (weak, nonatomic) IBOutlet UILabel *adSocialContextLabel;
@property (weak, nonatomic) IBOutlet UILabel *sponsoredLabel;
@property (weak, nonatomic) FBMediaView *adCoverMediaView;
@property (weak, nonatomic) IBOutlet UIView *adView;
@end
Ensuite, ajoutez une méthode dans votre fichier de mise en œuvre de View Controller initialisant FBNativeAd
et demander une annonce à charger:
FBNativeAd *nativeAd;
FBAdchoicesView *adChoicesView;
- (void)showNativeAd
{
nativeAd = [[FBNativeAd alloc] initWithPlacementID:@"YOUR_PLACEMENT_ID"];
nativeAd.delegate = self;
[nativeAd loadAd];
}
maintenant que vous avez ajouté le code pour charger l'annonce, ajouter les fonctions suivantes pour gérer les échecs de chargement et de construire l'annonce une fois qu'il a chargé:
- (void)nativeAdDidLoad:(FBNativeAd *)nativeAd
{
[self.adTitleLabel setText:nativeAd.title];
[self.adBodyLabel setText:nativeAd.body];
[self.SocialContextLabel setText:nativeAd.socialContext];
[self.sponsoredLabel setText:@”Sponsored”];
[self.adCallToActionButton setTitle:nativeAd.callToAction];
[nativeAd.icon loadImageAsyncWithBlock:^(UIImage *image) {
[self.adIconImageView setImage:image];
}];
// Allocate a FBMediaView to contain the cover image or native video asset
adCoverMediaView = [[FBMediaView alloc] initWithFrame:coverFrame]];
[adCoverMediaView setNativeAd:nativeAd];
// Add adChoicesView
adChoicesView = [[FBAdChoicesView alloc] initWithNativeAd:nativeAd];
[adView addSubview:adChoicesView];
[adChoicesView updateFrameFromSuperview];
// Register the native ad view and its view controller with the native ad instance
[nativeAd registerViewForInteraction:adView withViewController:self];
}
- (void)nativeAd:(FBNativeAd *)nativeAd didFailWithError:(NSError *)error
{
NSLog(@"Ad failed to load with error: %@", error);
}
Pour afficher l'image de couverture de l'annonce native, il est recommandé d'utiliser le MediaView de réseau d'audience Facebook, qui peut afficher à la fois des ressources d'image et de vidéo.
Référence: https://developers.facebook.com/docs/audience-network/ios/native-api
Comment est que cela répond à ma question? J'ai déjà mis en place tout ça. Comment réparer l'interface utilisateur bloquée? – Luda
vous n'avez pas mentionné ce qui est la question que vous ayez selon vos informations à condition que vous pouvez le faire comme 'dispatch_async (dispatch_get_global_queue (DISPATCH_QUEUE_PRIORITY_DEFAULT, 0),^(void) { // travail de fond dispatch_async (dispatch_get_main_queue(),^(vide) { // Travail de thread principal (interface utilisateur généralement) adMediaView.nativeAd = nativeAd }); }); ' –
J'ai essayé ça. N'a pas fonctionné. Avez-vous exécuté votre code sur un appareil? N'avez-vous pas d'interface utilisateur en retard? – Luda