如果 (r.getData()) 需要数据类型 boolean,则在 OneSignal 中显示错误

问题描述 投票:0回答:1

OneSignal.getNotifications().requestPermission(Continue.with(r -> {

        if (r.isSuccess()) {
            if (r.getData()) {
                // `requestPermission` completed successfully and the user has accepted permission
            }
            else {
                // `requestPermission` completed successfully but the user has rejected permission
            }
        }
        else {
            // `requestPermission` completed unsuccessfully, check `r.getThrowable()` for more info on the failure reason
        }
    }));

所需类型:布尔值 提供:对象

如何解决android studio项目中的信号实现问题

push onesignal
1个回答
0
投票

我遇到了类似的问题,错误是:

MainApplication.java:91: error: cannot find symbol
    OneSignal.getNotifications().requestPermission(Continue.with(r -> {
                                                   ^
  symbol:   variable Continue
  location: class MainApplication

修复方法是将这段代码完全注释掉,如代码上方的注释所示:

    // requestPermission will show the native iOS notification permission prompt.
    // We recommend removing the following code and instead using an In-App Message to prompt for notification permission

不幸的是,文档已过时,此评论不正确,因为它提到了“本机 iOS 通知权限提示”。

考虑到这是 Android,这很可能是“复制粘贴”,他们只是复制并粘贴了大部分代码和文档,并且没有非常仔细地校对。

无论如何,注释掉此部分允许构建 android 版本。 (我正在使用 React Native)。

或者更好的是,您甚至可以删除代码,尽管您需要找出提示用户通知权限的正确方法。

这是我注释掉的原始代码:

   // OneSignal.getNotifications().requestPermission(Continue.with(r -> {
    //     if (r.isSuccess()) {
    //       if (r.getData()) {
    //         // `requestPermission` completed successfully and the user has accepted permission
    //       }
    //       else {
    //         // `requestPermission` completed successfully but the user has rejected permission
    //       }
    //     }
    //     else {
    //       // `requestPermission` completed unsuccessfully, check `r.getThrowable()` for more info on the failure reason
    //     }
    // }));    
© www.soinside.com 2019 - 2024. All rights reserved.