Xamarin SDK
Just starting with Xamarin?
Check out our Xamarin SDK Setup guide.
Parameter | Data Type | Description |
---|---|---|
Debugging | ||
setLogLevel | Method | Enable logging to help debug OneSignal implementation |
Initialization | ||
StartInit | Method | Starts initialization of OneSignal, call this from your FinishedLaunching (iOS) or your OnCreate (Android) method. See Xamarin SDK Setup for code examples. |
inFocusDisplaying | Method | Setting to control how OneSignal notifications will be shown when one is received while your app is in focus. |
Settings | Method | iOS - Automatically prompt users to enable notifications and open all URLs in In-App Safari window. |
EndInit | Method | Must be called after StartInit to complete initialization of OneSignal. |
Handling Notifications | ||
NotificationReceived | Method | When a notification is received by a device in the foreground. |
HandleNotificationReceived | Delegate | |
NotificationOpened | Method | When a user takes an action on a notification. |
HandleNotificationOpened | Delegate | |
Privacy | ||
setRequiresUserPrivacyConsent | Method | Delays initialization of the SDK until the user provides privacy consent |
UserDidProvidePrivacyConsent | Method | Provides privacy consent. |
iOS Prompting | ||
promptForPushNotificationsWithUserResponse | Method | Prompt the user for notification permissions. Callback fires as soon as the user accepts or declines notifications. Must set kOSSettingsKeyAutoPrompt to false when calling initWithLaunchOptions.Recommended: Set to false and follow iOS Push Opt-In Prompt. |
User Status | ||
IdsAvailableCallback | Delegate | |
IdsAvailable | Method | Get the user ID of the device. |
setSubscription | Method | Disable OneSignal from sending notifications to current device. |
External User IDs | ||
setExternalUserId | Method | Allows you to use your own system's user ID's to send push notifications to your users. To tie a user to a given user ID, you can use this method. |
removeExternalUserId | Method | Removes whatever was set as the current user's external user ID. |
Tagging | ||
getTags | Method | View Tags from current device record. |
sendTag | Method | Add a single Data Tag to current device record. |
sendTags | Method | Add multiple Data Tags to current device record. |
deleteTag | Method | Delete a Tag from current device record. |
deleteTags | Method | Delete multiple Tags from current device record. |
Location Data | ||
setLocationShared | Method | Disable or Enable SDK location collection. See Handling Personal Data. |
promptLocation | Method | Prompt Users for Location Not Recommended Recommended: Use In-App Message Location Opt-In Prompt. |
Sending Notifications | ||
PostNotification | Method | Send or schedule a notification to a OneSignal Player ID. |
CancelNotification | Method | Delete a single app notification. |
ClearOneSignalNotifications | Method | Delete all app notifications. |
In-App Messaging | ||
addTrigger | Method | Add a trigger, may show an In-App Message if its triggers conditions were met. |
addTriggers | Method | Add a map of triggers, may show an In-App Message if its triggers conditions were met. |
removeTriggerForKey | Method | Removes a list of triggers based on a collection of keys, may show an In-App Message if its triggers conditions were met. |
getTriggerValueForKey | Method | Gets a trigger value for a provided trigger key. |
pauseInAppMessages | Method | Allows you to temporarily pause all In App Messages. |
setInAppMessageClickHandler | Method | Sets an In App Message opened block |
setEmail | Method | Set user's email. Creates a new user record for the email address. Use sendTag if you want to update a push user record with the email. |
logoutEmail | Method | Log user out to dissociate email from device |
Notification Objects | ||
OSNotificationOpenedResult | Class | Information returned from a notification the user received. |
OSNotification | Class | Represents a received push notification |
OSNotificationAction | Class | How user opened notification |
OSNotificationPayload | Class | Data that comes with a notification. |
Appearance | ||
EnableVibrate | Method | Android - When user receives notification, vibrate device less. |
EnableSound | Method | Android - When user receives notification, do not play a sound. |
Initialization
Settings
Settings that can be passed into the initialization chaining method.
Settings key options are:
IOSSettings.kOSSettingsKeyAutoPrompt
- Auto prompt user for notification permissions.IOSSettings.kOSSettingsKeyInAppLaunchURL
- Launch notifications with a launch URL as an in app webview.
Parameter | Type | Description |
---|---|---|
settings | Dictionary<string, bool> | Additional initialization settings. Set true or false . |
OneSignal.Current.StartInit("b2f7f966-d8cc-11e4-bed1-df8f05be55ba")
.Settings(new Dictionary<string, bool>() {
{ IOSSettings.kOSSettingsKeyAutoPrompt, false },
{ IOSSettings.kOSSettingsKeyInAppLaunchURL, false } })
.EndInit();
Privacy / GDPR
SetRequiresUserPrivacyConsent
Allows you to delay the initialization of the SDK until the user provides privacy consent. The SDK will not be fully initialized until the UserDidProvidePrivacyConsent(true)
method is called. Make sure to call this method before you initialize the SDK.
If you set this to be true, the SDK will not fully initialize until consent is provided. You can still call OneSignal methods, but nothing will happen, and the user will not be registered for push notifications.
//will delay initialization of the SDK
//make sure to call before init()
OneSignal.SetRequiresUserPrivacyConsent(true);
For GDPR users, your application should call this method before initialization of the SDK. If you pass in true, your application will need to call UserDidProvidePrivacyConsent(true)
before the OneSignal SDK gets fully initialized. Until this happens, you can continue to call methods (such as SendTags()
), but nothing will happen.
//will delay initialization of the SDK until the your application calls the method to provides consent.
OneSignal.Current.SetRequiresUserPrivacyConsent(true);
UserDidProvidePrivacyConsent
If your application is set to require the user's privacy consent, you can provide this consent using this method. Until you call UserDidProvidePrivacyConsent(true)
, the SDK will not fully initialize and will not send any data to OneSignal.
PrivacyConsentButton.TouchUpInside += delegate
{
//the SDK will now be initialized
OneSignal.UserDidProvidePrivacyConsent(true);
};
For GDPR users, if you set the SDK to require the user's privacy consent, your application can use this method once the user does or doesn't provide privacy consent to use the OneSignal SDK.
public void userTappedProvideConsentButton() {
//since the user agreed to your app's consent screen, provide consent with the SDK
OneSignal.Current.UserDidProvidePrivacyConsent(true);
}
RequiresUserPrivacyConsent
This method returns a boolean that indicates if the OneSignal SDK is waiting for the user to provide privacy consent.
true
- Indicates that the OneSignal SDK hasn't received the user's privacy consent yetfalse
- Either the user has already provided consent, or your app isn't set to require consent.
if (OneSignal.Current.RequiresUserPrivacyConsent()) {
// the SDK is waiting for your app to call UserDidProvidePrivacyConsent(true)
} else {
// the user has provided consent and the SDK will initialize
}
Registering Push
RegisterForPushNotifications
Call this when you would like to prompt an iOS user to accept push notifications with the default system prompt. Only use if you passed false
to kOSSettingsKeyAutoPrompt
when calling Init Settings.
OneSignal.Current.RegisterForPushNotifications();
User IDs
IdsAvailableCallback
Delegate you can define to get the OneSignal userId and Google registration Id or an iOS push token.
Parameter | Type | Description |
---|---|---|
userId | String | OneSignal userId is a UUID formatted string. (unique per device per app) |
pushToken | String | Either a Google registration Id or an iOS push token identifier(unique per device per app). NOTE: Might be blank if push notifications are not accepted on iOS, Google Play services are not installed, or from a connection issue. |
private void IdsAvailable(string userID, string pushToken) {
print("UserID:" + userID);
print("pushToken:" + pushToken);
}
IdsAvailable
Lets you retrieve the OneSignal player id and push token. Your delegate is called after the device is successfully registered with OneSignal. If the device has already successfully registered, the delegate will be called immediately.
Parameter | Type | Description |
---|---|---|
inIdsAvailableDelegate | IdsAvailableCallback | Calls the delegate when the player id is available. |
void SomeMethod() {
OneSignal.Current.IdsAvailable(IdsAvailable);
}
private void IdsAvailable(string userID, string pushToken) {
print("UserID:" + userID);
print("pushToken:" + pushToken);
}
External IDs
setExternalUserId
If your system assigns unique identifiers to users, it can be annoying to have to also remember their OneSignal user ID's as well. To make things easier, OneSignal now allows you to set an external_id
for your users. Simply call this method, pass in your custom user ID (as a string), and from now on when you send a push notification, you can use include_external_user_ids
instead of include_player_ids
.
let myCustomUniqueUserId = "something from my backend server";
OneSignal.Current.SetExternalUserId(myCustomUniqueUserId);
removeExternalUserId
If your user logs out of your app and you would like to disassociate their custom user ID from your system with their OneSignal user ID, you will want to call this method.
//usually called after the user logs out of your app
OneSignal.Current.RemoveExternalUserId()
Tags
GetTags
Retrieve a list of tags that have been set on the player from the OneSignal server.
Parameter | Type | Description |
---|---|---|
inTagsReceivedDelegate | TagsReceived | Delegate gets called once the tags are available. |
void SomeMethod() {
OneSignal.GetTags(TagsReceived);
}
private void TagsReceived(Dictionary<string, object> tags) {
foreach (var tag in tags)
print(tag.Key + ":" + tag.Value);
}
TagsReceived
Delegate you can define to get the all the tags set on a player from onesignal.com.
Parameter | Type | Description |
---|---|---|
tags | Dictionary<string, object> | Dictionary of key value pairs retrieved from the OneSignal server. |
private static void TagsReceived(Dictionary<string, object> tags) {
foreach (var tag in tags)
print(tag.Key + ":" + tag.Value);
}
SendTag
Tag a player based on a game event of your choosing so later you can create segments on onesignal.com to target these players. If you need to set more than one key at a time please use SendTags
instead.
Parameter | Type | Description |
---|---|---|
key | String | Key of your choosing to create or update. |
value | String | Value to set on the key. NOTE: Passing in a blank String deletes the key, you can also call DeleteTag or DeleteTags . |
OneSignal.Current.SendTag("key", "value");
SendTags
Set multiple tags on a player with one call.
Parameter | Type | Description |
---|---|---|
tags | Dictionary<string, string> | An IDictionary of key value pairs. NOTE: Passing in a blank as a value deletes the key, you can also call DeleteTag or DeleteTags . |
OneSignal.Current.SendTags(new Dictionary<string, string>() { {"TestKey2", "value2"}, {"TestKey3", "value3"} });
DeleteTag
Deletes a tag that was previously set on a player with SendTag
or SendTags
. Please use DeleteTags
if you need to delete more than one tag.
Parameter | Type | Description |
---|---|---|
key | String | Key to remove. |
OneSignal.DeleteTag("key");
DeleteTags
Deletes tags that were previously set on a player with SendTag
or SendTags
.
Parameter | Type | Description |
---|---|---|
keys | IList | Keys to remove. |
OneSignal.Current.DeleteTags(new List<string>() {"TestKey2", "TestKey3" })
Data
SetLocationShared
Accepts a boolean parameter, allows you to enable or disable OneSignal SDK location tracking. Please note that if you disable location tracking, you will not be able to use location based push notifications.
//disables location features
OneSignal.SetLocationShared(false);
PromptLocation
Prompts the user for location permissions. This allows for geotagging so you can send notifications to users based on location.
OneSignal.Current.PromptLocation();
iOS INSTRUCTIONS
You must add all of the following to your iOS plist settings:
NSLocationUsageDescription
NSLocationWhenInUseUsageDescription
ANDROID INSTRUCTIONS
You must add one of the following Android Permissions:
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
Sending Notifications
PostNotification
Allows you to send notifications from user to user or schedule ones in the future to be delivered to the current device.
Parameter | Type | Description |
---|---|---|
parameters | Dictionary<string, object> | Dictionary of notification options, see our Create notification POST call for all options. |
Returns | Method |
---|---|
onSuccess | OnPostNotificationSuccess delegate fires when the notification was created on OneSignal's server.Dictionary<string, object> - Json response from OneSignal's server. |
onFailure | OnPostNotificationFailure delegate fires when the notification failed to createDictionary<string, object> - Json response from OneSignal's server. |
using OneSignalPush.MiniJSON;
private static string oneSignalDebugMessage;
void someMethod() {
// Just an example userId, use your own or get it the devices by calling OneSignal.GetIdsAvailable
string userId = "b2f7f966-d8cc-11e4-bed1-df8f05be55ba";
var notification = new Dictionary<string, object>();
notification["contents"] = new Dictionary<string, string>() { {"en", "Test Message"} };
notification["include_player_ids"] = new List<string>() { userId };
// Example of scheduling a notification in the future.
notification["send_after"] = System.DateTime.Now.ToUniversalTime().AddSeconds(30).ToString("U");
OneSignal.Current.PostNotification(notification, (responseSuccess) => {
oneSignalDebugMessage = "Notification posted successful! Delayed by about 30 secounds to give you time to press the home button to see a notification vs an in-app alert.\n" + Json.Serialize(responseSuccess);
}, (responseFailure) => {
oneSignalDebugMessage = "Notification failed to post:\n" + Json.Serialize(responseFailure);
});
}
See the Create notification REST API POST call for a list of all possible options. Note: You can only use include_player_ids
as a targeting parameter from your app. Other target options such as tags
and included_segments
require your OneSignal App REST API key which can only be used from your server.
CancelNotification
Deletes a single app notification.
ClearOneSignalNotifications
Removes all OneSignal app notifications from the Notification Shade.
OneSignal.Current.ClearOneSignalNotifications();
SetSubscription
You can call this method with false to opt users out of receiving all notifications through OneSignal. You can pass true later to opt users back into notifications.
Parameter | Type | |
---|---|---|
enable | Boolean |
OneSignal.SetSubscription(false);
Receiving Notifications
NotificationReceived
Use to process a OneSignal notification that is received when the app is running in the foreground or background.
Parameter | Type | Description |
---|---|---|
result | OSNotification | Object containing properties of the notification. |
// Called when your app is in focus and a notificaiton is recieved.
// The name of the method can be anything as long as the signature matches.
// Method must be static or this object should be marked as DontDestroyOnLoad
private static void HandleNotificationReceived(OSNotification notification) {
OSNotificationPayload payload = notification.payload;
string message = payload.body;
print("GameControllerExample:HandleNotificationReceived: " + message);
print("displayType: " + notification.displayType);
extraMessage = "Notification received with text: " + message;
}
HandleNotificationReceived
Sets a notification received handler. The delegate will be called when a notification is received whether it was displayed or not when your app is in focus.
Parameter | Type | Description |
---|---|---|
handler | NotificationReceivedHandler | A delegate to handle the received event. |
OneSignal.Current.StartInit("b2f7f966-d8cc-11e4-bed1-df8f05be55ba")
.HandleNotificationReceived(HandleNotificationReceived)
.EndInit();
NotificationOpened
Use to process a OneSignal notification the user just tapped on.
Parameter | Type | Description |
---|---|---|
result | OSNotificationOpenedResult | Object containing both the user's response and properties of the notification. |
// Called when a notification is opened.
// The name of the method can be anything as long as the signature matches.
// Method must be static or this object should be marked as DontDestroyOnLoad
private static void HandleNotificationOpened(OSNotificationOpenedResult result) {
OSNotificationPayload payload = result.notification.payload;
Dictionary<string, object> additionalData = payload.additionalData;
string message = payload.body;
string actionID = result.action.actionID;
print("GameControllerExample:HandleNotificationOpened: " + message);
extraMessage = "Notification opened with text: " + message;
if (additionalData != null) {
if (additionalData.ContainsKey("discount")) {
extraMessage = (string)additionalData["discount"];
// Take user to your store.
}
}
if (actionID != null) {
// actionSelected equals the id on the button the user pressed.
// actionSelected will equal "__DEFAULT__" when the notification itself was tapped when buttons were present.
extraMessage = "Pressed ButtonId: " + actionID;
}
}
private static void HandleNotification(string message, Dictionary<string, object> additionalData, bool isActive) {
bool hasButtons = (additionalData != null && additionalData.ContainsKey("actionSelected"));
if (hasButtons) {
if (additionalData["actionSelected"].Equals("id1"))
print("button id1 pressed");
else if (additionalData["actionSelected"].Equals("id2"))
print("button id2 pressed");
else if (additionalData["actionSelected"].Equals("__DEFAULT__"))
print("Buttons present but you tapped on the notificaiton instead.");
}
}
private static void HandleNotification(string message, Dictionary<string, object> additionalData, bool isActive) {
print("Notification opned with Message: " + message);
if (additionalData != null && additionalData.ContainsKey("stacked_notifications")) {
var notificationsList = (List<object>)additionalData["stacked_notifications"];
print("Stacked Sotification Opened, number on stack: " + notificationsList.Count);
foreach (Dictionary<string, object> notifiAddData in notificationsList) {
foreach (KeyValuePair<string, object> kvp in notifiAddData)
print("Key = " + kvp.Key + ", Value = " + kvp.Value);
}
}
}
HandleNotificationOpened
Delegate you can define to process information on the notification the user just opened.
Parameter | Type | Description |
---|---|---|
handler | NotificationReceivedHandler | A delegate to handle the open event. |
OneSignal.Current.StartInit("b2f7f966-d8cc-11e4-bed1-df8f05be55ba")
.HandleNotificationOpened(HandleNotificationOpened)
.EndInit();
OSNotificationOpenedResult
The information returned from a notification the user received.
Parameter | Type | Description |
---|---|---|
notification | OSNotification | Notification the user opened. |
action | OSNotificationAction | The action the user took on the notification. |
OSNotification
The notification the user opened.
Parameter | Type | Description |
---|---|---|
isAppInFocus | boolean | Was app in focus. |
shown | boolean | Was notification shown to the user. Will be false for silent notifications. |
androidNotificationId | int | Android Notification assigned to the notification. Can be used to cancel or replace the notification. |
payload | OSNotificationPayload | Payload received from OneSignal. |
displayType | DisplayType | How the notification was displayed to the user. |
groupedNotifications | List<OSNotificationPayload> | Notification is a summary notification for a group this will contain all notification payloads it was created from. |
displayType
How the notification was displayed to the user. Part of OSNotification. See inFocusDisplaying for more information on how this is used.
Notification
- native notification display.InAppAlert
(Default) - native alert dialog display (note this is not an In-App Message).None
- notification is silent, or inFocusDisplaying is disabled.
OSNotificationAction
The action the user took on the notification.
Parameter | Type | Description |
---|---|---|
type | ActionType | Was the notification opened normally (Opened ) or was a button pressed on the notification (ActionTaken ). |
actionID | String | If type == ActionTaken then this will contain the id of the button pressed. |
OSNotificationPayload
Contents and settings of the notification the user received.
Parameter | Type | Description |
---|---|---|
notificationId | String | OneSignal notification UUID. |
title | String | Title of the notification. |
body | String | Body of the notification. |
additionalData | Dictionary<string, object> | Custom additional data that was sent with the notification. Set on the dashboard under Options > Additional Data or with the 'data' field on the REST API. |
smallIcon | String | Small icon resource name set on the notification. |
largeIcon | String | Large icon set on the notification. |
bigPicture | String | Big picture image set on the notification. |
smallIconAccentColor | String | Accent color shown around small notification icon on Android 5+ devices. ARGB format. |
launchUrl | String | URL to open when opening the notification. |
sound | String | Sound resource to play when the notification is shown. |
ledColor | String | Devices that have a notification LED will blink in this color. ARGB format. |
lockScreenVisibility | int | Privacy setting for how the notification should be shown on the lockscreen of Android 5+ devices. 1 = Public (fully visible)(default), 0 = Private (Contents are hidden), -1 = Secret (not shown). |
groupKey | String | Notifications with this same key will be grouped together as a single summary notification. |
groupMessage | string | Summary text displayed in the summary notification. |
actionButtons | List<Dictionary<string, object>> | List of action buttons on the notification. |
fromProjectNumber | String | The Google project number the notification was sent under. |
backgroundImageLayout | BackgroundImageLayout | If a background image was set this object will be available. |
rawPayload | String | Raw JSON payload string received from OneSignal. |
ActionButton
List of action buttons on the notification. Part of OSNotificationPayload.
Parameter | Type | Description |
---|---|---|
id | String | Id assigned to the button. |
text | String | Text show on the button to the user. |
icon | String | Icon shown on the button. |
BackgroundImageLayout
If a background image was set, this object will be available. Part of OSNotificationPayload.
Parameter | Type | Description |
---|---|---|
image | String | Image URL or name used as the background image. |
titleTextColor | String | Text color of the title on the notification. ARGB Format. |
bodyTextColor | String | Text color of the body on the notification. ARGB Format. |
Appearance
EnableVibrate
By default OneSignal always vibrates the device when a notification is displayed unless the device is in a total silent mode. Passing false means that the device will only vibrate lightly when the device is in it's vibrate only mode.
You can link this action to a UI button to give your user a vibration option for your notifications.
OneSignal.Current.EnableVibrate(false);
EnableSound
By default OneSignal plays the system's default notification sound when the device's notification system volume is turned on. Passing false means that the device will only vibrate unless the device is set to a total silent mode.
You can link this action to a UI button to give your user a different sound option for your notifications.
OneSignal.Current.EnableSound(false);
In-App Messaging

