Google用户消息传递平台和目标C迅速发展

问题描述

因此,我已经尝试了一个多星期,以使google用户消息传递平台正常工作(这个问题将在接下来的几周/每秒钟内弹出)。 问题是起始guid是用obj C编写的,我听不懂! 香港专业教育学院设法将obj C代码插入到我的swift项目中,它可以运行,但在尝试呈现表单时会导致异常。 我认为这是因为它是一个.m文件,并且试图通过self呈现表单,并且因为'self'不是视图控制器,所以它崩溃了? obj C代码(根据Google网站的建议)在这里

#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

在这里拔头发。 我真正需要的是 一种。将此代码转换快速代码,以便我理解或 b。有人可以建议我需要对presentfromviewcontroller函数进行哪些操作,以阻止它引发异常并提交表单吗?

谢谢.....

解决方法

好的,因此对我的问题没有任何反应,我终于设法通过将obj c转换为swift使它起作用。 认为将其发布在此处会很有帮助,以防其他人在同一问题上苦苦挣扎。 这是我想出的代码。将这两个函数添加到视图控制器中,然后从viewdidload调用第一个函数。 注释掉的位是调试集,可让您尝试其他地理位置等以确保其正常工作。 该代码有效,但我不太擅长快速操作,因此请随时指出错误或纠正错误。 不要忘记在顶部添加导入userMessagingPlatform ...

Index