Skip to content

Commit

Permalink
feat(catalyst): support building on catalyst, though ads will not work (
Browse files Browse the repository at this point in the history
#389)

* Excludes most of the code for Mac Catalyst builds

* style(lint): result of `lint:ios:fix`

---------

Co-authored-by: Mike Hardy <[email protected]>
  • Loading branch information
birdofpreyru and mikehardy authored Jun 24, 2023
1 parent 4dc08ef commit ab55792
Show file tree
Hide file tree
Showing 18 changed files with 89 additions and 1 deletion.
4 changes: 4 additions & 0 deletions RNGoogleMobileAds.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,19 @@ Pod::Spec.new do |s|
google_ump_sdk_version = $RNGoogleUmpSDKVersion
end

if !ENV['MAC_CATALYST']
s.dependency 'GoogleUserMessagingPlatform', google_ump_sdk_version
end

if defined?($RNGoogleMobileAdsSDKVersion)
Pod::UI.puts "#{s.name}: Using user specified Google Mobile-Ads SDK version '#{$RNGoogleMobileAdsSDKVersion}'"
google_mobile_ads_sdk_version = $RNGoogleMobileAdsSDKVersion
end

# AdMob dependencies
if !ENV['MAC_CATALYST']
s.dependency 'Google-Mobile-Ads-SDK', google_mobile_ads_sdk_version
end

if defined?($RNGoogleMobileAdsAsStaticFramework)
Pod::UI.puts "#{s.name}: Using overridden static_framework value of '#{$RNGoogleMobileAdsAsStaticFramework}'"
Expand Down
4 changes: 4 additions & 0 deletions ios/RNGoogleMobileAds/RNGoogleMobileAdsAppOpenModule.m
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
*
*/

#if !TARGET_OS_MACCATALYST

#import <React/RCTBridgeModule.h>

@interface RCT_EXTERN_MODULE (RNGoogleMobileAdsAppOpenModule, NSObject)
Expand All @@ -40,3 +42,5 @@ + (BOOL)requiresMainQueueSetup {
: (RCTPromiseRejectBlock)reject)

@end

#endif
4 changes: 4 additions & 0 deletions ios/RNGoogleMobileAds/RNGoogleMobileAdsAppOpenModule.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
*
*/

#if !targetEnvironment(macCatalyst)

import Foundation
import GoogleMobileAds

Expand Down Expand Up @@ -79,3 +81,5 @@ class RNGoogleMobileAdsAppOpenModule: NSObject {
}
}
}

#endif
4 changes: 4 additions & 0 deletions ios/RNGoogleMobileAds/RNGoogleMobileAdsBannerComponent.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
*
*/

#if !TARGET_OS_MACCATALYST

#import <GoogleMobileAds/GADAppEventDelegate.h>
#import <GoogleMobileAds/GADBannerView.h>
#import <GoogleMobileAds/GADBannerViewDelegate.h>
Expand All @@ -37,3 +39,5 @@
- (void)recordManualImpression;

@end

#endif
4 changes: 4 additions & 0 deletions ios/RNGoogleMobileAds/RNGoogleMobileAdsBannerComponent.m
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
*
*/

#if !TARGET_OS_MACCATALYST

#import "RNGoogleMobileAdsBannerComponent.h"
#import <React/RCTLog.h>
#import "RNGoogleMobileAdsCommon.h"
Expand Down Expand Up @@ -154,3 +156,5 @@ - (void)recordManualImpression {
}

@end

#endif
6 changes: 6 additions & 0 deletions ios/RNGoogleMobileAds/RNGoogleMobileAdsBannerViewManager.m
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ @implementation RNGoogleMobileAdsBannerViewManager
RCT_EXPORT_VIEW_PROPERTY(onNativeEvent, RCTBubblingEventBlock);

RCT_EXPORT_METHOD(recordManualImpression : (nonnull NSNumber *)reactTag) {
#if !TARGET_OS_MACCATALYST
[self.bridge.uiManager
addUIBlock:^(RCTUIManager *uiManager, NSDictionary<NSNumber *, UIView *> *viewRegistry) {
RNGoogleMobileAdsBannerComponent *banner = viewRegistry[reactTag];
Expand All @@ -44,13 +45,18 @@ @implementation RNGoogleMobileAdsBannerViewManager
}
[banner recordManualImpression];
}];
#endif
}

@synthesize bridge = _bridge;

- (UIView *)view {
#if TARGET_OS_MACCATALYST
return nil;
#else
RNGoogleMobileAdsBannerComponent *banner = [RNGoogleMobileAdsBannerComponent new];
return banner;
#endif
}

