Giter VIP home page Giter VIP logo

expo-mopub's Introduction

expo-mopub

Getting started

$ yarn add expo-mopub

Mostly automatic installation

$ react-native link expo-mopub

MoPub Integration

iOS

  1. Open terminal and navigate to project iOS directory and run command.
pod init
  1. It will create Podfile in your project, open it and paste the following lines below
`target 'PROJECT_NAME' do`.

pod 'React', :path => '../node_modules/react-native', :subspecs => [
'Core',
'CxxBridge', # Include this for RN >= 0.47
'DevSupport', # Include this to enable In-App Devmenu if RN >= 0.43
'RCTText',
'RCTNetwork',
'RCTWebSocket', # Needed for debugging
'RCTAnimation', # Needed for FlatList and animations running on native UI thread
# Add any other subspecs you want to use in your project
]
# Explicitly include Yoga if you are using RN >= 0.42.0
pod 'yoga', :path => '../node_modules/react-native/ReactCommon/yoga'
# Third party deps podspec link
pod 'DoubleConversion', :podspec => '../node_modules/react-native/third-party-podspecs/DoubleConversion.podspec'
pod 'glog', :podspec => '../node_modules/react-native/third-party-podspecs/glog.podspec'
pod 'Folly', :podspec => '../node_modules/react-native/third-party-podspecs/Folly.podspec'
pod 'expo-mopub', path: '../node_modules/expo-mopub'
end
  1. Then run the following command in termainal in the same location
pod install

Android

  1. Add following permissions to your android AndroidManifest.xml.
<!-- Required permissions -->
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>

<!-- Optional permissions. Will pass Lat/Lon values when available. Choose either Coarse or Fine -->
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>

<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
  1. Declare the following activities in your AndroidManifest.xml.
<!-- MoPub's consent dialog -->
<activity android:name="com.mopub.common.privacy.ConsentDialogActivity" android:configChanges="keyboardHidden|orientation|screenSize"/>

<!-- All ad formats -->
<activity android:name="com.mopub.common.MoPubBrowser" android:configChanges="keyboardHidden|orientation|screenSize"/>

<!-- Interstitials -->
<activity android:name="com.mopub.mobileads.MoPubActivity" android:configChanges="keyboardHidden|orientation|screenSize"/>
<activity android:name="com.mopub.mobileads.MraidActivity" android:configChanges="keyboardHidden|orientation|screenSize"/>

<!-- Rewarded Video and Rewarded Playables -->
<activity android:name="com.mopub.mobileads.RewardedMraidActivity" android:configChanges="keyboardHidden|orientation|screenSize"/>
<activity android:name="com.mopub.mobileads.MraidVideoPlayerActivity" android:configChanges="keyboardHidden|orientation|screenSize"/>

<meta-data android:name="com.google.android.gms.version"
android:value="15.0.90" />
  1. Add following lines to build.gradle allprojectsโžœ repositories
maven { url "https://s3.amazonaws.com/moat-sdk-builds" }
maven { url 'https://adcolony.bintray.com/AdColony' }
maven { url 'https://tapjoy.bintray.com/maven' }
maven { url 'https://jitpack.io' }

Usage

Interstitial

import {RNMoPubInterstitial} from 'expo-mopub';

Interstitial Methods

Mehod Description
initializeInterstitialAd (adUnitId: string) Initialize Interstitial ad for the the given ad unit.
loadAd () Loads ad for the unit provided through initialization.
setKeywords (keywords: string) Set keyword for the ad.
isReady () Return a promise to check whether Interstitial is ready.
show () Shows Interstitial if loaded.
addEventListener (eventType: string, listener: Function) Adds listener to the events from Interstitial ad, possible event names are "onLoaded" "onFailed", "onClicked", "onShown" and "onDismissed".
removeAllListeners (eventType: string) Remove listeners for added for events from Interstitial ad.

Banner Ad

import {MoPubBanner} from 'expo-mopub';

Banner Props

Prop Type Description
adUnitId String Banner ad unit id for which you want to show banner ad.
autoRefresh Bool Toggle auto-refresh enable or disable.
keywords String Pass the keywords from your app to MoPub as a comma-separated list in the ad view. Each keyword should be formatted as a key/value pair (e.g. m_age:24). Any characters can be used except & and =.
onLoaded Function Calls when the banner has successfully retrieved an ad.
onFailed Function Calls when the banner has failed to retrieve an ad. You can get error message from the event object.
onClicked Function Calls when the user has tapped on the banner.
onExpanded Function Calls when the banner has just taken over the screen.
onCollapsed Function Calls when an expanded banner has collapsed back to its original size.

expo-mopub's People

Contributors

jeremyvinec avatar

Watchers

 avatar  avatar

expo-mopub's Issues

Launching app from notification crashes

Hi, when launching an application using expo-mopub from a FCM notificaiton the application crashes, here are some relevant stack traces/logs:

10-12 18:36:18.078 6962 7125 E unknown:ReactNative: CatalystInstanceImpl caught native exception
10-12 18:36:18.078 6962 7125 E unknown:ReactNative: java.lang.NullPointerException: Attempt to invoke virtual method 'android.os.Looper android.app.Activity.getMainLooper()' on a null object reference
10-12 18:36:18.078 6962 7125 E unknown:ReactNative: at com.reactlibrary.AdLibSDK.initializeAdSDK(AdLibSDK.java:20)
10-12 18:36:18.078 6962 7125 E unknown:ReactNative: at com.reactlibrary.RNMoPubRewardedVideo.initializeSdkForRewardedVideoAd(RNMoPubRewardedVideo.java:69)
10-12 18:36:18.078 6962 7125 E unknown:ReactNative: at java.lang.reflect.Method.invoke(Native Method)
10-12 18:36:18.078 6962 7125 E unknown:ReactNative: at com.facebook.react.bridge.JavaMethodWrapper.invoke(JavaMethodWrapper.java:372)
10-12 18:36:18.078 6962 7125 E unknown:ReactNative: at com.facebook.react.bridge.JavaModuleWrapper.invoke(JavaModuleWrapper.java:151)
10-12 18:36:18.078 6962 7125 E unknown:ReactNative: at com.facebook.react.bridge.queue.NativeRunnable.run(Native Method)
10-12 18:36:18.078 6962 7125 E unknown:ReactNative: at android.os.Handler.handleCallback(Handler.java:938)
10-12 18:36:18.078 6962 7125 E unknown:ReactNative: at android.os.Handler.dispatchMessage(Handler.java:99)
10-12 18:36:18.078 6962 7125 E unknown:ReactNative: at com.facebook.react.bridge.queue.MessageQueueThreadHandler.dispatchMessage(MessageQueueThreadHandler.java:27)
10-12 18:36:18.078 6962 7125 E unknown:ReactNative: at android.os.Looper.loop(Looper.java:245)
10-12 18:36:18.078 6962 7125 E unknown:ReactNative: at com.facebook.react.bridge.queue.MessageQueueThreadImpl$4.run(MessageQueueThreadImpl.java:226)
10-12 18:36:18.078 6962 7125 E unknown:ReactNative: at java.lang.Thread.run(Thread.java:923)

Which leads to:

10-12 18:36:19.219 6962 7125 E unknown:ReactContextBaseJavaModule: java.lang.RuntimeException: Catalyst Instance has already disappeared: requested by Networking

Do you have any idea of how to delay the initialization untill the context is available?

Thanks

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.