2 Star 0 Fork 0

mirrors_gorangajic/react-native-admob

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
贡献代码
同步代码
取消
提示: 由于 Git 不支持空文件夾,创建文件夹后会生成空的 .keep 文件
Loading...
README
BSD-2-Clause

npm version

react-native-admob

A react-native module for Google AdMob GADBanner and GADInterstitial (react-native v0.19.0 or newer required).

The banner is implemented as a component while the interstitial has an imperative API.

Installation

With rnpm (recommended)

  1. npm i react-native-admob -S
  2. rnpm link
  3. Add Google AdMob Framework to your Xcode project. This is only needed for iOS and guarantees your app is using the newest admob version.

Manual Installation

iOS
  1. npm i react-native-admob -S
  2. Add Google AdMob Framework to your Xcode project.
  3. Add react-native-admob static library to your Xcode project like explained here. (Step 3 of this guide is not needed)
Android
  1. npm i react-native-admob -S
  2. Make the following additions to the given files:

android/settings.gradle

include ':RNAdMob', ':app'
project(':RNAdMob').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-admob/android')

android/app/build.gradle

dependencies {
   ...
   compile project(':RNAdMob')
}

MainActivity.java

On top, where imports are:

import com.sbugert.rnadmob.RNAdMobPackage;

Under protected List<ReactPackage> getPackages() {:

  return Arrays.<ReactPackage>asList(
    new MainReactPackage(),
    new RNAdMobPackage()
  );

Usage

import { AdMobBanner, AdMobInterstitial } from 'react-native-admob'

// Display a banner
<AdMobBanner
  bannerSize="fullBanner"
  adUnitID="your-admob-unit-id"
  testDeviveID="EMULATOR"
  didFailToReceiveAdWithError={this.bannerError} />

// Display an interstitial
AdMobInterstitial.setAdUnitID('your-admob-unit-id');
AdMobInterstitial.setTestDeviceID('EMULATOR');
AdMobInterstitial.requestAd(AdMobInterstitial.showAd);

For a full example reference to the example project.

Reference

AdMobBanner

bannerSize property

Corresponding to iOS framework banner size constants

Prop value Description Size
banner Standard Banner for Phones and Tablets 320x50
largeBanner Large Banner for Phones and Tablets 320x100
mediumRectangle IAB Medium Rectangle for Phones and Tablets 300x250
fullBanner IAB Full-Size Banner for Tablet 468x60
leaderboard IAB Leaderboard for Tablets 728x90
smartBannerPortrait Smart Banner for Phones and Tablets (default) Screen width x 32
smartBannerLandscape Smart Banner for Phones and Tablets Screen width x 32

Note: There is no smartBannerPortrait and smartBannerLandscape on Android. Both prop values will map to smartBanner

Events as function props

Corresponding to Ad lifecycle event callbacks

Prop
adViewDidReceiveAd()
didFailToReceiveAdWithError(errorDescription)
adViewWillPresentScreen()
adViewWillDismissScreen()
adViewDidDismissScreen()
adViewWillLeaveApplication()

AdMobInterstitials

Methods
Name Description
setAdUnitID(adUnitID) sets the AdUnit ID for all future ad requests.
setTestDeviceID(deviceID) sets the test device ID
requestAd(callback) requests an interstitial and calls callback when interstitialDidLoad orinterstitialDidFailToLoad event fires
showAd(callback) shows an interstitial if it is ready and calls callback when interstitialDidOpen event fires
isReady(callback) calls callback with boolean whether interstitial is ready to be shown

For simulators/emulators you can use 'EMULATOR' for the test device ID.
Note: tryShowNewInterstitial() is deprecated as of v1.1.0 and can be replaced by calling requestAd with showAd as callback.

Events

Unfortunately, events are not consistent across iOS and Android. To have one unified API, new event names are introduced for pairs that are roughly equivalent.

iOS this library Android
interstitialDidReceiveAd interstitialDidLoad onAdLoaded
interstitial:didFailToReceiveAdWithError interstitialDidFailToLoad onAdFailedToLoad
interstitialWillPresentScreen interstitialDidOpen onAdOpened
interstitialDidFailToPresentScreen
interstitialWillDismissScreen
interstitialDidDismissScreen interstitialDidClose onAdClosed
interstitialWillLeaveApplication interstitialWillLeaveApplication onAdLeftApplication

Note that interstitialWillLeaveApplication and onAdLeftApplication are not exactly the same but share one event in this library.


TODO

  • Support Ad Targeting
  • Also use interstitial event names for banner
Copyright (c) 2015, Simon Bugert All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

简介

暂无描述 展开 收起
README
BSD-2-Clause
取消

发行版

暂无发行版

贡献者

全部

近期动态

不能加载更多了
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/mirrors_gorangajic/react-native-admob.git
git@gitee.com:mirrors_gorangajic/react-native-admob.git
mirrors_gorangajic
react-native-admob
react-native-admob
master

搜索帮助