Google统一消息平台SDK实施

问题描述

我想知道如何在iOS应用https://developers.google.com/admob/ump/ios/quick-start显示表单。

我正在使用Xcode vs 11.6,并从Godot游戏引擎中导出了游戏。

我已经更改了GADApplicationIdentifier中的info.plist,并且在我的代码中没有出现任何错误,只是在我运行游戏时它没有显示表格。我住在欧洲。任何帮助表示赞赏。

这是我当前的代码

#include <UserMessagingPlatform/UserMessagingPlatform.h>
#import "ViewController1.h"
#include <UserMessagingPlatform/UserMessagingPlatform.h>

@interface ViewController1 ()

@end

@implementation ViewController1
- (void)start {
    // 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 @R_933_4045@ion.
    [UMPConsent@R_933_404[email protected]
        requestConsentInfoUpdateWithParameters:parameters
                             completionHandler:^(NSError *_Nullable error) {
                               if (error) {
                                 // Handle the error.
                               } else {
                                 // The consent @R_933_4045@ion state was updated.
                                 // You are Now ready to check if a form is
                                 // available.
                                UMPFormStatus formStatus =
                                    UMPConsent@R_933_404[email protected]
                                           .formStatus;
                                if (formStatus == UMPFormStatusAvailable) {
                                    [self loadForm];
                                   }
                               }
                             }];
    
}
- (void)viewDidLoad {
    // 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 @R_933_4045@ion.
    [UMPConsent@R_933_404[email protected]
        requestConsentInfoUpdateWithParameters:parameters
                             completionHandler:^(NSError *_Nullable error) {
                               if (error) {
                                 // Handle the error.
                               } else {
                                 // The consent @R_933_4045@ion state was updated.
                                 // You are Now ready to check if a form is
                                 // available.
                                UMPFormStatus formStatus =
                                    UMPConsent@R_933_404[email protected]
                                           .formStatus;
                                if (formStatus == UMPFormStatusAvailable) {
                                    [self loadForm];
                                   }
                               }
                             }];
    [super viewDidLoad];
}

- (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 (UMPConsent@R_933_404[email protected] ==
        UMPConsentStatusrequired) {
      [form
          presentFromViewController:self
                  completionHandler:^(NSError *_Nullable dismissError) {
                    if (UMPConsent@R_933_404[email protected] ==
                        UMPConsentStatusObtained) {
                      // App can start requesting ads.
                    }

                  }];
    } else {
      // Keep the form available for changes to user consent.
    }
  }
}];
}


@end

解决方法

编辑

添加一些NSLog来查看被调用的内容。

尝试以下方法-只是向灌木丛中扔石头,也许它撞到了东西...

#include <UserMessagingPlatform/UserMessagingPlatform.h>
#import "ViewController1.h"
#include <UserMessagingPlatform/UserMessagingPlatform.h>

@interface ViewController1 ()

@end

@implementation ViewController1
- (void)start {
    // 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];
                                   }
                               }
                             }];
    
}

// Change this one
- (void)viewDidLoad {
    [super viewDidLoad];
}


// Add this one
- ( void ) viewDidAppear:( BOOL ) animated {
    [super viewDidAppear:animated];
    // View controller is now visible and on screen,so request permission
    self.addMobStuff;
}

// Change / add this one
- ( void ) addMobStuff {
    NSLog( @"addMobStuff" );
    // 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.
    if ( ! UMPConsentInformation.sharedInstance )
    {
        NSLog(@"No shared instance");
    }
    [UMPConsentInformation.sharedInstance
        requestConsentInfoUpdateWithParameters:parameters
                             completionHandler:^(NSError *_Nullable error) {
                               if (error) {
                                 // Handle the error.
                                 NSLog(@"Some error %@",error);
                               } else {
                                 NSLog(@"Proceed to form ...");
                                 // 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) {
                                    NSLog(@"Loading form ...");
                                    [self loadForm];
                                   }
                                 else {
                                    NSLog(@"Form status is not available");
                                 }
                               }
                             }];
}

- (void)loadForm {
[UMPConsentForm loadWithCompletionHandler:^(UMPConsentForm *form,NSError *loadError) {
  if (loadError) {
    // Handle the error.
    NSLog(@"Form error %@",error);
  } else {
    // Present the form. You can also hold on to the reference to present
    // later.
    if (UMPConsentInformation.sharedInstance.consentStatus ==
        UMPConsentStatusRequired) {
      NSLog(@"Presenting form");
      [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.
      NSLog(@"Changes");
    }
  }
}];
}


@end

请注意,如果此方法可行,则可能需要进一步完善才能发布到世界上,但希望至少可以显示请求表...