MarketingCloudSdk

@objc(SFMarketingCloudSdk)
public final class MarketingCloudSdk : NSObject, SFMCModule, Publisher
extension MarketingCloudSdk: Subscriber
extension MarketingCloudSdk: MarketingCloudSdkInterface

This class is a Swift Interface for SFMarketingCloudSdk

Request SDK Method

  • Requests the MarketingCloudSdk Module when it’s operational and safe to use. The provided callback will be invoked with the MarketingCloudSdk Module when it’s ready. All MarketingCloudSdk module-related API calls should be made within this function.

    Declaration

    Swift

    @objc
    public static func requestSdk(_ callback: @escaping (_ marketingCloudSdk: MarketingCloudSdkInterface?) -> Void)

    Parameters

    callback

    A callback that will receive the MarketingCloudSdk Module when it’s operational/ready.

Push Methods

  • This method is to get the SDK metadata

    Declaration

    Swift

    @objc
    public static func metadata() -> [String : Any]
  • Ask MarketingCloudSDK to update its data. MarketingCloudSDK will throttle attempts based on the time since the last time this was called.

    Declaration

    Swift

    public func refresh(fetchCompletionHandler completionHandler: ((UIBackgroundFetchResult) -> Void)?) -> Bool

    Parameters

    completionHandler

    The UIBackgroundFetchResult completion handler. This method will be called with UIBackgroundFetchResultNoData if no attempt was made to update data, otherwise it will be called with UIBackgroundFetchResultNewData after the update completes. If nil is passed, then process of the completion handler must be managed by the caller.

Logging Methods

  • Enable/Disable extra debug logging from the SDK.

    Declaration

    Swift

    public func setDebugLoggingEnabled(_ enabled: Bool)

    Parameters

    enabled

    BOOL for enabling or disabling extra SDK logging.

  • Unified Logger initialized for ‘MarketingCloudSdk’ Module ### Usage Example: ### MarketingCloudSdk.shared.getLogger().d(category: .event, message: “Message”)

    Declaration

    Swift

    @objc
    public static func getLogger() -> ModuleLogger

Registration Methods

  • Declaration

    Swift

    public func contactKey() -> String?

    Return Value

    Contact key String that is set in the application.

  • Adds the provided Tag (NSString) to the set of unique tags.

    Declaration

    Swift

    public func addTag(_ tag: String) -> Bool

    Parameters

    tag

    A string to add to the list of tags.

    Return Value

    YES if added successfully.

  • Adds the provided array of Tags (NSString) to the set of unique tags. Will trim leading and trailing whitespace. Cannot be nil or blank.

    Declaration

    Swift

    public func addTags(_ tags: [Any]) -> Set<AnyHashable>?

    Parameters

    tags

    An array of tags to add to the list.

    Return Value

    Set of tags added, as strings, or nil if something failed.

  • Removes the provided Tag (NSString) from the list of tags.

    Declaration

    Swift

    public func removeTag(_ tag: String) -> Bool

    Parameters

    tag

    A string to remove from the list of tags.

    Return Value

    YES if removed successfully.

  • Returns the list of tags for this device.

    Declaration

    Swift

    public func tags() -> Set<AnyHashable>?

    Return Value

    All tags associated, as strings.

  • Returns a read-only copy of the Attributes dictionary as it is right now.

    Declaration

    Swift

    public func attributes() -> [AnyHashable : Any]?
  • Returns the Salesforce application accessToken.

    Declaration

    Swift

    public func accessToken() -> String?
  • Returns the unique device identifier that Salesforce will use to identify the device.

    Declaration

    Swift

    public func deviceIdentifier() -> String?
  • Add a signedString security token for registration security

    Declaration

    Swift

    public func setSignedString(_ signedString: String?) -> Bool

    Parameters

    signedString

    signedString opaque token used to verify registration. pass nil to clear signedString.

  • Returns the value of last stored signedString security token

    Declaration

    Swift

    public func signedString() -> String?
  • Register a callback that will be notified when Registration related events happen

    @see: https://salesforce-marketingcloud.github.io/MarketingCloudSDK-iOS/sdk-implementation/user-data.html

    @param registrationCallback closure to be provided when registration event occurs

    Declaration

    Swift

    public func setRegistrationCallback(_ registrationCallback: @escaping (Dictionary<AnyHashable, Any>) -> Void)
  • Declaration

    Swift

    public func unsetRegistrationCallback()

