Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-19626] Add FB Audience Network Support to Facebook Module

GitHub Issuen/a
TypeNew Feature
PriorityLow
StatusClosed
ResolutionWon't Fix
Resolution Date2018-01-23T13:58:52.000+0000
Affected Version/sn/a
Fix Version/sn/a
Componentsn/a
Labelsads, android, facebook, ios, module, titanium
ReporterGhassan
AssigneeUnknown
Created2015-05-21T01:28:02.000+0000
Updated2018-08-02T22:20:02.000+0000

Description

Current Facebook Module missing support for FB Audience Network for iOS and Android as indicated on facebook at: https://developers.facebook.com/docs/audience-network/getting-started#ads_sdk

Comments

  1. Ghassan 2015-05-27

    Facebook iOS Banner Instructions: // Import the SDK header file and declare that you are implementing // the FBAdViewDelegate protocol: #import @interface MyViewController : UIViewController // Other code might go here... @end // In your View Controller, create a new instance of the FBAdView // and add it to your view hierarchy: - (void)viewDidLoad { [super viewDidLoad]; FBAdView *adView = [[FBAdView alloc] initWithPlacementID:@"347360645445128_445223535658838" adSize:kFBAdSize320x50 rootViewController:self]; adView.delegate = self; [adView loadAd]; // Reposition the adView // ... [self.view addSubview:adView]; } // Now that you have the basic code running, it is recommended that you use // the FBAdView delegate to get notified when the ad fails to load so you // could hide the banner unit. In the same way, you can add it back when it // was loaded: - (void)adView:(FBAdView *)adView didFailWithError:(NSError *)error; { NSLog(@"Ad failed to load"); // Add code to hide the ad unit... // E.g. adView.hidden = YES; } - (void)adViewDidLoad:(FBAdView *)adView; { NSLog(@"Ad was loaded and ready to be displayed"); // Add code to show the ad unit... // E.g. adView.hidden = NO; }
  2. Ghassan 2015-05-27

    Facebook iOS Interstitial: // Import the SDK header file and declare that you are implementing // the FBInterstitialAdDelegate protocol: #import @interface MyViewController : UIViewController // Other code might go here... @end // Add a function in your View Controller that initializes the interstitialAd: - (void)loadInterstitial { FBInterstitialAd *interstitialAd = [[FBInterstitialAd alloc] initWithPlacementID:@"347360645445128_445223535658838"]; interstitialAd.delegate = self; [interstitialAd loadAd]; } // Now that you have added the code to load the ad, add the following functions // to display the ad once it is loaded and to handle loading failures: - (void)interstitialAdDidLoad:(FBInterstitialAd *)interstitialAd { NSLog(@"Interstitial ad is loaded and ready to be displayed"); // You can now display the full screen ad using this code: [interstitialAd showAdFromRootViewController:self]; } - (void)interstitialAd:(FBInterstitialAd *)interstitialAd didFailWithError:(NSError *)error { NSLog(@"Interstitial ad is failed to load with error: %@", error); }
  3. Ghassan 2015-05-27

    FB iOS Native Placement: // Import the SDK header file and declare that you are implementing // the FBNativeAdDelegate protocol: #import @interface MyViewController : UIViewController // 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:@"347360645445128_445223535658838"]; 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 hirarchy [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); }
  4. Ghassan 2015-05-27

    FB Android Banner: // Edit your activity's layout XML file to include a // RelativeLayout to contain the AdView: http://schemas.android.com/apk/res/android" android:orientation="vertical" > ... // In your activity's onCreate function, construct the AdView, // add to the container view and load the ad: private AdView adView; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); ... RelativeLayout adViewContainer = (RelativeLayout) findViewById(R.id.adViewContainer); adView = new AdView(this, "347360645445128_445223535658838", AdSize.BANNER_320_50); adViewContainer.addView(adView); adView.loadAd(); }
  5. Ghassan 2015-05-27

    FB Android Interstitial: // Declare the InterstitialActivity in AndroidManifest.xml: // // In the Activity that will launch the interstitial, // implement the AdListener interface and add the following: import com.facebook.ads.*; private InterstitialAd interstitialAd; private void loadInterstitialAd() { interstitialAd = new InterstitialAd(this, "347360645445128_445223535658838"); interstitialAd.setAdListener(this); interstitialAd.loadAd(); } @Override public void onError(Ad ad, AdError error) { // Ad failed to load } @Override public void onAdLoaded(Ad ad) { // Ad is loaded and ready to be displayed // You can now display the full screen add using this code: interstitialAd.show(); }
  6. Ghassan 2015-05-27

    FB Android Native Placement: // In the Activity that will launch the native ad, // implement the AdListener interface and add the following: import com.facebook.ads.*; private NativeAd nativeAd; private void showNativeAd(){ nativeAd = new NativeAd(this, "347360645445128_445223535658838"); nativeAd.setAdListener(new AdListener() { @Override public void onError(Ad ad, AdError error) { ... } @Override public void onAdLoaded(Ad ad) { ... } @Override public void onAdClicked(Ad ad) { ... } }); nativeAd.loadAd(); } // The next step is to extract the ad metadata and use its properties // to build your customized native UI. Modify the onAdLoaded function // above to retrieve the ad properties. For example: @Override public void onAdLoaded(Ad ad) { if (ad != nativeAd) { return; } String titleForAd = nativeAd.getAdTitle(); Image coverImage = nativeAd.getAdCoverImage(); Image iconForAd = nativeAd.getAdIcon(); String socialContextForAd = nativeAd.getAdSocialContext(); String titleForAdButton = nativeAd.getAdCallToAction(); String textForAdBody = nativeAd.getAdBody(); Rating appRatingForAd = nativeAd.getAdStarRating(); // Add code here to create a custom view that uses the ad properties // For example: LinearLayout nativeAdContainer = new LinearLayout(this); TextView titleLabel = new TextView(this); titleLabel.setText(titleForAd); nativeAdContainer.addView(titleLabel); ... // Add the ad to your layout LinearLayout mainContainer = (LinearLayout)findViewById(R.id.MainContainer); mainContainer.addView(nativeAdContainer); // Register the native ad view with the native ad instance nativeAd.registerViewForInteraction(nativeAdContainer); }
  7. Guillermo Figueras 2017-09-21

    Is there any plan on implementing this? It would be a good thing to have the possibility to include other ad networks besides Admob.
  8. Eric Merriman 2017-10-30

    Yes, we'd like to support this, but when is the real issue. This will have to move to after 7.0.0 SDK, so this will be the first for 7.1.0.
  9. Hans Knöchel 2018-01-23

    After checking some general requirements of this effort, I would recommend to *not* making it part of Ti.Facebook - simply because the .framework takes 60+ MB space and will blow up the app size even when not used. Instead, here is a simple implementation for Hyperloop using Cocoapods that does the same thing but only if you need it:

    Add pod 'FBAudienceNetwork' to your Podfile

    Import the framework

       var FBInterstitialAd = require('FBAudienceNetwork/FBInterstitialAd');
       

    Load the ad (taken as an example from [the official docs](https://developers.facebook.com/docs/audience-network/ios-interstitial))

       var ad = FBInterstitialAd.alloc(). initWithPlacementID('YOUR_PLACEMENT_ID');
       ad.delegate = yourDelegate;
       ad.loadAd();
       
  10. Eric Merriman 2018-08-02

    Closing old "Won't fix" tickets. If you disagree, please reopen.

JSON Source