Skip to content

Commit

Permalink
Merge pull request #355 from Astrovic/master
Browse files Browse the repository at this point in the history
[iOS] Migration to Google Mobile Ads SDK 11
  • Loading branch information
hansemannn committed Mar 4, 2024
2 parents 6df5993 + a77568a commit 74d293b
Show file tree
Hide file tree
Showing 772 changed files with 86,292 additions and 32,523 deletions.
26 changes: 25 additions & 1 deletion apidoc/Admob.yml
Original file line number Diff line number Diff line change
Expand Up @@ -307,6 +307,9 @@ properties:
summary: The deviceId for emulators to be used with <Modules.Admob.View.testDevices> property
permission: read-only
platforms: [android, iphone, ipad]
deprecated:
since: "7.0.0"
notes: Simulators are already in test mode by default.

- name: TRACKING_AUTHORIZATION_STATUS_NOT_DETERMINED
type: Number
Expand Down Expand Up @@ -444,6 +447,27 @@ methods:
type: Callback<LoadFormObject>
summary: async callback called when retrieved

- name: isGDPR
returns:
type: Boolean
summary: Check in the IABTCF string if GDPR applies, so if in EEA.
platforms: [iphone, ipad]
since: "6.3.0"

- name: canShowAds
returns:
type: Boolean
summary: Check in the IABTCF string if user granted at least minimum requirements to show ads.
platforms: [iphone, ipad]
since: "6.3.0"

- name: canShowPersonalizedAds
returns:
type: Boolean
summary: Check in the IABTCF string if user granted at least minimum requirements to show Personalized ads.
platforms: [iphone, ipad]
since: "6.3.0"

- name: requestConsentInfoUpdateForPublisherIdentifiers
returns:
type: void
Expand Down Expand Up @@ -697,7 +721,7 @@ objects:

- name: testDeviceIdentifiers
type: Array<String>
summary: Array of "TEST-DEVICE-HASHED-ID" strings. You can use Admob.SIMULATOR_ID for simulator.
summary: Array of "TEST-DEVICE-HASHED-ID" strings.
optional: true

- name: callback
Expand Down
2 changes: 1 addition & 1 deletion apidoc/LoadOptions.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,4 @@ properties:

