Giter Site home page Giter Site logo

googleads-mobile-ios-examples's Introduction

Google Mobile Ads SDK for iOS

Build status

The Google Mobile Ads SDK is the latest generation in Google mobile advertising, featuring refined ad formats and streamlined APIs for access to mobile ad networks and advertising solutions. The SDK enables mobile app developers to maximize their monetization in native mobile apps.

This repository contains open source examples and developer resources for both the Google AdMob and Google AdManager components of the Google Mobile Ads SDK.

Google Mobile Ads SDK Developers forum

To report SDK feature requests, bugs, and crashes or to browse SDK-related discusssions, please use our Google Mobile Ads SDK Developers forum. The forum provides the latest SDK announcements and updates as well as technical SDK support for our iOS developers.

Documentation

Check out our developers site for documentation on using the Mobile Ads SDK.

Examples

Each iOS example app includes a Podfile and a Podfile.lock. The Podfile.lock tracks the version of each Pod specified in the Podfile that was used to build the release of the iOS example apps.

  1. Run pod install in the same directory as the Podfile.
  2. [Optional] Run pod update to get the latest version of the SDK.
  3. Open the .xcworkspace file with Xcode and run the app.

See the CocoaPods Guides for more information on installing and updating pods.

Swift

AdMob

Advanced

  • API Demo - Provides additional examples for both AdMob and Ad Manager to help improve your mobile app integration of the Google Mobile Ads SDK.
  • Inline Adaptive Banner Example - Provides an example for displaying ads from AdMob Banners in a UITableView.
  • SwiftUI Demo - Provides an examples for displaying ads from AdMob in a SwiftUI project.

AdManager

Objective-C

AdMob

Advanced

  • API Demo
    • Provides additional examples for both AdMob and Ad Manager to help improve your mobile app integration of the Google Mobile Ads SDK.
  • Inline Adaptive Banner Example
    • Provides an example for displaying ads from AdMob Banners in a UITableView.

AdManager

Downloads

Please check out our releases for the latest downloads of our example apps.

GitHub issue tracker

To file bugs, make feature requests, or suggest improvements for the iOS example apps, please use GitHub's issue tracker.

For SDK support issues, please use the Google Mobile Ads SDK Developers forum.

License

Apache 2.0 License

googleads-mobile-ios-examples's People

Contributors

amyquispe avatar ericleich avatar jillsong avatar maddevrelgithubbot avatar mihailogazda avatar rajpara avatar rampara avatar redbrogdon avatar stowy avatar ykws avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

googleads-mobile-ios-examples's Issues

ObjC rewardedVideoAd example Depreciated

The rewarded video ad objective-c example uses a UIAlertView to notify the user when the video add is not ready. However that was depreciated in iOS 8. UIAlertController should be used instead for iOS 8+.

Module GoogleMobileAds not found

