管理用户同意
Pushwoosh 支持遵守隐私法规(例如 GDPR、CCPA),允许开发者控制 SDK 何时开始与 Pushwoosh 服务器通信。这确保了在用户明确同意之前不会收集任何数据。
默认情况下,Pushwoosh SDK 在初始化后会立即开始与 Pushwoosh 服务器通信并收集设备数据。但是,您可以更改此行为,以便在用户同意之前不进行任何通信。
通过此设置:
-
如果用户同意,SDK 将初始化并开始收集数据。
-
如果用户不同意,SDK 将保持非活动状态,不收集任何数据。
-
如果用户稍后撤回同意,SDK 将停止所有活动并断开与服务器的连接。
Pushwoosh 提供了在 iOS、Android 和 Unity 中管理此流程的机制。
在启动时禁用 SDK 服务器通信
Anchor link to默认情况下,与 SDK 的通信是启用的。要在用户明确授予同意之前禁用与 Pushwoosh 服务器的所有通信,请将以下键添加到您的 Info.plist 中:
<key>Pushwoosh_ALLOW_SERVER_COMMUNICATION</key><false/>检查通信状态
Anchor link to使用以下方法确定当前是否允许通信:
import SwiftUIimport PushwooshFramework
var serverCommunicationAllowed = PWCoreServerCommunicationManager.sharedInstance.isServerCommunicationAllowedprint("isServerCommunicationAllowed: ", serverCommunicationAllowed)import PushwooshFramework
var serverCommunicationAllowed = PWCoreServerCommunicationManager.sharedInstance.isServerCommunicationAllowedprint("isServerCommunicationAllowed: ", serverCommunicationAllowed)#import <PushwooshFramework/PushwooshFramework.h>
BOOL serverCommunicationAllowed = [PWCoreServerCommunicationManager sharedInstance].isServerCommunicationAllowed;NSLog(@"isServerCommunicationAllowed: %d", serverCommunicationAllowed);在同意后启用 SDK 通信
Anchor link to一旦用户授予同意,请按如下方式启用通信:
import SwiftUIimport PushwooshFramework
Pushwoosh.sharedInstance().startServerCommunication()import PushwooshFramework
Pushwoosh.sharedInstance().startServerCommunication()#import <PushwooshFramework/PushwooshFramework.h>
[[Pushwoosh sharedInstance] startServerCommunication];注册推送通知
Anchor link to启用通信后,明确注册推送通知:
import SwiftUIimport PushwooshFramework
Pushwoosh.sharedInstance().registerForPushNotifications()import PushwooshFramework
Pushwoosh.sharedInstance().registerForPushNotifications()#import <PushwooshFramework/PushwooshFramework.h>
[[Pushwoosh sharedInstance] registerForPushNotifications];禁用通信
Anchor link to要停止与 Pushwoosh 服务器的通信(例如,如果用户撤销同意):
import SwiftUIimport PushwooshFramework
Pushwoosh.sharedInstance().stopServerCommunication()import PushwooshFramework
Pushwoosh.sharedInstance().stopServerCommunication()#import <PushwooshFramework/PushwooshFramework.h>
[[Pushwoosh sharedInstance] stopServerCommunication];Android
Anchor link to在启动时禁用 SDK 服务器通信
Anchor link to默认情况下,通信是启用的。为防止在获得用户同意之前将任何数据发送到 Pushwoosh 服务器,请将以下内容添加到您的 AndroidManifest.xml 中:
<meta-data android:name="com.pushwoosh.allow_server_communication" android:value="false" />检查通信状态
Anchor link to使用以下方法确定当前是否允许服务器通信:
import com.pushwoosh.Pushwoosh;
boolean isCommunicationEnabled = Pushwoosh.getInstance().isServerCommunicationAllowed();Log.d("Pushwoosh", "Communication enabled = " + isCommunicationEnabled);import com.pushwoosh.Pushwoosh
val isCommunicationEnabled = Pushwoosh.getInstance().isServerCommunicationAllowed()Log.d("Pushwoosh", "Communication enabled = $isCommunicationEnabled")在同意后启用 SDK 通信
Anchor link to一旦用户授予同意,请按如下方式启用通信:
import com.pushwoosh.Pushwoosh;
Pushwoosh.getInstance().startServerCommunication();import com.pushwoosh.Pushwoosh
Pushwoosh.getInstance().startServerCommunication()注册推送通知
Anchor link to启用通信后,明确注册推送通知:
import com.pushwoosh.Pushwoosh;
Pushwoosh.getInstance().registerForPushNotifications();import com.pushwoosh.Pushwoosh
Pushwoosh.getInstance().registerForPushNotifications()禁用通信
Anchor link to要停止与 Pushwoosh 服务器的通信(例如,如果用户撤销同意):
import com.pushwoosh.Pushwoosh;
Pushwoosh.getInstance().stopServerCommunication();import com.pushwoosh.Pushwoosh
Pushwoosh.getInstance().stopServerCommunication()Unity
Anchor link to在启动时禁用 SDK 服务器通信
Anchor link to默认情况下,与 SDK 的通信是启用的。要在用户明确授予同意之前禁用与 Pushwoosh 服务器的所有通信,请应用平台特定设置:
Android
将以下内容添加到您的 Unity 项目中的 AndroidManifest.xml:
<meta-data android:name="com.pushwoosh.allow_server_communication" android:value="false" />iOS
修改 Info.plist:
<key>Pushwoosh_ALLOW_SERVER_COMMUNICATION</key><false/>注意: 您必须在调用 RegisterForPushNotifications 之前启用通信。
检查通信状态
Anchor link to使用以下方法检查当前是否允许服务器通信:
bool enabled = Pushwoosh.Instance.IsCommunicationEnabled();在同意后启用 SDK 通信
Anchor link to要在同意后启用通信:
Pushwoosh.Instance.SetCommunicationEnabled(true);注册推送通知
Anchor link to启用通信后,您可以注册设备以接收推送通知:
Pushwoosh.Instance.RegisterForPushNotifications();禁用通信
Anchor link to要停止与 Pushwoosh 服务器的通信(例如,如果用户撤销同意):
Pushwoosh.Instance.SetCommunicationEnabled(false);Web Push
Anchor link to在启动时禁用自动订阅
Anchor link to默认情况下,Pushwoosh SDK 在初始化后会立即显示原生订阅提示。为防止 SDK 在初始化时自动显示订阅提示,请在 init 调用中将 communicationEnabled 参数设置为 false。
<script type="text/javascript" src="//cdn.pushwoosh.com/webpush/v3/pushwoosh-web-notifications.js" async></script><script type="text/javascript"> var Pushwoosh = Pushwoosh || []; Pushwoosh.push(['init', { // other initialization parameters... communicationEnabled: false, // Disable communication to prevent automatic subscription prompts }]);</script>在同意后启用订阅
Anchor link to禁用自动订阅后,您可以随时提示用户订阅。当用户同意接收推送通知(例如,通过点击自定义 UI 上的“订阅”按钮)时,您可以通过调用 setCommunicationEnabled 方法来启用通信。调用 Pushwoosh.setCommunicationEnabled(true) 将启用与 Pushwoosh 服务的通信。一旦启用,SDK 将继续显示原生浏览器权限提示。
Pushwoosh.setCommunicationEnabled(true) .then(() => { console.log('User is subscribed to push notifications.'); }) .catch((error) => { console.error('Error subscribing user:', error); });禁用通信
Anchor link to要停止与 Pushwoosh 服务的通信(例如,如果用户撤销同意),请调用 setCommunicationEnabled 并传入 false。
Pushwoosh.setCommunicationEnabled(false);