OneSignal class

Constructors

OneSignal()

Properties

hashCode int
The hash code for this object.
no setterinherited
runtimeType Type
A representation of the runtime type of the object.
no setterinherited

Methods

addTrigger(String key, Object value) Future<void>
Adds a single key, value trigger, which will trigger an in app message if one exists matching the specific trigger added
addTriggers(Map<String, Object> triggers) Future<void>
Adds one or more key, value triggers, which will trigger in app messages (one at a time) if any exist matching the specific triggers added
clearOneSignalNotifications() Future<void>
Allows you to manually remove all OneSignal notifications from the Notification Shade
completeNotification(String notificationId, bool shouldDisplay) → void
The notification foreground handler is called whenever a notification arrives and the application is in foreground
consentGranted(bool granted) Future<void>
If your application is set to require the user's consent before using push notifications, your app should call this method when the user gives their consent. This will cause the OneSignal SDK to initialize.
deleteTag(String key) Future<Map<String, dynamic>>
Allows you to delete a single key/value pair from the user's tags by specifying the key. This method can often take more than five seconds to complete, so please do NOT block any user-interactive content while waiting for this request to complete.
deleteTags(List<String> keys) Future<Map<String, dynamic>>
Allows you to delete an array of tags by specifying an array of keys.
disablePush(bool disable) Future<void>
Allows you to manually disable or enable push notifications for this user. Note: This method does not change the user's system (iOS) push notification permission status. If the user disabled (or never allowed) your application to send push notifications, calling disablePush(false) will not change that.
enterLiveActivity(String activityId, String token) Future<void>
Only applies to iOS Associates a temporary push token with an Activity ID on the OneSignal server.
exitLiveActivity(String activityId) Future<void>
Only applies to iOS Deletes activityId associated temporary push token on the OneSignal server.
getDeviceState() Future<OSDeviceState?>
Returns an OSDeviceState object, which contains the current device state
getTags() Future<Map<String, dynamic>>
An asynchronous method that makes an HTTP request to OneSignal's API to retrieve the current user's tags. This request can take a while to complete: please do NOT block any user-interactive content while waiting for this request to finish.
getTriggerValueForKey(String key) Future<Object?>
Get the trigger value associated with the key provided
logoutEmail() Future<void>
Dissociates the user's email from OneSignal, akin to turning off push notifications for email.
logoutSMSNumber() Future<Map<String, dynamic>>
Dissociates the user's SMS number from OneSignal, akin to turning off push notifications for SMS number.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
pauseInAppMessages(bool pause) Future<void>
Toggles the showing of all in app messages
postNotification(OSCreateNotification notification) Future<Map<String, dynamic>>
postNotificationWithJson(Map<String, dynamic> json) Future<Map<String, dynamic>>
Allows you to post a notification to the current user (or a different user if you specify their OneSignal user ID).
promptLocationPermission() Future<void>
Allows you to prompt the user for permission to use location services
promptUserForPushNotificationPermission({bool fallbackToSettings = false}) Future<bool>
removeExternalUserId() Future<Map<String, dynamic>>
Removes the external user ID that was set for the current user.
removeNotification(int notificationId) → void
Allows you to manually cancel a single OneSignal notification based on its Android notification integer ID
removeTriggerForKey(String key) Future<void>
Remove a single key, value trigger to prevent an in app message from showing with that trigger
removeTriggersForKeys(List<String> keys) Future<void>
Remove one or more key, value triggers to prevent any in app messages from showing with those triggers
requiresUserPrivacyConsent() Future<bool>
A boolean value indicating if the OneSignal SDK is waiting for the user's consent before it can initialize (if you set the app to require the user's consent)
sendOutcome(String name) Future<OSOutcomeEvent>
Send a normal outcome event for the current session and notifications with the attribution window Counted each time sent successfully, failed ones will be cached and reattempted in future
sendOutcomeWithValue(String name, double value) Future<OSOutcomeEvent>
Send an outcome event with a value for the current session and notifications with the attribution window Counted each time sent successfully, failed ones will be cached and reattempted in future
sendTag(String key, dynamic value) Future<Map<String, dynamic>>
Sends a single key/value pair to tags to OneSignal. Please do not send hashmaps/arrays as values as this will fail. This method can often take more than five seconds to complete, so please do NOT block any user-interactive content while waiting for this request to complete.
sendTags(Map<String, dynamic> tags) Future<Map<String, dynamic>>
Updates the user's OneSignal tags. This method is additive This method can often take more than five seconds to complete, so please do NOT block any user-interactive content while waiting for this request to complete.
sendUniqueOutcome(String name) Future<OSOutcomeEvent>
Send a unique outcome event for the current session and notifications with the attribution window Counted once per notification when sent successfully, failed ones will be cached and reattempted in future
setAppId(String appId) Future<void>
The initializer for OneSignal. Note that this initializer accepts an iOSSettings object, in Android you can pass null.
setEmail({required String email, String? emailAuthHashToken}) Future<void>
Sets the user's email so you can send them emails through the OneSignal dashboard and API. The emailAuthHashToken is optional (but highly recommended) as part of Identity Verification. The email auth hash is a hash of your app's API key and the user ID. We recommend you generate this token from your backend server, do NOT store your API key in your app as this is highly insecure.
setEmailSubscriptionObserver(EmailSubscriptionChangeHandler handler) → void
The email subscription handler will be called whenever the user's email subscription changes (OneSignal can also send emails in addition to push notifications). For example, if you call setEmail() or logoutEmail().
setExternalUserId(String externalId, [String? authHashToken]) Future<Map<String, dynamic>>
OneSignal allows you to set a custom ID for your users. This makes it so that if your app has its own user ID's, you can use your own custom user ID's with our API instead of having to save their OneSignal user ID's.
setInAppMessageClickedHandler(InAppMessageClickedHandler handler) → void
The in app message clicked handler is called whenever the user clicks a OneSignal IAM button or image with an action event attacthed to it
setLanguage(String language) Future<Map<String, dynamic>>
Sets the user's language. Applies also to the email and/or SMS player if those are logged in on the device.
setLaunchURLsInApp(bool isEnabled) Future<void>
Only applies to iOS Sets if launch URLs should be opened within the application or in Safari. When set to true, launch URLs will open an in-app browser.
setLocationShared(bool shared) Future<void>
Allows you to determine if the user's location data is shared with OneSignal. This allows you to do things like geofenced notifications, etc.
setLogLevel(OSLogLevel logLevel, OSLogLevel visualLevel) Future<void>
Sets the log level for the SDK. The first parameter (logLevel) controls how verbose logs in the console/logcat are, while the visual log level controls if the SDK will show alerts for each logged message
setNotificationOpenedHandler(OpenedNotificationHandler handler) → void
The notification opened handler is called whenever the user opens a OneSignal push notification, or taps an action button on a notification.
setNotificationWillShowInForegroundHandler(NotificationWillShowInForegroundHandler handler) → void
The notification foreground handler is called whenever a notification arrives and the application is in foreground
setOnDidDismissInAppMessageHandler(OnDidDismissInAppMessageHandler handler) → void
The in app message did dismiss handler is called whenever the in app message is dismissed
setOnDidDisplayInAppMessageHandler(OnDidDisplayInAppMessageHandler handler) → void
The in app message did display handler is called whenever the in app message is displayed
setOnWillDismissInAppMessageHandler(OnWillDismissInAppMessageHandler handler) → void
The in app message will dismiss handler is called whenever the in app message is about to be dismissed
setOnWillDisplayInAppMessageHandler(OnWillDisplayInAppMessageHandler handler) → void
The in app message will display handler is called whenever the in app message is about to be displayed
setPermissionObserver(PermissionChangeHandler handler) → void
The permission handler will be called whenever the user's Permission state changes, which is applicable to iOS (Android does not prompt the user for permission to receive push notifications).
setRequiresUserPrivacyConsent(bool required) Future<void>
Allows you to completely disable the SDK until your app calls the OneSignal.consentGranted(true) function. This is useful if you want to show a Terms and Conditions or privacy popup for GDPR.
setSMSNumber({required String smsNumber, String? smsAuthHashToken}) Future<Map<String, dynamic>>
Sets the user's SMS number so you can send them SMSs through the OneSignal dashboard and API. The smsAuthHashToken is optional (but highly recommended) as part of Identity Verification. The SMS auth hash is a hash of your app's API key and the user ID. We recommend you generate this token from your backend server, do NOT store your API key in your app as this is highly insecure.
setSMSSubscriptionObserver(SMSSubscriptionChangeHandler handler) → void
The SMS subscription handler will be called whenever the user's SMS subscription changes (OneSignal can also send SMSs in addition to push notifications). For example, if you call setSMSNumber() or logoutSMSNumber().
setSubscriptionObserver(SubscriptionChangedHandler handler) → void
The subscription handler will be called whenever the user's OneSignal subscription changes, such as when they are first assigned a OneSignal user ID.
toString() String
A string representation of this object.
inherited
userProvidedPrivacyConsent() Future<bool>
A boolean value indicating if the user provided privacy consent

Operators

operator ==(Object other) bool
The equality operator.
inherited

Static Properties

shared OneSignal
A singleton representing the OneSignal SDK. Note that the iOS and Android native libraries are static, so if you create multiple instances of OneSignal, they will mostly share the same state.
getter/setter pair