So Ive been trying for over a week to get the google user messaging platform to work (a question that's going to pop up all over the place in the next few weeks/mponths). The problem is that the start guid is written in obj C and I can't understand it! Ive managed to insert the obj C code into my swift project and it runs but causes an exception when it tries to present the form. I think this is because its a .m file and its trying to present the form from self and as 'self' isn't a view controller then it crashes? The obj C Code (as recommended in the google site) is here:
#import "CustomObject.h"
@implementation CustomObject
- (void) someMethod {
// Create a UMPRequestParameters object.
UMPRequestParameters *parameters = [[UMPRequestParameters alloc] init];
// Set tag for under age of consent. Here NO means users are not under age.
parameters.tagForUnderAgeOfConsent = NO;
// Request an update to the consent information.
[UMPConsentInformation.sharedInstance
requestConsentInfoUpdateWithParameters:parameters
completionHandler:^(NSError *_Nullable error) {
if (error) {
// Handle the error.
} else {
// The consent information state was updated.
// You are now ready to check if a form is
// available.
UMPFormStatus formStatus = UMPConsentInformation.sharedInstance.formStatus;
if (formStatus == UMPFormStatusAvailable) {
[self loadForm];
}
}
}];
}
-(void) loadForm {
[UMPConsentForm loadWithCompletionHandler:^(UMPConsentForm *form, NSError *loadError) {
if (loadError) {
// Handle the error
} else {
// Present the form. You can also hold on to the reference to present
// later.
if (UMPConsentInformation.sharedInstance.consentStatus ==
UMPConsentStatusRequired) {
[form
presentFromViewController: self
completionHandler:^(NSError *_Nullable dismissError) {
if (UMPConsentInformation.sharedInstance.consentStatus ==
UMPConsentStatusObtained) {
// App can start requesting ads.
}
}];
} else {
// Keep the form available for changes to user consent.
}
}
}];
}
@end
Im pulling my hair out here. What I really need is either a. A conversion of this code into swift so I can understand it OR b. can anyone suggest what I need to do to the presentfromviewcontroller function to stop it throwing an exception and present a form?
Thanks.....