I probably missed something basic but out of the box, "Module GoogleMobileAds not found" error comes up.
(doh, pod... sorry my mistake. I just don't ever liked pod)

Can compile swift test project

GADInterstitialDelegate: use of undeclared type"GDAIntertitial Delegate"

First I do a pod install but I can build the project.

I'm in Xcode 7.3.1

Getting Below issues after run the app

Cannot find an ad network adapter with the name(s): (
"com.google.DummyAdapter"
). Remember to link all required ad network adapters and SDKs, and set -ObjC in the 'Other Linker Flags' setting of your build target.

ad is never ready

i have this game and i created 3 funcions in my gameviewcontroller and here they are
func getInterstitialAd(){
interstitial = GADInterstitial(adUnitID: "ca-app-pub-1782852253088296/5018877964")
let requestInterstitial = GADRequest()
interstitial.load(requestInterstitial)
}

func showAd() {
    
    if (interstitial.isReady == true){
        interstitial.present(fromRootViewController: GameViewController())
    }else{
        print("ad wasn't ready")
        interstitial = createAd()
    }
    
    
    
}

func createAd() -> GADInterstitial{
    let interstital = GADInterstitial(adUnitID: "ca-app-pub-1782852253088296/5018877964")
    interstitial.load(GADRequest())
    return interstital
}

and in one of my scene called StartMenu , i call those function
var viewController: GameViewController!

and then i call the functions

       viewController.getInterstitialAd()
        viewController.showAd()

but it always returns ad not ready , and false for interstitial.isReady,
but also the getInterstitial function is always called .

can someone help with that please

No interstitial ad to show (Ad unit id example taken from documentation)

I have a hard time integrating AdMob with existing project - receiving No ad to show. all the time.
However, when I create a new project I have no problems with retrieving ads with the same code.

My main project includes Google Analytics pod, I commented out it's setup with no success.
On both existing and new project ATS is disabled.

I've tried setting IS_ADS_ENABLED to YES for analytics but then it shows an error that I have to include Google/Ads in the pods file which results with target has frameworks with conflicting names: GoogleMobileAds.
When I comment out Google-Mobile-Ads-SDK and leave Google/Ads I get build errors.

Both projects are with target iOS >= 8.0 + Swift.

class AdViewController: UIViewController {
    private var interstitial: GADInterstitial!

    override func viewDidLoad() {
        super.viewDidLoad()
        interstitial = GADInterstitial(adUnitID: "ca-app-pub-3940256099942544/4411468910")

        let request = GADRequest()
        // Requests test ads on test devices.
        request.testDevices = ["eade18b6188d6fe8214f399759097686"]

        interstitial.delegate = self
        interstitial.loadRequest(request)
    }
}

extension AdViewController: GADInterstitialDelegate {
    /// Called when an interstitial ad request succeeded.
    func interstitialDidReceiveAd(ad: GADInterstitial!) {
        print("interstitialDidReceiveAd")
    }

    /// Called when an interstitial ad request failed.
    func interstitial(ad: GADInterstitial!, didFailToReceiveAdWithError error: GADRequestError!) {
        print("interstitial:didFailToReceiveAdWithError: \(error.localizedDescription)")
    }

    /// Called just before presenting an interstitial.
    func interstitialWillPresentScreen(ad: GADInterstitial!) {
        print("interstitialWillPresentScreen")
    }

    /// Called before the interstitial is to be animated off the screen.
    func interstitialWillDismissScreen(ad: GADInterstitial!) {
        print("interstitialWillDismissScreen")
    }

    /// Called just after dismissing an interstitial and it has animated off the screen.
    func interstitialDidDismissScreen(ad: GADInterstitial!) {
        print("interstitialDidDismissScreen")
    }

    /// Called just before the application will background or terminate because the user clicked on an
    /// ad that will launch another app (such as the App Store).
    func interstitialWillLeaveApplication(ad: GADInterstitial!) {
        print("interstitialWillLeaveApplication")
    }
}

Rewarded Video - Let server know about reward

Hi,

I'm implementing rewarded videos on my app and I want to let server know about the reward.

How can I get an unique identifier of the reward? Or do you recommend any other safe option?

Thank you,
Mário

Undefined symbols for architecture armv7

i have updated admob library to version 6.12, how to solve this error

Undefined symbols for architecture armv7:
"OBJC_CLASS$_EKEvent", referenced from:
objc-class-ref in libGoogleAdMobAds.a(GADOpener.o)
"OBJC_CLASS$_EKEventEditViewController", referenced from:
objc-class-ref in libGoogleAdMobAds.a(GADOpener.o)
ld: symbol(s) not found for architecture armv7
clang: error: linker command failed with exit code 1 (use -v to see invocation)

How to enable location services

Hello,

I have some difficulties with enabling location services in SDK. I don't have any option to Allow user location or ask to allow for when I check possible permissions in settings for this app. I tried with adding location-services in Info.plist file like it is mentioned on https://developer.apple.com/library/ios/documentation/UserExperience/Conceptual/LocationAwarenessPG/CoreLocation/CoreLocation.html but it didn't work for me. Do you have any additional info how to include option to share location.

Thanks

two rewardVideo problems

hello!

we encountered 2 problems while testing admob reward ads.

  1. sometimes a non-reward-video-ad is served
    https://github.com/cngamegirl/cngamegirl.github.io/blob/master/admobbug.chls.zip

  2. we always preload ads and check availability before presenting it, but sometimes the video just pause/freeze. i suspect the ads is not fully cached when it's ready to show?????
    we encounter this problem on interstitial video ads too, the count-down number stops counting and then disappear when time is up

Swift + Cocoapods + use_frameworks!

Has anyone found a clever way to install the Google Ads SDK in a swift app that uses use_frameworks! in the Podfile?

Bumping up against this issue: CocoaPods/CocoaPods#3267

Where my error is:

[!] The 'Pods-PROJECTNAME' target has transitive dependencies that include static binaries: (/Users/tim.kelly/code//Example/PROJECTNAME/Pods/Google-Mobile-Ads-SDK/GoogleMobileAdsSdkiOS-7.6.0/GoogleMobileAds.framework)

library not found for -lGoogleToolboxForMac

After installing pods build is failed with error

ld: library not found for -lGoogleToolboxForMac
clang: error: linker command failed with exit code 1 (use -v to see invocation)

Using cocoapods-1.2.0.beta.1 (cocoapods-1.1.1 fails to generate pods project when installing pods)

interstitial:didFailToReceiveAdWithError not called

Steps to reproduce.

Download repo.
Run "pod install"
Open "DFPInterstitialExample.xcworkspace" and put a breakpoint in

interstitial:didFailToReceiveAdWithError

Connect a device in "Airplane mode" and run the demo

The interstitial:interstitial:didFailToReceiveAdWithError: is never called.

Expected behavior:
interstitial:interstitial:didFailToReceiveAdWithError: -> should be called on connection errors (including no connection at all)

Rewarded examples not working

Obj-C rewarded example has issue with setup it seems. Console log:

<FIRInstanceID/WARNING> Failed to fetch default token Error Domain=com.firebase.iid Code=501 "(null)"
Invalid Request. Cannot determine request type. Is your ad unit id correct?
Reward based video ad failed to load.

Issue seems with line 31 in AppDelegate.m:
[GADMobileAds configureWithApplicationID:@"INSERT_APP_ID_HERE"];

And on line 103 in ViewController.m
[[GADRewardBasedVideoAd sharedInstance] loadRequest:request withAdUnitID:@"INSERT_AD_UNIT_HERE"];

Same goes for Swift version as well.

UIViewController

Hello.
Is there any way to make the example work with UIViewController (with a tableview inside) instead of TableViewController?

I've completed my application as the example (also with the correct admob pub and google info plist from firebase) But it only shows the regular cells from my Class and it never enters at this lines of code

func tableView(_ tableView: UITableView,
                            cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        
        if let nativeExpressAdView = taEvent[indexPath.row] as? GADNativeExpressAdView {
            let reusableAdCell = tableView.dequeueReusableCell(withIdentifier: "NativeExpressAdViewCell",
                                                               for: indexPath)
            
            // Remove previous GADNativeExpressAdView from the content view before adding a new one.
            for subview in reusableAdCell.contentView.subviews {
                subview.removeFromSuperview()
            }
            print("test")   // ITS NEVER PRINTED AS SCROLLING
            reusableAdCell.contentView.addSubview(nativeExpressAdView)
            // Center GADNativeExpressAdView in the table cell's content view.
            nativeExpressAdView.center = reusableAdCell.contentView.center
            
            return reusableAdCell
    
        } else {
                
            let cell = tableView.dequeueReusableCell(withIdentifier: "locationCell", for: indexPath) as? EventsTableViewCell
                
                            let event = taEvent[indexPath.row]
                            cell?.configureCell(events: event as! Events)
                            return cell!
            }
    }

And i think its because of the reloaddata that i use.
Any idea?

My ads don't work on real devices

Hi there,

I can see ads working properly on simulator or testing device but not on a real device.

The app was approved and it is on the AppStore.

Here is the code I'm using.

print("Google Mobile Ads SDK version: " + GADRequest.sdkVersion())
let request = GADRequest()
request.testDevices = ["XXXXXXX", kGADSimulatorID]        
bannerView.adUnitID = "ca-app-pub-XXXXXX/YYYYY"
bannerView.rootViewController = self
bannerView.loadRequest(request)

Do you have any idea?

Thanks and regards!

Ad wasn't ready

i used the code from the example for ad interstitial for swift 3 , and the app can't get an add, the code runs fine but when it comes to check isReady, it prints "Ad Wasn't ready "

DFP interstitial Ads size

DFP interstitial Ad doesn't appear with its correct size, it doesn't fit the screen the add appear to be smaller than screen width and height.
the ad unit ID "/1017609/mobileapp_interstitial"
4fbaf93c-6257-11e6-8a53-b0a91bd066f1

rewardVideo problem

Why do I use this unitID: ca-app-pub-3940256099942544/1712485313 does not have any data that can provide a data test unitID?

GADNativeExpressAdView

Sometimes I see error:

2016-11-24 15:59:57.732 Russian[36147:1904224] <Google> Unable to set adSize property. Not enough space to show ad with custom size, {726, 264}. Please use a size that fits the current screen bounds of {375, 667}.
2016-11-24 15:59:57.754 Russian[36147:1904216] <Google> Invalid Request. Ad size will not fit on screen

But I does not set ad size 726, 264, I set 363, 132. Looks like it's in pixels and compared to screen size in pt.


(lldb) po adSize.size
(width = 363, height = 132)

(lldb) po adSize.flags
1

(lldb) po [UIScreen mainScreen]
<UIScreen: 0x7fa990402e30; bounds = {{0, 0}, {375, 667}}; mode = <UIScreenMode: 0x61000023cfa0; size = 750.000000 x 1334.000000>>

(lldb) po self.superview
<UICollectionView: 0x7fa991875200; frame = (0 0; 375 603); clipsToBounds = YES; gestureRecognizers = <NSArray: 0x618000250980>; layer = <CALayer: 0x6180002369a0>; contentOffset: {0, 0}; contentSize: {375, 262}> collection view layout: <UICollectionViewFlowLayout: 0x7fa9921363d0>

(lldb) po self
<AdsCell: 0x7fa99043a180; baseClass = UICollectionViewCell; frame = (6 124; 363 132); clipsToBounds = YES; layer = <CALayer: 0x6000002341c0>>

(lldb) po self.contentView
<UIView: 0x7fa99043a7f0; frame = (0 0; 363 132); gestureRecognizers = <NSArray: 0x600000258780>; layer = <CALayer: 0x6000002347e0>>

(lldb) po self.contentView.subviews
<__NSArrayM 0x600000259080>(
<UIView: 0x7fa99043aae0; frame = (0 0; 363 132); layer = <CALayer: 0x600000234420>>,
<UIActivityIndicatorView: 0x7fa99043ac80; frame = (171.5 56; 20 20); layer = <CALayer: 0x600000233860>>
)

Interstitial Ad Issue

Getting this error every time, I added ATS privacy in plist file...

InterstitialExample[6790:2228703] CFNetwork SSLHandshake failed (-9806)
2017-04-11 16:31:39.331 InterstitialExample[6790] [Firebase/Core][I-NET901017] <Firebase/Network/ERROR> Encounter network error. Code, error: -1001, Error Domain=NSURLErrorDomain Code=-1001 "The request timed out." UserInfo={NSErrorFailingURLStringKey=https://play.googleapis.com/log, NSErrorFailingURLKey=https://play.googleapis.com/log, _kCFStreamErrorDomainKey=4, _kCFStreamErrorCodeKey=-2103, NSLocalizedDescription=The request timed out.}

AdChoices overlay not shown

simulator screen shot 19 oct 2015 19 06 31
simulator screen shot 19 oct 2015 19 06 54

Instead I see circled i icon which I assume is not AdChoices overlay.
Tried both /6499/example/native and /6499/example/native-backfill unit IDs.

DFP Custom Native Ads Memory Leak

When running the example project (DFPNativeExample.xcodeproj) and using Custom Native Ads, there appears to be a memory leak. Memory usage goes up upon each ad Request.

Running Xcode 6.3.2, iPhone 6 iOS 8.1.

Is this the proper place to log this?

Just making a wild guess, I assume the ad is being held in memory because impression and click logging happens async, and when looking the code to record an impression, it's a call on the AdLoader object, thus it would have to sit around in memory (again, just guessing).
The screen shots below show memory growth after requesting about 10 ads with a 10 second delay in between each ad.

customnativead_memoryleak2

customnativead_memoryleak

Does kGADAdSizeSmartBannerPortrait actually work?

Even using only a constraint of 50 points for height, a banner view setup with kGADAdSizeSmartBannerPortrait does always only pull down the "320x50 test banner" creative. Does this mean that the smart size thing does actually not work, OR, it works but there is just no matching test creative so it sends the "next nearest match" which could be 320x50 in this case - kind of thinking? I am expecting, in portrait, a 414 point wide banner on iPhone 6 Plus, 375 points on iPhone 6, 320 on other iPhones and iPods.

FYI: I came here looking for smart sized banners as advertised on your pages. The example projects showed nothing of that, I had to setup define the kGADAdSizeSmartBannerPortrait myself. A suggestion would be to show off all possible banner sizes in your sample projects. Granted they work.

There were a few other issues stemming from too old codebases. Bitcode needed to be turned off, some battling with cocoapods, adding launch images (for the ObjC project) in order to get native resolution on iPhone 6 Plus and iPhone 6, and possibly a few more issues before it was even possible to build and run properly. You might want to fix that stuff.

swift Admob banner ad Memory lack

  1. So high memory when admob banner ad load
    screen shot 2016-04-27 at 19 09 45
  2. The memory has been increasing, also used facebook ad, very low memory, and auto resize banner

Expanded example for GADNativeExpressAdView

Hi Guys, could you please improve the samples for GADNativeExpressAdView, the actual example it's really a "hello world" type... for example We are having issues trying to put the view into a collection view or table view, please refer to this SO question GADNativeExpressAdView mainly because the Ad blocks the main thread while scrolling.

What should be the right approach when including GADNativeExpressAdView in this type of scenarios?

Thanks!

No ad to show

I got this error message : Error Domain=com.google.ads Code=1 "Request Error: No ad to show." UserInfo={NSLocalizedDescription=Request Error: No ad to show., NSLocalizedFailureReason=Request Error: No ad to show.}

ios code :
var nativeExpressAdView: GADNativeExpressAdView!

func displayGoogleBanner() {
    var gadAdSize = GADAdSize()
    let size = CGSize(width: 280,height: 250)
    gadAdSize.size = size;
    
    self.nativeExpressAdView = GADNativeExpressAdView(adSize: gadAdSize, origin: CGPoint(x:
        ScreenSize.SCREEN_WIDTH/2 - 140, y: 10))
    self.contentView.addSubview(nativeExpressAdView)
    
    
    nativeExpressAdView.adUnitID = AppGame.googleNativeAdsBlocMappsGame
    nativeExpressAdView.rootViewController = self
    nativeExpressAdView.delegate = self
    
    let request : GADRequest = GADRequest()
    nativeExpressAdView.loadRequest(request)

}

High CPU

Hello,every time loadRequest is being called CPU is 100%.
in v. 7.6.0 even if the user closes the interstitial, cpu remains 100%.
At v. 7.7.0 cpu is again 100% ( all the time the ad is open) but drops when ad close.
Any idea?

Custom native ad is not working

Run DFPNativeExample project.
Check only Custom Native Ad switch on.
Tap Refresh Ad.

Result in console:
2015-10-20 10:49:48.339 DFPNativeExample[50671:32868793] <GADAdLoader: 0x7fa24db8bcb0> failed with error: Request Error: Received invalid response.

Nothing changes in app.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.