Class
This class is a Swift Interface for SFMarketingCloudSdk
Declaration
@objc(SFMarketingCloudSdk)
public final class MarketingCloudSdk : NSObject, SFMCModule, Publisher
@objc
public static func requestSdk(_ callback: @escaping (_ marketingCloudSdk: MarketingCloudSdkInterface?) -> Void)
@objc
public static func metadata() -> [String : Any]
public func refresh(fetchCompletionHandler completionHandler: ((UIBackgroundFetchResult) -> Void)?) -> Bool
public func setDebugLoggingEnabled(_ enabled: Bool)
@objc
public static func getLogger() -> ModuleLogger
public func contactKey() -> String?
public func addTag(_ tag: String) -> Bool
public func addTags(_ tags: [Any]) -> Set<AnyHashable>?
public func removeTag(_ tag: String) -> Bool
public func tags() -> Set<AnyHashable>?
public func attributes() -> [AnyHashable : Any]?
public func accessToken() -> String?
public func deviceIdentifier() -> String?
public func setSignedString(_ signedString: String?) -> Bool
public func signedString() -> String?
public func setRegistrationCallback(_ registrationCallback: @escaping (Dictionary<AnyHashable, Any>) -> Void)
public func unsetRegistrationCallback()
public func setAnalyticsEnabled(_ analyticsEnabled: Bool)
public func isAnalyticsEnabled() -> Bool
public func setPiAnalyticsEnabled(_ analyticsEnabled: Bool)
public func isPiAnalyticsEnabled() -> Bool
public func isLocationEnabled() -> Bool
public func setLocationEnabled(_ locationEnabled: Bool)
public func isInboxEnabled() -> Bool
public func setInboxEnabled(_ inboxEnabled: Bool)
public func getAllMessages() -> [Any]?
public func getUnreadMessages() -> [Any]?
public func getReadMessages() -> [Any]?
public func getDeletedMessages() -> [Any]?
public func getAllMessagesCount() -> UInt
public func getUnreadMessagesCount() -> UInt
public func getReadMessagesCount() -> UInt
public func getDeletedMessagesCount() -> UInt
public func markMessageRead(_ messageDictionary: [AnyHashable : Any]) -> Bool
public func markMessageDeleted(_ messageDictionary: [AnyHashable : Any]) -> Bool
public func markMessageWithIdRead(messageId: String) -> Bool
public func markMessageWithIdDeleted(messageId: String) -> Bool
public func markAllMessagesRead() -> Bool
public func markAllMessagesDeleted() -> Bool
public func refreshMessages() -> Bool
public func setPiIdentifier(_ identifier: String?) -> Bool
public func piIdentifier() -> String?
public func trackMessageOpened(_ inboxMessage: [AnyHashable : Any])
public func trackPageView(url: String, title: String?, item: String?, search: String?)
public func trackCartContents(_ cartDictionary: [AnyHashable : Any])
public func trackCartConversion(_ orderDictionary: [AnyHashable : Any])
public func cartItemDictionary(price: NSNumber, quantity: NSNumber, item: String, uniqueId: String?) -> [AnyHashable : Any]?
public func cartDictionary(cartItem: [Any]) -> [AnyHashable : Any]?
public func orderDictionary(orderNumber: String, shipping: NSNumber, discount: NSNumber, cart: [AnyHashable : Any]) -> [AnyHashable : Any]?
public func setLocationDelegate(_ delegate: LocationDelegate?)
public func regionFrom(dictionary: [AnyHashable : Any]) -> CLRegion?
public func locationEnabled() -> Bool
public func startWatchingLocation()
public func stopWatchingLocation()
public func watchingLocation() -> Bool
public func lastKnownLocation() -> [String : String]?
Request SDK Method
requestSdk(_:)
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.
@objc
public static func requestSdk(_ callback: @escaping (_ marketingCloudSdk: MarketingCloudSdkInterface?) -> Void)
Push Methods
metadata()
This method is to get the SDK metadata
@objc
public static func metadata() -> [String : Any]
refresh(fetchCompletionHandler:)
Ask MarketingCloudSDK to update its data. MarketingCloudSDK will throttle attempts based on the time since the last time this was called.
public func refresh(fetchCompletionHandler completionHandler: ((UIBackgroundFetchResult) -> Void)?) -> Bool
Logging Methods
setDebugLoggingEnabled(_:)
Enable/Disable extra debug logging from the SDK.
public func setDebugLoggingEnabled(_ enabled: Bool)
getLogger()
Unified Logger initialized for ‘MarketingCloudSdk’ Module Usage Example: MarketingCloudSdk.shared.getLogger().d(category: .event, message: “Message”)
@objc
public static func getLogger() -> ModuleLogger
Registration Methods
contactKey()
public func contactKey() -> String?
Returns: Contact key String that is set in the application.
addTag(_:)
Adds the provided Tag (NSString) to the set of unique tags.
public func addTag(_ tag: String) -> Bool
Returns: YES if added successfully.
addTags(_:)
Adds the provided array of Tags (NSString) to the set of unique tags. Will trim leading and trailing whitespace. Cannot be nil or blank.
public func addTags(_ tags: [Any]) -> Set<AnyHashable>?
Returns: Set of tags added, as strings, or nil if something failed.
removeTag(_:)
Removes the provided Tag (NSString) from the list of tags.
public func removeTag(_ tag: String) -> Bool
Returns: YES if removed successfully.
tags()
Returns the list of tags for this device.
public func tags() -> Set<AnyHashable>?
Returns: All tags associated, as strings.
attributes()
Returns a read-only copy of the Attributes dictionary as it is right now.
public func attributes() -> [AnyHashable : Any]?
accessToken()
Returns the Salesforce application accessToken.
public func accessToken() -> String?
deviceIdentifier()
Returns the unique device identifier that Salesforce will use to identify the device.
public func deviceIdentifier() -> String?
setSignedString(_:)
Add a signedString security token for registration security
public func setSignedString(_ signedString: String?) -> Bool
signedString()
Returns the value of last stored signedString security token
public func signedString() -> String?
setRegistrationCallback(_:)
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
public func setRegistrationCallback(_ registrationCallback: @escaping (Dictionary<AnyHashable, Any>) -> Void)
unsetRegistrationCallback()
Removes the registration callback @see: https://salesforce-marketingcloud.github.io/MarketingCloudSDK-iOS/sdk-implementation/user-data.html
public func unsetRegistrationCallback()
Feature Toggle Methods
setAnalyticsEnabled(_:)
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.
public func setAnalyticsEnabled(_ analyticsEnabled: Bool)
isAnalyticsEnabled()
The current state of the Analytics enablement override
public func isAnalyticsEnabled() -> Bool
setPiAnalyticsEnabled(_:)
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.
public func setPiAnalyticsEnabled(_ analyticsEnabled: Bool)
isPiAnalyticsEnabled()
The current state of the PI Analytics enablement override
public func isPiAnalyticsEnabled() -> Bool
isLocationEnabled()
The current state of the Location enablement override
public func isLocationEnabled() -> Bool
setLocationEnabled(_:)
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.
public func setLocationEnabled(_ locationEnabled: Bool)
isInboxEnabled()
The current state of the Inbox enablement override
public func isInboxEnabled() -> Bool
setInboxEnabled(_:)
Developer override to set the state of Inbox enablement to YES/NO. If set to NO, Inbox feature will be disabled. This value takes precedence over the config setting which is passed during the SDK initialization.
public func setInboxEnabled(_ inboxEnabled: Bool)
InboxMessages
getAllMessages()
Returns an array of all messages that includes read, unread , deleted messages Public properties in inbox message dictionary
public func getAllMessages() -> [Any]?
Returns: an Array of Dictionary containing all messages (read, unread and deleted)
getUnreadMessages()
Returns an array of unread messages Public properties in inbox message dictionary
public func getUnreadMessages() -> [Any]?
getReadMessages()
Returns an array of read messages Public properties in inbox message dictionary
public func getReadMessages() -> [Any]?
getDeletedMessages()
Returns an array of deleted messages Public properties in inbox message dictionary
public func getDeletedMessages() -> [Any]?
getAllMessagesCount()
Returns all messages count
public func getAllMessagesCount() -> UInt
getUnreadMessagesCount()
Returns unread messages count
public func getUnreadMessagesCount() -> UInt
getReadMessagesCount()
Returns read messages count
public func getReadMessagesCount() -> UInt
getDeletedMessagesCount()
Returns deleted messages count
public func getDeletedMessagesCount() -> UInt
markMessageRead(_:)
Mark the unread messages as read
public func markMessageRead(_ messageDictionary: [AnyHashable : Any]) -> Bool
markMessageDeleted(_:)
Mark the messages as deleted
public func markMessageDeleted(_ messageDictionary: [AnyHashable : Any]) -> Bool
markMessageWithIdRead(messageId:)
Mark the message with specific messageId as read
public func markMessageWithIdRead(messageId: String) -> Bool
markMessageWithIdDeleted(messageId:)
Mark the message with specific messageId as deleted
public func markMessageWithIdDeleted(messageId: String) -> Bool
markAllMessagesRead()
Mark all the messages with specific messageId as read
public func markAllMessagesRead() -> Bool
markAllMessagesDeleted()
Mark all the messages with specific messageId as deleted
public func markAllMessagesDeleted() -> Bool
refreshMessages()
Fetches and refreshes messages from server Reload and refresh Inbox messages from the Marketing Cloud server. Note: The underlying request to the server will be throttled such that it will execute at most every 60 seconds. If the method has been called less than 60 seconds after the preceeding method call, NO will be returned and the request will not be made. If NO is returned, best practice is that any UI used to reflect the refresh operation is updated (pull to refresh indicators, loading spinners, etc.). DDoS Protection The SDK has several built in mechanisms to protect Marketing Cloud servers and services. For message GET routes, we allow at most one manual refresh request per minute. This prevents bad application implementations or mobile app users from calling refresh over and over when there will be no new data available. Within the SDK and it’s logging, this presents a 429 - Too Many Requests log statement. Throttling To protect the workload and ensure optimal performance, the Inbox Message routes may throttle incoming requests. This throttling is based on adaptive logic, which operates as a percentage of traffic depending on the current load. The system is designed to automatically determine when throttling is necessary or when it can be reduced. During periods of traffic throttling, some customer requests may receive a 429 - Too Many Requests response. This will log a 429 response within the SDK. The Marketing Cloud has considerable server-side logic to monitor and adjust this throttling mechanism. This method will cause notifications to be posted to NSNotificationCenter: SFMCInboxMessagesRefreshCompleteNotification: posted when the refresh process has completed SFMCInboxMessagesNewInboxMessagesNotification: posted if there are new Inbox messages
public func refreshMessages() -> Bool
Intelligence
setPiIdentifier(_:)
Set String identifier
public func setPiIdentifier(_ identifier: String?) -> Bool
piIdentifier()
Returns piIdentifier
public func piIdentifier() -> String?
trackMessageOpened(_:)
Track the inbox messages that are opened in the app
public func trackMessageOpened(_ inboxMessage: [AnyHashable : Any])
trackPageView(url:title:item:search:)
Track the pageview visited in the page
public func trackPageView(url: String, title: String?, item: String?, search: String?)
trackCartContents(_:)
Track contents in the cart
public func trackCartContents(_ cartDictionary: [AnyHashable : Any])
trackCartConversion(_:)
Track Conversion on the items in the cart
public func trackCartConversion(_ orderDictionary: [AnyHashable : Any])
cartItemDictionary(price:quantity:item:uniqueId:)
Returns cartItem Dictionary with specific price, quantity, item and Id
public func cartItemDictionary(price: NSNumber, quantity: NSNumber, item: String, uniqueId: String?) -> [AnyHashable : Any]?
cartDictionary(cartItem:)
Returns cart Dictionary with cartItem
public func cartDictionary(cartItem: [Any]) -> [AnyHashable : Any]?
orderDictionary(orderNumber:shipping:discount:cart:)
Returns order Dictionary with ordernumber, shipping number, discount, cart dictionary
public func orderDictionary(orderNumber: String, shipping: NSNumber, discount: NSNumber, cart: [AnyHashable : Any]) -> [AnyHashable : Any]?
Location
setLocationDelegate(_:)
Set location delegate
public func setLocationDelegate(_ delegate: LocationDelegate?)
regionFrom(dictionary:)
Returns region from collection of region
public func regionFrom(dictionary: [AnyHashable : Any]) -> CLRegion?
locationEnabled()
Returns if location is enabled in the SDK
public func locationEnabled() -> Bool
startWatchingLocation()
Enables the co-ordinates tracking on the device
public func startWatchingLocation()
stopWatchingLocation()
Disables the co-ordinates tracking on the device
public func stopWatchingLocation()
watchingLocation()
Returns if location watching is enabled or not
public func watchingLocation() -> Bool
lastKnownLocation()
Returns last known location
public func lastKnownLocation() -> [String : String]?