Onesignal GDPR 更改未注册设备

Onesignal GDPR changes not registering the device

当我针对 Onesignal 新 GDPR 更改尝试以下步骤时 Onesignal 未注册设备,我不知道是否正确。

第 1 步: 在应用程序 onCreate

if(!OneSignal.userProvidedPrivacyConsent()) {
 OneSignal.setRequiresUserPrivacyConsent(true);
}

第 2 步: 当用户接受条款时,我将设置 provideUserConsent(true)

第 3 步: 在用户接受条款后,我将启动 OneSignal 方法

 OneSignal.startInit(this)
     .setNotificationReceivedHandler(new OneSignalNotificationReceivedHandler())
     .setNotificationOpenedHandler(new OneSignalNotificationOpenedHandler())
     .init();

执行上述步骤后,我将收到这样的日志消息

05-23 11:19:21.790 22460-22460/com.example.app V/OneSignal: OneSignal SDK initialization delayed, user privacy consent is set to required for this application.

05-23 11:19:21.795 22460-22460/com.example.app W/OneSignal: Method idsAvailable() was called before the user provided privacy consent. Your application is set to require the user's privacy consent before the OneSignal SDK can be initialized. Please ensure the user has provided consent before calling this method. You can check the latest OneSignal consent status by calling OneSignal.userProvidedPrivacyConsent()

在 OneSignal 仪表板中收到这样的消息

Google Play services library initialization error. Check for conflicting plugins and make sure "com.google.android.gms.version" is in your AndroidManifest.xml. Check the logcat for more details.

但我在 AndroidManifest.xml

中包含了所有必要的细节
<meta-data
            android:name="com.google.android.gms.version"
            android:value="@integer/google_play_services_version" />

一定是弄错了。

setRequiresUserPrivacyConsent(true) 必须在初始化 OneSignal 之前调用。

示例:

public void onCreate() {
    super.onCreate();
    // Prevents OneSignal from sending any data until provideUserConsent` is called.
    OneSignal.setRequiresUserPrivacyConsent(true);

    // OneSignal Initialization
    OneSignal.startInit(this)
        .inFocusDisplaying(OneSignal.OSInFocusDisplayOption.Notification)
        .unsubscribeWhenNotificationsAreDisabled(true)
        .init();
}

public void onUserTappedProvidePrivacyConsent(View v) {
    // will initialize the OneSignal SDK and enable push notifications
    OneSignal.provideUserConsent(true);
}

https://documentation.onesignal.com/docs/android-native-sdk#section--setrequiresuserprivacyconsent-