SDK Methods
All public methods and properties of the iOS SDK 1.3.0. Each entry links to its description on the topic page, with parameters and examples.
Setup
| Method or property | What it does |
|---|---|
UserSDK(application:apiKey:baseURL:shouldTrackActivities:fcmToken:) | Creates the SDK instance and sets UserSDK.default. Sends nothing by itself. |
UserSDK.default | The shared SDK instance. |
setFcmToken(_:) | Stores the FCM token and sends a ping. |
apiKey | The Mobile SDK key passed to the initializer. Read only. |
baseURL | The workspace address passed to the initializer. Read only. |
Contact
| Method or property | What it does |
|---|---|
ping(fcmToken:_:) | Creates or updates the contact with device data. |
updateContact(_:fcmToken:_:) | Adds the data of a Contact to the current contact, with an optional FCM token, in one request. |
Contact | Contact data: userId, email, firstName, lastName, phoneNumber, attributes. |
logout(fcmToken:_:) | Records a logout and starts a new anonymous contact that keeps the push token. |
userKey | The key of the current contact in Positive User. |
Events
| Method | What it does |
|---|---|
sendEvent(name:attributes:_:) | Sends a custom event. |
trackScreen(name:_:) | Sends a screen event with a name you choose. |
trackScreen() | Sends a screen event named after the view controller class. |
sendProductEvent(_:eventType:attributes:_:) | Sends a product event. |
ProductEventType | The product event types. |
Trackable view controllers | Base classes that send a screen event in viewDidLoad. |
screenName | A UIViewController property with the class name of the view controller. trackScreen() sends it as the screen name. |
Push notifications
| Method or property | What it does |
|---|---|
registerForRemoteNotifications(options:notificationDelegate:) | Requests permission, registers with APNs and makes the SDK the notification center delegate. |
handleNotification(_:) | Passes a received notification to the SDK: shows in-app messages, never counts a click. Returns whether the notification is from Positive User. |
handleNotificationClick(_:) | Passes a tapped notification to the SDK: counts the click and calls notificationDelegate. |
isUserComNotification(_:) | Checks whether a payload is a Positive User notification. |
notificationDelegate | Receives tapped notifications, except in-app messages. |
NotificationExtensionHelper | Attaches images to push notifications in a Notification Service Extension. |
In-app messages
| Property | What it does |
|---|---|
inAppMessageClickHandler | Receives button links before the SDK opens them. Swift only. |
fontResolver | Provides custom fonts for message text. |
inAppAlertCloseButtonText | Has no effect. Kept for source compatibility. |
Email links
| Method | What it does |
|---|---|
handleEmailLink(_:_:) | Counts the click on a link from a Positive User email that opened the app and returns the target of the link. Also available as async. |
Errors
| Type or property | What it does |
|---|---|
UserSDKError | The error every failure reports. |
UserSDK.errorHandler | Receives every error on the main thread, also from calls without a completion. Swift only. |
Deprecated
These still work and stay until 2.0. See the Migration Guide.
| Deprecated | Use instead |
|---|---|
sendEvent(with:params:_:) | sendEvent(name:attributes:_:) |
trackScreen(with:_:) | trackScreen(name:_:) |
sendProductEvent(_:eventType:name:productURL:params:_:) | sendProductEvent(_:eventType:attributes:_:), with name and product_url in attributes |
EventType | ProductEventType |
setUserData(_:fcmToken:_:), setCustomUserData(_:fcmToken:_:), UserDataKey | updateContact(_:fcmToken:_:) with a Contact |
userId | userKey |
inAppNotificationClickDelegate | inAppMessageClickHandler |
handleNotification(userInfo:) | handleNotification(_:) for received notifications, handleNotificationClick(_:) for taps |
userDataDictionary | None. Internal ping data, to be removed in 2.0. |
shouldTrackActivities | Has no effect. Track screens with trackScreen(name:_:) or Trackable view controllers. |
Objective-C
All methods above are available in Objective-C, except inAppMessageClickHandler, UserSDK.errorHandler, screenName and the async form of handleEmailLink. In Objective-C:
UserSDK.defaultis[UserSDK default],ContactisUserSDKContact, andProductEventTypeisEventType, with values such asEventTypeAddToCart,- errors arrive as
NSErrorwith the domaincom.user.sdk, see Errors, - method names follow the selectors shown in the Objective-C examples on each topic page, for example
sendEventWithName:attributes:completion:.