- (dispatch_queue_t)methodQueue {
Expand Down
4 changes: 4 additions & 0 deletions ios/RNGoogleMobileAds/RNGoogleMobileAdsCommon.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
*
*/

#if !TARGET_OS_MACCATALYST

#import <React/RCTBridgeModule.h>
@import GoogleMobileAds;

Expand Down Expand Up @@ -64,3 +66,5 @@ extern NSString *const GOOGLE_MOBILE_ADS_EVENT_APP_EVENT;

extern NSString *const GOOGLE_MOBILE_ADS_EVENT_REWARDED_LOADED;
extern NSString *const GOOGLE_MOBILE_ADS_EVENT_REWARDED_EARNED_REWARD;

#endif
4 changes: 4 additions & 0 deletions ios/RNGoogleMobileAds/RNGoogleMobileAdsCommon.m
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
*
*/

#if !TARGET_OS_MACCATALYST

#import "RNGoogleMobileAdsCommon.h"
#import "common/RNRCTEventEmitter.h"

Expand Down Expand Up @@ -231,3 +233,5 @@ + (UIViewController *)currentViewController {
}

@end

#endif
14 changes: 13 additions & 1 deletion ios/RNGoogleMobileAds/RNGoogleMobileAdsConsentModule.m
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@
#import <React/RCTUtils.h>

#import <React/RCTConvert.h>
#if !TARGET_OS_MACCATALYST
#include <UserMessagingPlatform/UserMessagingPlatform.h>
#endif
#import "RCTBridgeModule.h"
#import "RNGoogleMobileAdsConsentModule.h"
#import "common/RNSharedUtils.h"
Expand All @@ -37,6 +39,7 @@ - (dispatch_queue_t)methodQueue {
#pragma mark -
#pragma mark Google Mobile Ads Methods

#if !TARGET_OS_MACCATALYST
- (NSString *)getConsentStatusString:(UMPConsentStatus)consentStatus {
switch (consentStatus) {
case UMPConsentStatusRequired:
Expand All @@ -50,11 +53,13 @@ - (NSString *)getConsentStatusString:(UMPConsentStatus)consentStatus {
return @"UNKNOWN";
}
}
#endif

RCT_EXPORT_METHOD(requestInfoUpdate
: (NSDictionary *)options
: (RCTPromiseResolveBlock)resolve
: (RCTPromiseRejectBlock)reject) {
#if !TARGET_OS_MACCATALYST
UMPRequestParameters *parameters = [[UMPRequestParameters alloc] init];
UMPDebugSettings *debugSettings = [[UMPDebugSettings alloc] init];

Expand Down Expand Up @@ -86,9 +91,11 @@ - (NSString *)getConsentStatusString:(UMPConsentStatus)consentStatus {
});
}
}];
#endif
}

RCT_EXPORT_METHOD(showForm : (RCTPromiseResolveBlock)resolve : (RCTPromiseRejectBlock)reject) {
#if !TARGET_OS_MACCATALYST
[UMPConsentForm loadWithCompletionHandler:^(UMPConsentForm *form, NSError *loadError) {
if (loadError) {
[RNSharedUtils rejectPromiseWithUserInfo:reject
Expand Down Expand Up @@ -117,9 +124,14 @@ - (NSString *)getConsentStatusString:(UMPConsentStatus)consentStatus {
}];
}
}];
#endif
}

RCT_EXPORT_METHOD(reset) { [UMPConsentInformation.sharedInstance reset]; }
RCT_EXPORT_METHOD(reset) {
#if !TARGET_OS_MACCATALYST
[UMPConsentInformation.sharedInstance reset];
#endif
}

RCT_EXPORT_METHOD(getTCString : (RCTPromiseResolveBlock)resolve : (RCTPromiseRejectBlock)reject) {
@try {
Expand Down
4 changes: 4 additions & 0 deletions ios/RNGoogleMobileAds/RNGoogleMobileAdsFullScreenAd.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
*
*/

#if !targetEnvironment(macCatalyst)

import Foundation
import GoogleMobileAds

Expand Down Expand Up @@ -206,3 +208,5 @@ class RNGoogleMobileAdsFullScreenAd<T>: NSObject where T : GADFullScreenPresenti
resolve!(nil)
}
}

#endif
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#if !targetEnvironment(macCatalyst)

import Foundation
import GoogleMobileAds

Expand Down Expand Up @@ -70,3 +72,5 @@ class RNGoogleMobileAdsFullScreenContentDelegate: NSObject, GADFullScreenContent
)
}
}

#endif
4 changes: 4 additions & 0 deletions ios/RNGoogleMobileAds/RNGoogleMobileAdsInterstitialModule.m
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
*
*/

#if !TARGET_OS_MACCATALYST

#import <React/RCTBridgeModule.h>

@interface RCT_EXTERN_MODULE (RNGoogleMobileAdsInterstitialModule, NSObject)
Expand All @@ -40,3 +42,5 @@ + (BOOL)requiresMainQueueSetup {
: (RCTPromiseRejectBlock)reject)

