首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Google统一消息平台SDK实现

Google统一消息平台SDK实现
EN

Stack Overflow用户
提问于 2020-08-22 09:34:34
回答 1查看 1.1K关注 0票数 1

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

我使用Xcode vs 11.6,并从戈多游戏引擎导出游戏。

我在我的info.plist中更改了info.plist,我的代码中没有任何错误,只是在运行游戏时没有显示表单。我住在欧洲。任何帮助都是非常感谢的。

这是我目前的代码:

代码语言:javascript
复制
#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];
                                   }
                               }
                             }];
    
}
- (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 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];
                                   }
                               }
                             }];
    [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 (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
EN

回答 1

Stack Overflow用户

发布于 2020-08-23 10:37:22

编辑

添加几个NSLog来查看调用什么。

试一试-只是一块石头插进灌木丛,也许它撞到了什么东西.

代码语言:javascript
复制
#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

注意,如果这是可行的,它可能需要更多的抛光,然后才能发布到世界上,但希望至少请求表格将显示.

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/63534686

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档