Feature Toggle Methods

  • Developer override to set the state of analytics enablement to YES/NO. If set to NO, the SDK will stop tracking analytics and also purges all the analytics stored locally. This value takes precedence over the config setting which is passed during the SDK initialization.

    Declaration

    Swift

    public func setAnalyticsEnabled(_ analyticsEnabled: Bool)
  • The current state of the Analytics enablement override

    Declaration

    Swift

    public func isAnalyticsEnabled() -> Bool
  • Developer override to set the state of PI analytics enablement to YES/NO. If set to NO, the SDK will stop tracking PI analytics and also purges all the analytics stored locally. This value takes precedence over the config setting which is passed during the SDK initialization.

    Declaration

    Swift

    public func setPiAnalyticsEnabled(_ analyticsEnabled: Bool)
  • The current state of the PI Analytics enablement override

    Declaration

    Swift

    public func isPiAnalyticsEnabled() -> Bool
  • The current state of the Location enablement override

    Declaration

    Swift

    public func isLocationEnabled() -> Bool
  • Developer override to set the state of Location enablement to YES/NO. If set to NO, the SDK will stop monitoring location and Location services are not available for the consuming application. This value takes precedence over the config setting which is passed during the SDK initialization.

    Declaration

    Swift

    public func setLocationEnabled(_ locationEnabled: Bool)

    Parameters

    locationEnabled

    Bool value to enabled/disable geofence at runtime

Intelligence

  • Set String identifier

    Declaration

    Swift

    public func setPiIdentifier(_ identifier: String?) -> Bool

    Parameters

    identifier

    Identifier to be set

  • Returns piIdentifier

    Declaration

    Swift

    public func piIdentifier() -> String?
  • Track the pageview visited in the page

    Declaration

    Swift

    public func trackPageView(url: String, title: String?, item: String?, search: String?)

    Parameters

    url

    url String

    title

    Title of the pageview

    item

    item String

    search

    search String

  • Track contents in the cart

    Declaration

    Swift

    public func trackCartContents(_ cartDictionary: [AnyHashable : Any])

    Parameters

    cartDictionary

    Collection of items to be tracked

  • Track Conversion on the items in the cart

    Declaration

    Swift

    public func trackCartConversion(_ orderDictionary: [AnyHashable : Any])

    Parameters

    orderDictionary

    Collection of items converted in the bag

  • Returns cartItem Dictionary with specific price, quantity, item and Id

    Declaration

    Swift

    public func cartItemDictionary(price: NSNumber, quantity: NSNumber, item: String, uniqueId: String?) -> [AnyHashable : Any]?

    Parameters

    quantity

    car item Dictionary should be returned by quantity

    item

    item by which the car item Dictionary should be returned

    uniqueId

    Unique Id by which the car item Dictionary should be returned

  • Returns cart Dictionary with cartItem

    Declaration

    Swift

    public func cartDictionary(cartItem: [Any]) -> [AnyHashable : Any]?

    Parameters

    cartItem

    Collection of cartItems

  • Returns order Dictionary with ordernumber, shipping number, discount, cart dictionary

    Declaration

    Swift

    public func orderDictionary(orderNumber: String, shipping: NSNumber, discount: NSNumber, cart: [AnyHashable : Any]) -> [AnyHashable : Any]?

    Parameters

    orderNumber

    Order Dictionary returned by orderNumber

    shipping

    Order Dictionary returned by shipping

    discount

    Order Dictionary returned by discount

    cart

    Order Dictionary returned by cart

Location

  • Set location delegate

    Declaration

    Swift

    public func setLocationDelegate(_ delegate: LocationDelegate?)

    Parameters

    delegate

    Location delegate

  • Returns region from collection of region

    Declaration

    Swift

    public func regionFrom(dictionary: [AnyHashable : Any]) -> CLRegion?

    Parameters

    dictionary

    Collection of region

  • Returns if location is enabled in the SDK

    Declaration

    Swift

    public func locationEnabled() -> Bool
  • Enables the co-ordinates tracking on the device

    Declaration

    Swift

    public func startWatchingLocation()
  • Disables the co-ordinates tracking on the device

    Declaration

    Swift

    public func stopWatchingLocation()
  • Returns if location watching is enabled or not

    Declaration

    Swift

    public func watchingLocation() -> Bool
  • Returns last known location

    Declaration

    Swift

    public func lastKnownLocation() -> [String : String]?