Skip to content

Functions to Disable AdMob Automatic Services on iOS #772

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 9 commits into from
Dec 16, 2021
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions admob/integration_test/src/integration_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,14 @@ TEST_F(FirebaseAdMobTest, TestInitializationStatus) {
<< "Expected adapter class '" << kAdMobClassName << "' is not loaded.";
}

TEST_F(FirebaseAdMobTest, TestDisableSDKCrashReporting) {
firebase::admob::DisableSDKCrashReporting();
}

TEST_F(FirebaseAdMobTest, TestDisableMediationInitialization) {
firebase::admob::DisableMediationInitialization();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems like these tests aren't really testing the functionality, since it needs to be called before initialization. I think a comment regarding what this is actually testing (that calling the function won't have issues, and not necessarily the functionality) would be good.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done!

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You could also implement a second test fixture class that doesn't automatically initialize AdMob to test what happens when you call these before initialization.

}

TEST_F(FirebaseAdMobTest, TestGetAdRequest) { GetAdRequest(); }

TEST_F(FirebaseAdMobTest, TestGetAdRequestValues) {
Expand Down
4 changes: 4 additions & 0 deletions admob/src/android/admob_android.cc
Original file line number Diff line number Diff line change
Expand Up @@ -374,6 +374,10 @@ AdapterInitializationStatus GetInitializationStatus() {
}
}

void DisableSDKCrashReporting() {}

void DisableMediationInitialization() {}

void SetRequestConfiguration(
const RequestConfiguration& request_configuration) {
JNIEnv* env = ::firebase::admob::GetJNI();
Expand Down
18 changes: 18 additions & 0 deletions admob/src/include/firebase/admob.h
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,24 @@ Future<AdapterInitializationStatus> InitializeLastResult();
/// check which adapters have been initialized.
AdapterInitializationStatus GetInitializationStatus();

/// Disables automated SDK crash reporting on iOS. If not called, the SDK
/// records the original exception handler if available and registers a new
/// exception handler. The new exception handler only reports SDK related
/// exceptions and calls the recorded original exception handler.
///
/// This method has no effect on Android.
void DisableSDKCrashReporting();

/// Disables mediation adapter initialization on iOS during initialization of
/// the AdMob SDK. Calling this method may negatively impact your ad
/// performance and should only be called if you will not use AdMob SDK
/// controlled mediation during this app session. This method must be called
/// before initializing the AdMob SDK or loading ads and has no effect once the
/// SDK has been initialized.
///
/// This method has no effect on Android.
void DisableMediationInitialization();

/// Sets the global @ref RequestConfiguration that will be used for
/// every @ref AdRequest during the app's session.
///
Expand Down
8 changes: 8 additions & 0 deletions admob/src/ios/admob_ios.mm
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,14 @@ static AdapterInitializationStatus PopulateAdapterInitializationStatus(

bool IsInitialized() { return g_initialized; }

void DisableSDKCrashReporting() {
[GADMobileAds.sharedInstance disableSDKCrashReporting];
}

void DisableMediationInitialization() {
[GADMobileAds.sharedInstance disableMediationInitialization];
}

void SetRequestConfiguration(const RequestConfiguration& request_configuration)
{
GADMobileAds.sharedInstance.requestConfiguration.testDeviceIdentifiers =
Expand Down
4 changes: 4 additions & 0 deletions admob/src/stub/admob_stub.cc
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,10 @@ AdapterInitializationStatus GetInitializationStatus() {
}
}

void DisableSDKCrashReporting() {}

void DisableMediationInitialization() {}

bool IsInitialized() { return g_initialized; }

void SetRequestConfiguration(
Expand Down
4 changes: 2 additions & 2 deletions app/src/util_ios.h
Original file line number Diff line number Diff line change
Expand Up @@ -195,8 +195,8 @@ NSMutableArray *StringVectorToNSMutableArray(

// Convert a NSArray into a vector of strings. Asserts if a non NSString
// object is found in the array.
void NSArrayOfNSStringToVectorOfString(NSArray* array,
std::vector<std::string>* string_vector);
void NSArrayOfNSStringToVectorOfString(NSArray *array,
std::vector<std::string> *string_vector);
Copy link
Contributor Author

@DellaBitta DellaBitta Dec 1, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

#include <vector> is indeed at the top of this file.

... fixed.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably the linter either doesn't know that OBJC will be defined, you could move the c++-specific includes outside of that ifdef. Or just ignore.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed.


// Convert a string map to NSDictionary.
NSDictionary *StringMapToNSDictionary(
Expand Down
13 changes: 6 additions & 7 deletions app/src/util_ios.mm
Original file line number Diff line number Diff line change
Expand Up @@ -161,21 +161,20 @@ void ForEachAppDelegateClass(void (^block)(Class)) {
return array;
}

void NSArrayOfNSStringToVectorOfString(NSArray* array, std::vector<std::string>* string_vector) {
void NSArrayOfNSStringToVectorOfString(NSArray *array, std::vector<std::string> *string_vector) {
string_vector->reserve(array.count);
for (id object in array) {
if(![object isKindOfClass:[NSString class]]) {
if (![object isKindOfClass:[NSString class]]) {
FIREBASE_ASSERT_MESSAGE(false, "Object in Array is not of type NSString");
} else {
string_vector->push_back(NSStringToString((NSString*)object));
string_vector->push_back(NSStringToString((NSString *)object));
}
}
}

NSMutableArray* StdVectorToNSMutableArray(const std::vector<Variant>& vector) {
NSMutableArray* array =
[[NSMutableArray alloc] initWithCapacity:vector.size()];
for (auto& variant : vector) {
NSMutableArray *StdVectorToNSMutableArray(const std::vector<Variant> &vector) {
NSMutableArray *array = [[NSMutableArray alloc] initWithCapacity:vector.size()];
for (auto &variant : vector) {
[array addObject:VariantToId(variant)];
}
return array;
Expand Down