-
-
Notifications
You must be signed in to change notification settings - Fork 46
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
74 additions
and
84 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
}; |