In my case: I have 2 options to push:
I want to unsubscribe only Player ID, and keep Segment
I've seen:
OneSignalServices.instance.disablePush(true)
=> But it disable all my pushes. curl --include \ --request DELETE \ --header "Authorization: Basic YOUR_ONESIGNAL_API_KEY" \ https://onesignal.com/api/v1/players/ONESIGNAL_PLAYER_ID?app_id=YOUR_APP_ID
But follow the OneSignal document I need Uninstall the app and re-install the app.
How to do it when the user signs out?
Don't send notifications based on player Id instead use an external User Id to send notifications and map your player Id with an external User Id.
In your case, the external User Id will be a random string generated at the time of login and stored in the database as a notification token. Then map this token with the player Id and when the user will logout just delete this token from the database.
Steps Involved:
Generate a random String and stored it in the database as a notification token.
Map this notification token with current player ID.
let externalUserId = '123456789'; // You will supply the external user id to the OneSignal SDK
// Setting External User Id with Callback Available in SDK Version 3.9.3+ OneSignal.shared.setExternalUserId(externalUserId).then((results) { log(results.toString()); }).catchError((error) { log(error.toString()); });
Reference Link for mapping: https://documentation.onesignal.com/docs/external-user-ids#setexternaluserid-method
Send Notification based on this notification Token.
Reference Link to create notification based on external User Id: https://documentation.onesignal.com/reference/create-notification#platform-to-deliver-to
Hope this help.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.