- name: testDevices
type: Array<String>
summary: Test ads will be returned for devices with device IDs specified in this array. Use AdMob.SIMULATOR_ID to add the simulator.
summary: Test ads will be returned for devices with device IDs specified in this array.
52 changes: 40 additions & 12 deletions apidoc/View.yml
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ properties:
type: Array<String>
summary: An array of test device ids. Adding the id of a test device to this array will allow that device to be served test ads.
description: |
Use the module constant `SIMULATOR_ID` to use the simulator as a test device.
If you do not know the id for your device, launch your app and request an ad
like you normally would, then look in the console for the id.
Expand Down Expand Up @@ -109,18 +108,47 @@ properties:
- name: tagForChildDirectedTreatment
type: Boolean
summary: his property allows you to specify whether you would like your app to be treated as child-directed for purposes of the Children's Online Privacy Protection Act (COPPA), http:///business.ftc.gov/privacy-and-security/childrens-privacy.
summary: his property allows you to specify whether you would like your app to be treated as child-directed for purposes of the Children's Online Privacy Protection Act (COPPA), https://www.ftc.gov/business-guidance/privacy-security/childrens-privacy.
description: |
If you call this method with `true`, you are indicating that your app should be treated as child-directed for purposes of the
Children's Online Privacy Protection Act (COPPA). If you call this method with NO, you are indicating that your app should
not be treated as child-directed for purposes of the Children's Online Privacy Protection Act (COPPA). If you do not call this
method, ad requests will include no indication of how you would like your app treated with respect to COPPA.
By setting this method, you certify that this notification is accurate and you are authorized to act on behalf of the owner of
the app. You understand that abuse of this setting may result in termination of your Google account.
It may take some time for this designation to be fully implemented in applicable Google services. This designation will
only apply to ad requests for which you have set this method.
For purposes of the [Children's Online Privacy Protection Act (COPPA)](https://www.ftc.gov/business-guidance/privacy-security/childrens-privacy), there is a setting called tagForChildDirectedTreatment.
As an app developer, you can indicate whether you want Google to treat your content as child-directed when you make an ad request. When you indicate that you want Google to treat your content as child-directed, Google takes steps to disable IBA and remarketing ads on that ad request. The setting options are as follows:
- Set `tagForChildDirectedTreatment` to `true` to indicate that you want your content treated as child-directed for purposes of COPPA. This prevents the transmission of the Advertising Identifier, IDFA.
- Set `tagForChildDirectedTreatment` to `false` to indicate that you don't want your content treated as child-directed for purposes of COPPA.
- Don't set `tagForChildDirectedTreatment` if you don't want to indicate how you would like your content treated with respect to COPPA.
By setting this tag, you certify that this notification is accurate and you are authorized to act on behalf of the owner of the app. You understand that abuse of this setting may result in termination of your Google Account.
platforms: [iphone, ipad]

- name: tagForUnderAgeOfConsent
type: Boolean
summary: his property allows you to specify whether you would like your app to be treated as users in the European Economic Area (EEA) under the age of consent, https://eur-lex.europa.eu/legal-content/EN/TXT/?uri=CELEX:32016R0679.
description: |
You can mark your ad requests to receive treatment for users in the European Economic Area (EEA) under the age of consent. This feature is designed to help facilitate compliance with the [General Data Protection Regulation (GDPR)](https://eur-lex.europa.eu/legal-content/EN/TXT/?uri=CELEX:32016R0679). Note that you may have other legal obligations under GDPR. Review the European Union’s guidance and consult with your own legal counsel. Note that Google's tools are designed to facilitate compliance and do not relieve any particular publisher of its obligations under the law. [Learn more about how the GDPR affects publishers](https://support.google.com/admob/answer/7666366).
When using this feature, a Tag For Users under the Age of Consent in Europe (TFUA) parameter will be included in all future ad requests. This parameter disables personalized advertising, including remarketing, for that specific ad request. It also disables requests to third-party ad vendors, such as ad measurement pixels and third-party ad servers.
The setting can be used with all versions of the Google Mobile Ads SDK by setting the `tagForUnderAgeOfConsent` property on the GADMobileAds.requestConfiguration object and passing in `true`.
- Set `tagForUnderAgeOfConsent` to `true` to indicate that you want ad requests to be handled in a manner suitable for users under the age of consent. This also prevents the transmission of the Advertising Identifier, IDFA.
- Not setting `tagForUnderAgeOfConsent` indicates that you don't want ad requests to be handled in a manner suitable for users under the age of consent.
The tags to enable the `tagForChildDirectedTreatmentsetting` and `tagForUnderAgeOfConsent` shouldn't both simultaneously be set to `true`. If they are, the child-directed setting takes precedence.
platforms: [iphone, ipad]
since: 7.0.0

- name: maxAdContentRating
type: String
summary: his property allows you to specify a maximum ad content rating.
description: |
Apps can set a maximum ad content rating for all ad requests using the `maxAdContentRating` property. This setting applies to all future ad requests for the remainder of the session. The possible values for this property are based on [digital content label classifications](https://support.google.com/admob/answer/7562142), and should be one of the following Admob module constants:
- `MAX_AD_CONTENT_RATING_GENERAL`
- `MAX_AD_CONTENT_RATING_PARENTAL_GUIDANCE`
- `MAX_AD_CONTENT_RATING_TEEN`
- `MAX_AD_CONTENT_RATING_MATURE_AUDIENCE`
platforms: [iphone, ipad]
since: 7.0.0

events:
- name: didReceiveAd
Expand Down
8 changes: 8 additions & 0 deletions ios/Classes/StatusBarHiddenViewController.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#import <UIKit/UIKit.h>
#import <GoogleMobileAds/GoogleMobileAds.h>

@interface StatusBarHiddenViewController : UIViewController

@property (nonatomic, strong) GADAppOpenAd *ad;

@end
16 changes: 16 additions & 0 deletions ios/Classes/StatusBarHiddenViewController.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#import "StatusBarHiddenViewController.h"

@implementation StatusBarHiddenViewController

- (BOOL)prefersStatusBarHidden {
return YES;
}

- (void)viewDidAppear:(BOOL)animated {
[super viewDidAppear:animated];

// Present the ad here
[self.ad presentFromRootViewController:self];
}

@end
6 changes: 6 additions & 0 deletions ios/Classes/TiAdmobModule.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,12 @@

- (void)loadForm:(id)args;

- (NSNumber *)isGDPR:(id)unused;

- (NSNumber *)canShowAds:(id)unused;

- (NSNumber *)canShowPersonalizedAds:(id)unused;

- (void)requestConsentInfoUpdateForPublisherIdentifiers:(id)args; // REMOVED

- (void)showConsentForm:(id)args; // REMOVED
Expand Down
92 changes: 88 additions & 4 deletions ios/Classes/TiAdmobModule.m
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,85 @@ - (void)requestConsentInfoUpdateForPublisherIdentifiers:(id)args
*/
}

/**
* This functions check if the user has granted the minimum requirements to be able to view the ads,
* (https://support.google.com/admob/answer/9760862?ref_topic=10303737) and if he has chosen to see
* personalized or non-personalized ones.
*
* Inspired by https://stackoverflow.com/questions/65351543/how-to-implement-ump-sdk-correctly-for-eu-consent/68310602#68310602
*/

- (NSNumber *)isGDPR:(id)unused
{
NSUserDefaults *settings = [NSUserDefaults standardUserDefaults];
NSInteger gdpr = [settings integerForKey:@"IABTCF_gdprApplies"];
return @(gdpr == 1);
}

- (NSNumber *)canShowAds:(id)unused
{
NSUserDefaults *settings = [NSUserDefaults standardUserDefaults];

NSString *purposeConsent = [settings stringForKey:@"IABTCF_PurposeConsents"] ?: @"";
NSString *vendorConsent = [settings stringForKey:@"IABTCF_VendorConsents"] ?: @"";
NSString *vendorLI = [settings stringForKey:@"IABTCF_VendorLegitimateInterests"] ?: @"";
NSString *purposeLI = [settings stringForKey:@"IABTCF_PurposeLegitimateInterests"] ?: @"";

NSInteger googleId = 755;
BOOL hasGoogleVendorConsent = [self hasAttribute:vendorConsent atIndex:googleId];
BOOL hasGoogleVendorLI = [self hasAttribute:vendorLI atIndex:googleId];

return @([self hasConsentFor:@[@(1)] purposeConsent:purposeConsent hasVendorConsent:hasGoogleVendorConsent]
&& [self hasConsentOrLegitimateInterestFor:@[@(2), @(7), @(9), @(10)] purposeConsent:purposeConsent purposeLI:purposeLI hasVendorConsent:hasGoogleVendorConsent hasVendorLI:hasGoogleVendorLI]);
}

- (NSNumber *)canShowPersonalizedAds:(id)unused
{
NSUserDefaults *settings = [NSUserDefaults standardUserDefaults];

NSString *purposeConsent = [settings stringForKey:@"IABTCF_PurposeConsents"] ?: @"";
NSString *vendorConsent = [settings stringForKey:@"IABTCF_VendorConsents"] ?: @"";
NSString *vendorLI = [settings stringForKey:@"IABTCF_VendorLegitimateInterests"] ?: @"";
NSString *purposeLI = [settings stringForKey:@"IABTCF_PurposeLegitimateInterests"] ?: @"";

NSInteger googleId = 755;
BOOL hasGoogleVendorConsent = [self hasAttribute:vendorConsent atIndex:googleId];
BOOL hasGoogleVendorLI = [self hasAttribute:vendorLI atIndex:googleId];

return @([self hasConsentFor:@[@(1), @(3), @(4)] purposeConsent:purposeConsent hasVendorConsent:hasGoogleVendorConsent]
&& [self hasConsentOrLegitimateInterestFor:@[@(2), @(7), @(9), @(10)] purposeConsent:purposeConsent purposeLI:purposeLI hasVendorConsent:hasGoogleVendorConsent hasVendorLI:hasGoogleVendorLI]);
}

- (BOOL)hasAttribute:(NSString *)input atIndex:(NSInteger)index
{
return input.length >= index && [[input substringWithRange:NSMakeRange(index - 1, 1)] isEqualToString:@"1"];
}

- (BOOL)hasConsentFor:(NSArray *)purposes purposeConsent:(NSString *)purposeConsent hasVendorConsent:(BOOL)hasVendorConsent
{
for (NSNumber *purpose in purposes) {
NSInteger i = [purpose integerValue];
if (![self hasAttribute:purposeConsent atIndex:i]) {
return NO;
}
}
return hasVendorConsent;
}

- (BOOL)hasConsentOrLegitimateInterestFor:(NSArray *)purposes purposeConsent:(NSString *)purposeConsent purposeLI:(NSString *)purposeLI hasVendorConsent:(BOOL)hasVendorConsent hasVendorLI:(BOOL)hasVendorLI
{
for (NSNumber *purpose in purposes) {
NSInteger i = [purpose integerValue];
if (([self hasAttribute:purposeLI atIndex:i] && hasVendorLI) ||
([self hasAttribute:purposeConsent atIndex:i] && hasVendorConsent)) {
continue;
} else {
return NO;
}
}
return YES;
}

- (void)showConsentForm:(id)args
{
DEPRECATED_REMOVED(@"Admob.showConsentForm", @"5.0.0", @"5.0.0 (Removed since Ti.Admob 5.0.0 in favor of new UMP method Admob.requestConsentInfoUpdateWithParameters())");
Expand Down Expand Up @@ -305,7 +384,7 @@ - (void)resetConsent:(id)unused

- (void)setTagForUnderAgeOfConsent:(id)tagForUnderAgeOfConsent
{
DEPRECATED_REMOVED(@"Admob.setTagForUnderAgeOfConsent", @"5.0.0", @"5.0.0 (Removed since Ti.Admob 5.0.0. You can set 'tagForUnderAgeOfConsent' parameter in Admob.requestConsentInfoUpdateWithParameters() )");
DEPRECATED_REMOVED(@"Admob.setTagForUnderAgeOfConsent", @"5.0.0", @"5.0.0 (Removed since Ti.Admob 5.0.0. You can set 'tagForUnderAgeOfConsent' parameter in Admob.requestConsentInfoUpdateWithParameters() or in Admob.createView() )");
/*
ENSURE_TYPE(tagForUnderAgeOfConsent, NSNumber);
[[PACConsentInformation sharedInstance] setTagForUnderAgeOfConsent:[TiUtils boolValue:tagForUnderAgeOfConsent]];
Expand All @@ -314,7 +393,7 @@ - (void)setTagForUnderAgeOfConsent:(id)tagForUnderAgeOfConsent

- (NSNumber *)isTaggedForUnderAgeOfConsent:(id)unused
{
DEPRECATED_REMOVED(@"Admob.isTaggedForUnderAgeOfConsent", @"5.0.0", @"5.0.0 (Removed since Ti.Admob 5.0.0. You can set 'tagForUnderAgeOfConsent' parameter in Admob.requestConsentInfoUpdateWithParameters() )");
DEPRECATED_REMOVED(@"Admob.isTaggedForUnderAgeOfConsent", @"5.0.0", @"5.0.0 (Removed since Ti.Admob 5.0.0. You can set 'tagForUnderAgeOfConsent' parameter in Admob.requestConsentInfoUpdateWithParameters() or in Admob.createView() )");
//return @([[PACConsentInformation sharedInstance] isTaggedForUnderAgeOfConsent]);
}

Expand Down Expand Up @@ -374,11 +453,11 @@ - (void)setInMobi_updateGDPRConsent:(id)updateGDPRConsent
if ([TiUtils boolValue:updateGDPRConsent]) {
// this method is required by InMobi to set GDPR
[consentObject setObject:@"1" forKey:@"gdpr"];
[consentObject setObject:@"true" forKey:IM_GDPR_CONSENT_AVAILABLE];
[consentObject setObject:@"true" forKey:IMCommonConstants.IM_GDPR_CONSENT_AVAILABLE];
NSLog(@"[DEBUG] Ti.AdMob: inMobi_updateGDPRConsent --> true");
} else {
[consentObject setObject:@"0" forKey:@"gdpr"];
[consentObject setObject:@"true" forKey:IM_GDPR_CONSENT_AVAILABLE];
[consentObject setObject:@"true" forKey:IMCommonConstants.IM_GDPR_CONSENT_AVAILABLE];
NSLog(@"[DEBUG] Ti.AdMob: inMobi_updateGDPRConsent --> false");
}

Expand Down Expand Up @@ -421,4 +500,9 @@ - (void)setInMobi_updateGDPRConsent:(id)updateGDPRConsent
MAKE_SYSTEM_PROP(AD_TYPE_REWARDED_VIDEO, TiAdmobAdTypeRewardedVideo);
MAKE_SYSTEM_PROP(AD_TYPE_APP_OPEN, TiAdmobAdTypeAppOpen);

MAKE_SYSTEM_STR(MAX_AD_CONTENT_RATING_GENERAL, GADMaxAdContentRatingGeneral);
MAKE_SYSTEM_STR(MAX_AD_CONTENT_RATING_PARENTAL_GUIDANCE, GADMaxAdContentRatingParentalGuidance);
MAKE_SYSTEM_STR(MAX_AD_CONTENT_RATING_TEEN, GADMaxAdContentRatingTeen);
MAKE_SYSTEM_STR(MAX_AD_CONTENT_RATING_MATURE_AUDIENCE, GADMaxAdContentRatingMatureAudience);

@end
24 changes: 24 additions & 0 deletions ios/Classes/TiAdmobModuleAssets.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/**
* This is a generated file. Do not edit or your changes will be lost
*/
#import "TiAdmobModuleAssets.h"

extern NSData* filterDataInRange(NSData* thedata, NSRange range);

@implementation TiAdmobModuleAssets

- (NSData *)moduleAsset
{


return nil;
}

- (NSData *)resolveModuleAsset:(NSString *)path
{


return nil;
}

@end
4 changes: 4 additions & 0 deletions ios/Classes/TiAdmobView.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@

- (void)setTagForChildDirectedTreatment_:(id)value;

- (void)setTagForUnderAgeOfConsent_:(id)value;

- (void)setMaxAdContentRating_:(NSString *)maxAdContentRating;

- (void)setRequestAgent_:(id)value;

- (void)setContentURL_:(id)value;
Expand Down
Loading

0 comments on commit 74d293b

Please sign in to comment.