Skip to content

Commit

Permalink
fix(admob): remove deleted method
Browse files Browse the repository at this point in the history
  • Loading branch information
triniwiz committed May 29, 2022
1 parent 35c3f44 commit f0ccb4a
Show file tree
Hide file tree
Showing 2 changed files with 74 additions and 84 deletions.
2 changes: 0 additions & 2 deletions packages/firebase-admob/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -133,8 +133,6 @@ export interface RequestConfiguration {
export interface RequestOptions {
contentUrl?: undefined | string;
keywords?: string[];
location?: [number, number];
locationAccuracy?: undefined | number;
networkExtras?: undefined | { [key: string]: string };
requestAgent?: undefined | string;
requestNonPersonalizedAdsOnly?: undefined | false | true;
Expand Down
156 changes: 74 additions & 82 deletions packages/firebase-admob/utils.ts
Original file line number Diff line number Diff line change
@@ -1,109 +1,101 @@
import {ManagerRequestOptions, RequestOptions} from "./common";
import { ManagerRequestOptions, RequestOptions } from './common';

export function toSerializeRequestOptions(requestOptions?: RequestOptions, isManager: boolean = false) {
if (global.isAndroid) {
return null;
}
const request = isManager ? GADRequest.request() : GAMRequest.request();
if (global.isAndroid) {
return null;
}
const request = isManager ? GADRequest.request() : GAMRequest.request();

if (requestOptions?.contentUrl) {
request.contentURL = requestOptions?.contentUrl;
}
if (requestOptions?.contentUrl) {
request.contentURL = requestOptions?.contentUrl;
}

if (requestOptions?.keywords) {
request.keywords = requestOptions?.keywords as any;
}
if (requestOptions?.keywords) {
request.keywords = requestOptions?.keywords as any;
}

if (requestOptions?.location) {
request.setLocationWithLatitudeLongitudeAccuracy(requestOptions?.location[0], requestOptions?.location[1], requestOptions?.locationAccuracy);
}
const nativeExtras = GADExtras.new();
let extras = {};

const nativeExtras = GADExtras.new();
let extras = {};
if (requestOptions?.requestNonPersonalizedAdsOnly) {
extras['npa'] = '1';
}

if (requestOptions?.requestNonPersonalizedAdsOnly) {
extras['npa'] = '1';
}
if (requestOptions?.networkExtras) {
extras = Object.assign(extras, requestOptions?.networkExtras);
}

if (requestOptions?.networkExtras) {
extras = Object.assign(extras, requestOptions?.networkExtras);
}
nativeExtras.additionalParameters = extras as any;
request.registerAdNetworkExtras(nativeExtras);

nativeExtras.additionalParameters = extras as any;
request.registerAdNetworkExtras(nativeExtras);

if (requestOptions?.requestAgent) {
request.requestAgent = requestOptions?.requestAgent;
}
return request;
if (requestOptions?.requestAgent) {
request.requestAgent = requestOptions?.requestAgent;
}
return request;
}

export function toSerializeManagerRequestOptions(requestOptions?: ManagerRequestOptions) {
if (global.isAndroid) {
return null;
}

if (global.isAndroid) {
return null;
}

const request = toSerializeRequestOptions(requestOptions, true) as GAMRequest;
const request = toSerializeRequestOptions(requestOptions, true) as GAMRequest;

if (requestOptions.publisherProvidedId) {
request.publisherProvidedID = requestOptions.publisherProvidedId;
}
if (requestOptions.publisherProvidedId) {
request.publisherProvidedID = requestOptions.publisherProvidedId;
}

if (requestOptions.customTargeting) {
request.customTargeting = requestOptions.customTargeting as any;
}
if (requestOptions.customTargeting) {
request.customTargeting = requestOptions.customTargeting as any;
}

if (Array.isArray(requestOptions.categoryExclusions)) {
request.categoryExclusions = requestOptions.categoryExclusions as any;
}
if (Array.isArray(requestOptions.categoryExclusions)) {
request.categoryExclusions = requestOptions.categoryExclusions as any;
}

return request;
return request;
}


export const topViewController = (): UIViewController | undefined => {
if (global.isAndroid) {
return undefined;
}
const root = rootViewController();
if (root == null) {
return undefined;
}
return findTopViewController(root);
if (global.isAndroid) {
return undefined;
}
const root = rootViewController();
if (root == null) {
return undefined;
}
return findTopViewController(root);
};


const rootViewController = (): UIViewController | undefined => {
const keyWindow = UIApplication.sharedApplication.keyWindow;
return keyWindow != null ? keyWindow.rootViewController : undefined;
const keyWindow = UIApplication.sharedApplication.keyWindow;
return keyWindow != null ? keyWindow.rootViewController : undefined;
};


const findTopViewController = (root: UIViewController): UIViewController | undefined => {
const presented = root.presentedViewController;
if (presented != null) {
return findTopViewController(presented);
}
if (root instanceof UISplitViewController) {
const last = root.viewControllers.lastObject;
if (last == null) {
return root;
}
return findTopViewController(last);
} else if (root instanceof UINavigationController) {
const top = root.topViewController;
if (top == null) {
return root;
}
return findTopViewController(top);
} else if (root instanceof UITabBarController) {
const selected = root.selectedViewController;
if (selected == null) {
return root;
}
return findTopViewController(selected);
} else {
return root;
}
const presented = root.presentedViewController;
if (presented != null) {
return findTopViewController(presented);
}
if (root instanceof UISplitViewController) {
const last = root.viewControllers.lastObject;
if (last == null) {
return root;
}
return findTopViewController(last);
} else if (root instanceof UINavigationController) {
const top = root.topViewController;
if (top == null) {
return root;
}
return findTopViewController(top);
} else if (root instanceof UITabBarController) {
const selected = root.selectedViewController;
if (selected == null) {
return root;
}
return findTopViewController(selected);
} else {
return root;
}
};

0 comments on commit f0ccb4a

Please sign in to comment.