Skip to content

Commit

Permalink
feat(ios, sdk): migrate to mobile ads sdk v9
Browse files Browse the repository at this point in the history
Fixes #113

BREAKING CHANGES: The update to google mobile ads ios SDK v9 has these changes -

iOS 10 will no longer receive ads, iOS 11 is the minimum version to receive ads
Location ad request options are ignored, locations are not used for ads in the SDK
  • Loading branch information
dylancom authored and mikehardy committed Apr 19, 2022
1 parent c496979 commit 36a440a
Show file tree
Hide file tree
Showing 6 changed files with 3 additions and 90 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,11 @@
*
*/

import android.location.Location;
import android.os.Bundle;
import android.util.DisplayMetrics;
import android.view.Display;
import com.facebook.react.bridge.Arguments;
import com.facebook.react.bridge.ReactContext;
import com.facebook.react.bridge.ReadableArray;
import com.facebook.react.bridge.ReadableMap;
import com.facebook.react.bridge.WritableMap;
import com.facebook.react.views.view.ReactViewGroup;
Expand Down Expand Up @@ -165,15 +163,6 @@ public static AdManagerAdRequest buildAdRequest(ReadableMap adRequestOptions) {
builder.setContentUrl(Objects.requireNonNull(adRequestOptions.getString("contentUrl")));
}

if (adRequestOptions.hasKey("location")) {
ReadableArray locationArray = adRequestOptions.getArray("location");
Location location = new Location("");
location.setLatitude(Objects.requireNonNull(locationArray).getDouble(0));
location.setLongitude(Objects.requireNonNull(locationArray).getDouble(1));

builder.setLocation(location);
}

if (adRequestOptions.hasKey("requestAgent")) {
builder.setRequestAgent(Objects.requireNonNull(adRequestOptions.getString("requestAgent")));
}
Expand Down
7 changes: 0 additions & 7 deletions ios/RNGoogleMobileAds/RNGoogleMobileAdsCommon.m
Original file line number Diff line number Diff line change
Expand Up @@ -68,13 +68,6 @@ + (GAMRequest *)buildAdRequest:(NSDictionary *)adRequestOptions {
request.keywords = adRequestOptions[@"keywords"];
}

if (adRequestOptions[@"location"]) {
NSArray<NSNumber *> *latLong = adRequestOptions[@"location"];
[request setLocationWithLatitude:[latLong[0] doubleValue]
longitude:[latLong[1] doubleValue]
accuracy:[adRequestOptions[@"locationAccuracy"] doubleValue]];
}

if (adRequestOptions[@"contentUrl"]) {
request.contentURL = adRequestOptions[@"contentUrl"];
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ @implementation RNGoogleMobileAdsFullScreenContentDelegate
#pragma mark -
#pragma mark GADFullScreenContentDelegate Methods

/// Tells the delegate that the ad presented full screen content.
- (void)adDidPresentFullScreenContent:(nonnull id<GADFullScreenPresentingAd>)ad {
/// Tells the delegate that the ad is about to present full screen content.
- (void)adWillPresentFullScreenContent:(nonnull id<GADFullScreenPresentingAd>)ad {
[RNGoogleMobileAdsCommon sendAdEvent:_sendAdEvent
requestId:_requestId
type:GOOGLE_MOBILE_ADS_EVENT_OPENED
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
],
"sdkVersions": {
"ios": {
"googleMobileAds": "8.13.0",
"googleMobileAds": "9.3.0",
"googleUmp": "2.0.0"
},
"android": {
Expand Down
24 changes: 0 additions & 24 deletions src/types/RequestOptions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,30 +72,6 @@ export interface RequestOptions {
*/
customTargeting?: { [key: string]: string };

/**
* The latitude and longitude location of the user.
*
* Ensure your app requests location permissions from the user.
*
* #### Example
*
* ```js
* await Interstitial.createForAdRequest('ca-app-pub-3940256099942544/1033173712', {
* location: [53.481073, -2.237074],
* });
* ```
*/
location?: [number, number];

/**
* Sets the location accuracy if the location is set, in meters.
*
* This option is only applied to iOS devices. On Android, this option has no effect.
*
* @ios
*/
locationAccuracy?: number;

/**
* Sets the request agent string to identify the ad request's origin. Third party libraries that reference the Mobile
* Ads SDK should call this method to denote the platform from which the ad request originated. For example, if a
Expand Down
45 changes: 0 additions & 45 deletions src/validateAdRequestOptions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ import {
hasOwnProperty,
isArray,
isBoolean,
isNumber,
isObject,
isString,
isUndefined,
Expand Down Expand Up @@ -92,50 +91,6 @@ export function validateAdRequestOptions(options?: RequestOptions) {
out.contentUrl = options.contentUrl;
}

if (options.location) {
const error = new Error(
"'options.location' expected an array value containing a latitude & longitude number value.",
);

if (!isArray(options.location)) {
throw error;
}

const [latitude, longitude] = options.location;

if (!isNumber(latitude) || !isNumber(longitude)) {
throw error;
}

if (latitude < -90 || latitude > 90) {
throw new Error(
`'options.location' latitude value must be a number between -90 and 90, but was: ${latitude}`,
);
}

if (longitude < -180 || longitude > 180) {
throw new Error(
`'options.location' longitude value must be a number between -180 and 180, but was: ${latitude}`,
);
}

out.location = [latitude, longitude];
}

if (hasOwnProperty(options, 'locationAccuracy')) {
if (!isNumber(options.locationAccuracy)) {
throw new Error("'options.locationAccuracy' expected a number value.");
}

if (isNumber(options.locationAccuracy) && options.locationAccuracy < 0) {
throw new Error("'options.locationAccuracy' expected a number greater than 0.");
}

out.locationAccuracy = options.locationAccuracy;
} else {
out.locationAccuracy = 5;
}

if (options.requestAgent) {
if (!isString(options.requestAgent)) {
throw new Error("'options.requestAgent' expected a string value");
Expand Down

0 comments on commit 36a440a

Please sign in to comment.