Skip to content
This repository has been archived by the owner on Oct 21, 2022. It is now read-only.

Commit

Permalink
Version v1.0.1 of the Consent SDK.
Browse files Browse the repository at this point in the history
  • Loading branch information
rampara committed May 25, 2018
1 parent 759473b commit e4d987e
Show file tree
Hide file tree
Showing 6 changed files with 75 additions and 33 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
archiveVersion = 1;
classes = {
};
objectVersion = 50;
objectVersion = 48;
objects = {

/* Begin PBXBuildFile section */
Expand Down Expand Up @@ -142,11 +142,12 @@
TargetAttributes = {
5A92D29E2076961800FFE51D = {
CreatedOnToolsVersion = 9.3;
ProvisioningStyle = Automatic;
};
};
};
buildConfigurationList = 5A92D2992076961800FFE51D /* Build configuration list for PBXProject "PersonalizedAdConsent" */;
compatibilityVersion = "Xcode 9.3";
compatibilityVersion = "Xcode 8.0";
developmentRegion = en;
hasScannedForEncodings = 0;
knownRegions = (
Expand Down Expand Up @@ -316,11 +317,7 @@
INFOPLIST_FILE = PersonalizedAdConsent/Info.plist;
INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks";
IPHONEOS_DEPLOYMENT_TARGET = 7.0;
LD_RUNPATH_SEARCH_PATHS = (
"$(inherited)",
"@executable_path/Frameworks",
"@loader_path/Frameworks",
);
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
MACH_O_TYPE = staticlib;
MODULEMAP_FILE = "$(SRCROOT)/PersonalizedAdConsent/module.modulemap";
PRODUCT_BUNDLE_IDENTIFIER = com.google.PersonalizedAdConsent;
Expand All @@ -343,11 +340,7 @@
INFOPLIST_FILE = PersonalizedAdConsent/Info.plist;
INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks";
IPHONEOS_DEPLOYMENT_TARGET = 7.0;
LD_RUNPATH_SEARCH_PATHS = (
"$(inherited)",
"@executable_path/Frameworks",
"@loader_path/Frameworks",
);
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
MACH_O_TYPE = staticlib;
MODULEMAP_FILE = "$(SRCROOT)/PersonalizedAdConsent/module.modulemap";
PRODUCT_BUNDLE_IDENTIFIER = com.google.PersonalizedAdConsent;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@

#import <UIKit/UIKit.h>

/// Personalized ad consent SDK version string.
extern NSString *_Nonnull const PACVersionString;

/// Personalized ad consent error domain.
extern NSErrorDomain _Nonnull const PACErrorDomain;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,11 @@ @interface PACAdProvider ()
- (nullable instancetype)initWithDictionary:(nullable NSDictionary<NSString *, id> *)dictionary;
@end

NSString *const PACVersionString = @"1.0.1";
NSString *const PACUserDefaultsRootKey = @"personalized_ad_status";

static NSString *const PACInfoUpdateURLFormat =
@"https://adservice.google.com/getconfig/pubvendors?es=2&pubs=%@";
@"https://adservice.google.com/getconfig/pubvendors?es=2&plat=ios&v=%@&pubs=%@";

typedef NSString *PACStoreKey NS_STRING_ENUM;
static PACStoreKey const PACStoreKeyTaggedForUnderAgeOfConsent = @"tag_for_under_age_of_consent";
Expand All @@ -44,6 +45,8 @@ - (nullable instancetype)initWithDictionary:(nullable NSDictionary<NSString *, i
static PACStoreKey const PACStoreKeyConsentedProviders = @"consented_providers";
static PACStoreKey const PACStoreKeyRawResponse = @"raw_response";
static PACStoreKey const PACStoreKeyIsRequestInEEAOrUnknown = @"is_request_in_eea_or_unknown";
static PACStoreKey const PACStoreKeyVersionString = @"version";
static PACStoreKey const PACStoreKeyPlatform = @"plat";

typedef NSString *PACConsentStatusString NS_STRING_ENUM;
static PACConsentStatusString const PACConsentStatusStringUnknown = @"unknown";
Expand Down Expand Up @@ -236,6 +239,8 @@ - (void)writeStatusToUserDefaults {
PAC_MUST_BE_MAIN_THREAD();

NSDictionary<PACStoreKey, id> *personalizedAdStatus = @{
PACStoreKeyVersionString : PACVersionString,
PACStoreKeyPlatform : @"ios",
PACStoreKeyTaggedForUnderAgeOfConsent : _tagForUnderAgeOfConsent ? @1 : @0,
PACStoreKeyIsRequestInEEAOrUnknown : _isRequestInEEAOrUnknown ? @1 : @0,
PACStoreKeyHasAnyNonPersonalizedPublisherIdentifier :
Expand Down Expand Up @@ -267,8 +272,8 @@ - (nullable NSURL *)infoUpdateURLForPublisherIdentifiers:
if (!publisherIdentifierString.length) {
publisherIdentifierString = @"";
}
NSString *infoUpdateURLString =
[[NSString alloc] initWithFormat:PACInfoUpdateURLFormat, publisherIdentifierString];
NSString *infoUpdateURLString = [[NSString alloc]
initWithFormat:PACInfoUpdateURLFormat, PACVersionString, publisherIdentifierString];

if ([self debugModeEnabled]) {
NSString *debugGeographyParam = @"";
Expand Down
1 change: 1 addition & 0 deletions PersonalizedAdConsent/PersonalizedAdConsent/PACView.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ static PACFormKey const PACFormKeyAppPrivacyPolicyURLString = @"app_privacy_url"
static PACFormKey const PACFormKeyConstentInfo = @"consent_info";
static PACFormKey const PACFormKeyAppName = @"app_name";
static PACFormKey const PACFormKeyAppIcon = @"app_icon";
static PACFormKey const PACFormKeyPlatform = @"plat";

/// Loads and displays the consent form.
@interface PACView : UIView<UIWebViewDelegate>
Expand Down
43 changes: 31 additions & 12 deletions PersonalizedAdConsent/PersonalizedAdConsent/PACView.m
Original file line number Diff line number Diff line change
Expand Up @@ -162,31 +162,49 @@ - (instancetype)initWithFrame:(CGRect)frame {
- (void)loadWithFormInformation:(nonnull NSDictionary<PACFormKey, id> *)formInformation
completionHandler:(nonnull PACLoadCompletion)handler {
formInformation = [formInformation copy];
PACLoadCompletion wrappedHandler = ^(NSError *_Nullable error) {
if (handler) {
handler(error);
}
};
dispatch_async(dispatch_get_main_queue(), ^{
if (self->_loadCompletionHandler) {
// In progress.
NSError *error = PACErrorWithDescription(@"Another load is in progress.");
if (handler) {
handler(error);
}
wrappedHandler(error);
return;
}
self->_formInformation = formInformation;
self->_loadCompletionHandler = ^(NSError *_Nullable error) {
if (handler) {
handler(error);
}
};
self->_loadCompletionHandler = wrappedHandler;
[self loadWebView];
});
}

/// Returns the resource bundle located within |bundle|.
- (nullable NSBundle *)resourceBundleForBundle:(nonnull NSBundle *)bundle {
NSURL *resourceBundleURL =
[bundle URLForResource:@"PersonalizedAdConsent" withExtension:@"bundle"];
if (resourceBundleURL) {
return [NSBundle bundleWithURL:resourceBundleURL];
}
return nil;
}

/// Loads the consent form HTML into the web view.
- (void)loadWebView {
NSURL *bundleURL =
[[NSBundle mainBundle] URLForResource:@"PersonalizedAdConsent" withExtension:@"bundle"];
NSBundle *bundle = [NSBundle bundleWithURL:bundleURL];
NSURL *URL = [bundle URLForResource:@"consentform" withExtension:@"html"];
NSBundle *bundle = [NSBundle bundleForClass:[self class]];
NSBundle *resourceBundle = [self resourceBundleForBundle:bundle];
if (!resourceBundle) {
resourceBundle = [self resourceBundleForBundle:[NSBundle mainBundle]];
}
if (!resourceBundle) {
NSError *error =
PACErrorWithDescription(@"Resource bundle not found. Ensure the resource bundle is "
@"packaged with your application or framework bundle.");
[self loadCompletedWithError:error];
return;
}
NSURL *URL = [resourceBundle URLForResource:@"consentform" withExtension:@"html"];
NSURLRequest *URLRequest = [[NSURLRequest alloc] initWithURL:URL];
[_webView loadRequest:URLRequest];
}
Expand All @@ -198,6 +216,7 @@ - (void)updateWebViewInformation {
[self->_formInformation mutableCopy];
mutableFormInformation[PACFormKeyAppName] = PACShortAppName();
mutableFormInformation[PACFormKeyAppIcon] = PACIconDataURIString();
mutableFormInformation[PACFormKeyPlatform] = @"ios";

NSString *infoString = PACJSONStringForDictionary(mutableFormInformation);
NSString *command = PACCreateJavaScriptCommandString(@"setUpConsentDialog", @{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -600,16 +600,37 @@
var infoJSON = args['info'] || '';

var formInfo;
var consentInfo;
var rawResponseJSON;
var rawResponse;
try {
formInfo = JSON.parse(infoJSON) || {};
consentInfo = formInfo['consent_info'] || {};
rawResponseJSON = consentInfo['raw_response'] || '';
} catch(e) {
formLoadCompleted('Error: consent SDK passed invalid data to the ' +
'consent form. ' + e.message);
return;
}

var consentInfo = formInfo['consent_info'] || {};
var rawResponseJSON = consentInfo['raw_response'] || '';

if (!rawResponseJSON) {
var method;
if (formInfo['plat'] === 'ios') {
method = '-[PACConsentInformation ' +
'requestConsentInfoUpdateForPublisherIdentifiers:completionHandler:]';
} else {
method = 'com.google.ads.consent.ConsentInformation.requestConsentInfoUpdate()';
}
var message = 'Error: no information available. Successful call to ' +
method + ' required before using this form.';
formLoadCompleted(message);
return;
}

var rawResponse;
try {
rawResponse = JSON.parse(rawResponseJSON) || {};
} catch(e) {
formLoadCompleted('Error: invalid data. ' + e.message);
formLoadCompleted('Error: consent form received invalid data from ' +
'the consent server. ' + e.message);
return;
}

Expand Down

0 comments on commit e4d987e

Please sign in to comment.