@end

#endif
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
*
*/

#if !targetEnvironment(macCatalyst)

import Foundation
import GoogleMobileAds

Expand Down Expand Up @@ -117,3 +119,5 @@ class RNGoogleMobileAdsInterstitialModule: NSObject {
}
}
}

#endif
10 changes: 10 additions & 0 deletions ios/RNGoogleMobileAds/RNGoogleMobileAdsModule.m
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@
*
*/

#if !TARGET_OS_MACCATALYST
#import <GoogleMobileAds/GoogleMobileAds.h>
#endif
#import <React/RCTUtils.h>

#import "RNGoogleMobileAdsModule.h"
Expand All @@ -35,6 +37,7 @@ - (dispatch_queue_t)methodQueue {
#pragma mark Google Mobile Ads Methods

RCT_EXPORT_METHOD(initialize : (RCTPromiseResolveBlock)resolve : (RCTPromiseRejectBlock)reject) {
#if !TARGET_OS_MACCATALYST
[[GADMobileAds sharedInstance]
startWithCompletionHandler:^(GADInitializationStatus *_Nonnull status) {
NSDictionary *adapterStatuses = [status adapterStatusesByClassName];
Expand All @@ -50,6 +53,7 @@ - (dispatch_queue_t)methodQueue {
}
resolve(result);
}];
#endif
}

RCT_EXPORT_METHOD(setRequestConfiguration
Expand All @@ -61,6 +65,7 @@ - (dispatch_queue_t)methodQueue {
}

- (void)setRequestConfiguration:(NSDictionary *)requestConfiguration {
#if !TARGET_OS_MACCATALYST
if (requestConfiguration[@"maxAdContentRating"]) {
NSString *rating = requestConfiguration[@"maxAdContentRating"];
if ([rating isEqualToString:@"G"]) {
Expand Down Expand Up @@ -99,11 +104,13 @@ - (void)setRequestConfiguration:(NSDictionary *)requestConfiguration {
}
GADMobileAds.sharedInstance.requestConfiguration.testDeviceIdentifiers = devices;
}
#endif
}

RCT_EXPORT_METHOD(openAdInspector
: (RCTPromiseResolveBlock)resolve
: (RCTPromiseRejectBlock)reject) {
#if !TARGET_OS_MACCATALYST
[GADMobileAds.sharedInstance
presentAdInspectorFromViewController:RCTSharedApplication().delegate.window.rootViewController
completionHandler:^(NSError *_Nullable error) {
Expand All @@ -119,15 +126,18 @@ - (void)setRequestConfiguration:(NSDictionary *)requestConfiguration {
resolve(nil);
}
}];
#endif
}

RCT_EXPORT_METHOD(openDebugMenu : (NSString *)adUnit) {
#if !TARGET_OS_MACCATALYST
GADDebugOptionsViewController *debugOptionsViewController =
[GADDebugOptionsViewController debugOptionsViewControllerWithAdUnitID:adUnit];
[RCTSharedApplication().delegate.window.rootViewController
presentViewController:debugOptionsViewController
animated:YES
completion:nil];
#endif
}

@end
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
*
*/

#if !TARGET_OS_MACCATALYST

#import <React/RCTBridgeModule.h>

@interface RCT_EXTERN_MODULE (RNGoogleMobileAdsRewardedInterstitialModule, NSObject)
Expand All @@ -40,3 +42,5 @@ + (BOOL)requiresMainQueueSetup {
: (RCTPromiseRejectBlock)reject)

@end

#endif
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
*
*/

#if !targetEnvironment(macCatalyst)

import Foundation
import GoogleMobileAds

Expand Down Expand Up @@ -79,3 +81,5 @@ class RNGoogleMobileAdsRewardedInterstitialModule: NSObject {
}
}
}

#endif
4 changes: 4 additions & 0 deletions ios/RNGoogleMobileAds/RNGoogleMobileAdsRewardedModule.m
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
*
*/

#if !TARGET_OS_MACCATALYST

#import <React/RCTBridgeModule.h>

@interface RCT_EXTERN_MODULE (RNGoogleMobileAdsRewardedModule, NSObject)
Expand All @@ -40,3 +42,5 @@ + (BOOL)requiresMainQueueSetup {
: (RCTPromiseRejectBlock)reject)

@end

#endif
4 changes: 4 additions & 0 deletions ios/RNGoogleMobileAds/RNGoogleMobileAdsRewardedModule.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
*
*/

#if !targetEnvironment(macCatalyst)

import Foundation
import GoogleMobileAds

Expand Down Expand Up @@ -79,3 +81,5 @@ class RNGoogleMobileAdsRewardedModule: NSObject {
}
}
}

#endif

0 comments on commit ab55792

Please sign in to comment.