【问题标题】:Cannot initialise variable with an rvalue无法用右值初始化变量
【发布时间】:2018-06-05 12:48:42
【问题描述】:

我正在尝试将Google's Consent SDK 集成到 Xcode 项目中,使用以下代码显示从 SDK 生成的同意书:

//show consent form
[form presentFromViewController:_vc
    dismissCompletion:^(NSError *_Nullable error, BOOL userPrefersAdFree) {
    if (error) {
        // Handle error.
    } else if (userPrefersAdFree) {
        // The user prefers to use a paid version of the app.
    } else {
        // Check the user's consent choice.
        PACConsentStatus *status = PACConsentInformation.sharedInstance.consentStatus;
        // ERROR FOR ABOVE LINE
    }
}];

_vc 是我访问 viewController 的方式:

AppDelegate* app = (AppDelegate*)[[UIApplication sharedApplication] delegate];
_vc = app.window.rootViewController;

由于某种原因,我在尝试存储 consentStatus 时似乎收到以下错误:

Cannot initialize a variable of type 'PACConsentStatus *' with an rvalue of type 'PACConsentStatus'

除了v​​iewController的呈现方式之外,我准确地遵循Admob's Guide。 请帮忙。谢谢。

【问题讨论】:

    标签: objective-c xcode initialization admob


    【解决方案1】:

    错误是抱怨您将PACConsentStatus 类型的东西分配给PACConsentStatus* 类型的变量(指向PACConsentStatus 的指针)。 PAConsentStatus 是一个枚举,而不是一个对象。去掉星星:

    PACConsentStatus status = PACConsentInformation.sharedInstance.consentStatus;
    

    【讨论】:

    • 如果我删除指针,它会变成一个未使用的变量并且表单不会加载。
    • 仅仅给一个变量赋值并不会自己做任何事情。我不知道您所说的“表单未加载”是什么意思。我也不知道_vc_consent 是什么。传递给presentFromViewController 有点奇怪(通常你传递self,如链接示例所示)。我也不知道form 是什么,或者它是否非零。我会确保您完全按照链接的示例进行操作(如前所述,您已经进行了更改)。
    • 对不起。该表单是从 Consent SDK 生成的 Consent Dialog 表单。我正在使用一个单独的类,使用指向 viewController 的指针。除此之外,我没有改变任何东西。据我了解,这应该存储许可状态,而不仅仅是将其保存为变量。我会更新我的问题。
    • 关于该问题的任何更新?我遇到了同样的错误。
    • 我能够删除“”并成功加载表单,不确定没有“”是否有任何影响,但它不能使用它,所以必须删除它
    猜你喜欢
    • 1970-01-01
    • 2019-10-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多