Check out In-App Messaging Quickstart to get an overview before diving into the SDK methods below.
In-App - Triggers
Triggers are something you fire in your app based on events/state changes which may show an In-App Message. Every time you add or remove a trigger with the below methods the SDK will evaluate if an In-App Message should be shown based on the Trigger conditions set on it via OneSignal Dashboard when it was created.
Triggers are reset each time your app is closed so make sure to set them again when starting your app if you need any of them to be persistent.
AddTrigger
Add a trigger, may show an In-App Message if its triggers conditions were met.
Parameter | Type | Description |
---|---|---|
key | String | Key for the trigger |
value | Object | Value for the trigger. Object passed in will have toString() called if not a String |
OneSignal.Current.AddTrigger("trigger_1", "one");
AddTriggers
Add a map of triggers, may show an In-App Message if its triggers conditions were met.
Parameter | Type | Description |
---|---|---|
triggers | Dictionary<string, object> | Allows you to set multiple trigger key/value pairs simultaneously |
Dictionary<string, object> triggers = new Dictionary<string, object>();
triggers.Add("trigger_2", "two");
triggers.Add("trigger_3", "three");
OneSignal.Current.AddTriggers(triggers);
RemoveTriggerForKey
Removes a single trigger for the given key, may show an In-App Message if its triggers conditions were met.
Parameter | Type | Description |
---|---|---|
key | String | Key for trigger to remove |
OneSignal.Current.RemoveTriggerForKey("trigger_2");
RemoveTriggersForKeys
Removes a list of triggers based on a collection of keys, may show an In-App Message if its triggers conditions were met.
Parameter | Type | Description |
---|---|---|
keys | List<String> | Removes a collection of triggers from their keys |
List<string> removeKeys = new List<string>();
removeKeys.Add("trigger_1");
removeKeys.Add("trigger_3");
OneSignal.Current.RemoveTriggersForKeys(removeKeys);
GetTriggerValueForKey
Gets a trigger value for a provided trigger key.
Parameter | Type | Description |
---|---|---|
key | String | Returns a single trigger value for the given key, if it exists, otherwise returns null |
Return Type | Description |
---|---|
object | Value if added with AddTrigger or null if never set. |
object value = OneSignal.Current.GetTriggerValueForKey("trigger_1");
Debug.WriteLine("trigger_1 value: " + value);
In App - Misc
PauseInAppMessages
Allows you to temporarily pause all In-App Messages. You may want to do this while the user is watching a video playing a match in your game to make sure they don't get interrupted at a bad time.
Parameter | Type | Description |
---|---|---|
pause | boolean | To pause set true To resume set false |
In App - Handlers
HandleInAppMessageClicked
Sets a In App Message opened handler. The instance will be called when an In App Message action is tapped on.
Parameter | Type | Description |
---|---|---|
handler | Delegate | Instance to a class implementing this interference. |
Example
OneSignal.Current.StartInit("b0f7f966-d8ec-11e4-bed1-df8f05je55ba").Settings(new Dictionary<string, bool>() {
{ IOSSettings.kOSSettingsKeyAutoPrompt, false },
{ IOSSettings.kOSSettingsKeyInAppLaunchURL, true } })
.HandleInAppMessageClicked((action) =>
{
// Example IAM click handling for IAM elements
Debug.WriteLine("HandledInAppMessageClicked: {0}", action.clickName);
})
.EndInit();
OSInAppMessageAction
Details about the In-App Message action element (button or image) that was tapped on. Passed into the delegate for HandleInAppMessageClicked
.
Field | Type | Description |
---|---|---|
clickName | String | An optional click name defined for the action element.null if not set |
clickUrl | String | An optional URL that opens when the action takes place.null if not set. |
firstClick | boolean | true if this is the first time the user has pressedany action on the In App Message. |
closesMessage | boolean | Did the action close the In App Message.true the In App Message will animate off the screen.false the In App Message will stay on screen until the user dismisses. |
Email
SetEmail
SetEmail
allows you to set the user's email address with the OneSignal SDK. We offer several overloaded versions of this method.
The user's email will be cached by our SDK, so it is only necessary to call this method a single time.
Note: Because several events must occur before the SDK can set the user's email with our API, please note that the callbacks for SetEmail
may take several seconds, and in the very worst-case can take up to 30 seconds.
OneSignal.Current.SetEmail("[email protected]");
// Optionally, you can also use callbacks
OneSignal.Current.SetEmail("[email protected]", () => {
//handle success
}, (error) => {
//handle failure
});
If you have a backend server, we strongly recommend using Identity Verification with your users. Your backend can generate an email authentication token and send it to your app. The following code also includes callbacks:
string email = "[email protected]";
string emailAuthCode = ; //generated on your backend server
OneSignal.SetEmail(email, emailAuthCode);
// Optionally, you can also use callbacks
OneSignal.Current.SetEmail(email, emailAuthCode, () => {
//handle success
}, (error) => {
//handle failure
});
LogoutEmail
If your app implements logout functionality, you can call LogoutEmail
to dissociate the email from the device:
OneSignal.Current.LogoutEmail();
// Optionally, you can also use callbacks
OneSignal.Current.LogoutEmail(() => {
//handle success
}, (error) => {
//handle failure
});
Updated almost 3 years ago