Skip to main content

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 propertyWhat it does
UserSDK(application:apiKey:baseURL:shouldTrackActivities:fcmToken:)Creates the SDK instance and sets UserSDK.default. Sends nothing by itself.
UserSDK.defaultThe shared SDK instance.
setFcmToken(_:)Stores the FCM token and sends a ping.
apiKeyThe Mobile SDK key passed to the initializer. Read only.
baseURLThe workspace address passed to the initializer. Read only.

Contact​

Method or propertyWhat 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.
ContactContact data: userId, email, firstName, lastName, phoneNumber, attributes.
logout(fcmToken:_:)Records a logout and starts a new anonymous contact that keeps the push token.
userKeyThe key of the current contact in Positive User.

Events​

MethodWhat 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.
ProductEventTypeThe product event types.
Trackable view controllersBase classes that send a screen event in viewDidLoad.
screenNameA UIViewController property with the class name of the view controller. trackScreen() sends it as the screen name.

Push notifications​

Method or propertyWhat 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.
notificationDelegateReceives tapped notifications, except in-app messages.
NotificationExtensionHelperAttaches images to push notifications in a Notification Service Extension.

In-app messages​

PropertyWhat it does
inAppMessageClickHandlerReceives button links before the SDK opens them. Swift only.
fontResolverProvides custom fonts for message text.
inAppAlertCloseButtonTextHas no effect. Kept for source compatibility.

MethodWhat 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 propertyWhat it does
UserSDKErrorThe error every failure reports.
UserSDK.errorHandlerReceives 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.

DeprecatedUse 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
EventTypeProductEventType
setUserData(_:fcmToken:_:), setCustomUserData(_:fcmToken:_:), UserDataKeyupdateContact(_:fcmToken:_:) with a Contact
userIduserKey
inAppNotificationClickDelegateinAppMessageClickHandler
handleNotification(userInfo:)handleNotification(_:) for received notifications, handleNotificationClick(_:) for taps
userDataDictionaryNone. Internal ping data, to be removed in 2.0.
shouldTrackActivitiesHas 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.default is [UserSDK default],
  • Contact is UserSDKContact, and ProductEventType is EventType, with values such as EventTypeAddToCart,
  • errors arrive as NSError with the domain com.user.sdk, see Errors,
  • method names follow the selectors shown in the Objective-C examples on each topic page, for example sendEventWithName:attributes:completion:.