MarketingCloudSdk

Class

This class is a Swift Interface for SFMarketingCloudSdk

Declaration 

1@objc(SFMarketingCloudSdk)
2public final class MarketingCloudSdk : NSObject, SFMCModule, Publisher
3
4@objc
5public static func requestSdk(_ callback: @escaping (_ marketingCloudSdk: MarketingCloudSdkInterface?) -> Void)
6
7@objc
8public static func metadata() -> [String : Any]
9
10public func refresh(fetchCompletionHandler completionHandler: ((UIBackgroundFetchResult) -> Void)?) -> Bool
11
12public func setDebugLoggingEnabled(_ enabled: Bool)
13
14@objc
15public static func getLogger() -> ModuleLogger
16
17public func contactKey() -> String?
18
19public func addTag(_ tag: String) -> Bool
20
21public func addTags(_ tags: [Any]) -> Set<AnyHashable>?
22
23public func removeTag(_ tag: String) -> Bool
24
25public func tags() -> Set<AnyHashable>?
26
27public func attributes() -> [AnyHashable : Any]?
28
29public func accessToken() -> String?
30
31public func deviceIdentifier() -> String?
32
33public func setSignedString(_ signedString: String?) -> Bool
34
35public func signedString() -> String?
36
37public func setRegistrationCallback(_ registrationCallback: @escaping (Dictionary<AnyHashable, Any>) -> Void)
38
39public func unsetRegistrationCallback()
40
41public func setAnalyticsEnabled(_ analyticsEnabled: Bool)
42
43public func isAnalyticsEnabled() -> Bool
44
45public func setPiAnalyticsEnabled(_ analyticsEnabled: Bool)
46
47public func isPiAnalyticsEnabled() -> Bool
48
49public func isLocationEnabled() -> Bool
50
51public func setLocationEnabled(_ locationEnabled: Bool)
52
53public func isInboxEnabled() -> Bool
54
55public func setInboxEnabled(_ inboxEnabled: Bool)
56
57public func getAllMessages() -> [Any]?
58
59public func getUnreadMessages() -> [Any]?
60
61public func getReadMessages() -> [Any]?
62
63public func getDeletedMessages() -> [Any]?
64
65public func getAllMessagesCount() -> UInt
66
67public func getUnreadMessagesCount() -> UInt
68
69public func getReadMessagesCount() -> UInt
70
71public func getDeletedMessagesCount() -> UInt
72
73public func markMessageRead(_ messageDictionary: [AnyHashable : Any]) -> Bool
74
75public func markMessageDeleted(_ messageDictionary: [AnyHashable : Any]) -> Bool
76
77public func markMessageWithIdRead(messageId: String) -> Bool
78
79public func markMessageWithIdDeleted(messageId: String) -> Bool
80
81public func markAllMessagesRead() -> Bool
82
83public func markAllMessagesDeleted() -> Bool
84
85public func refreshMessages() -> Bool
86
87public func setPiIdentifier(_ identifier: String?) -> Bool
88
89public func piIdentifier() -> String?
90
91public func trackMessageOpened(_ inboxMessage: [AnyHashable : Any])
92
93public func trackPageView(url: String, title: String?, item: String?, search: String?)
94
95public func trackCartContents(_ cartDictionary: [AnyHashable : Any])
96
97public func trackCartConversion(_ orderDictionary: [AnyHashable : Any])
98
99public func cartItemDictionary(price: NSNumber, quantity: NSNumber, item: String, uniqueId: String?) -> [AnyHashable : Any]?
100
101public func cartDictionary(cartItem: [Any]) -> [AnyHashable : Any]?
102
103public func orderDictionary(orderNumber: String, shipping: NSNumber, discount: NSNumber, cart: [AnyHashable : Any]) -> [AnyHashable : Any]?
104
105public func setLocationDelegate(_ delegate: LocationDelegate?)
106
107public func regionFrom(dictionary: [AnyHashable : Any]) -> CLRegion?
108
109public func locationEnabled() -> Bool
110
111public func startWatchingLocation()
112
113public func stopWatchingLocation()
114
115public func watchingLocation() -> Bool
116
117public 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.

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

Push Methods 

metadata() 

This method is to get the SDK metadata

1@objc
2public 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.

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

Logging Methods 

setDebugLoggingEnabled(_:) 

Enable/Disable extra debug logging from the SDK.

1public func setDebugLoggingEnabled(_ enabled: Bool)

getLogger() 

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

1@objc
2public static func getLogger() -> ModuleLogger

Registration Methods 

contactKey() 

1public 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.

1public 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.

1public 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.

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

Returns: YES if removed successfully.


tags() 

Returns the list of tags for this device.

1public 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.

1public func attributes() -> [AnyHashable : Any]?

accessToken() 

Returns the Salesforce application accessToken.

1public func accessToken() -> String?

deviceIdentifier() 

Returns the unique device identifier that Salesforce will use to identify the device.

1public func deviceIdentifier() -> String?

setSignedString(_:) 

Add a signedString security token for registration security

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

signedString() 

Returns the value of last stored signedString security token

1public 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

1public 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

1public 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.

1public func setAnalyticsEnabled(_ analyticsEnabled: Bool)

isAnalyticsEnabled() 

The current state of the Analytics enablement override

1public 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.

1public func setPiAnalyticsEnabled(_ analyticsEnabled: Bool)

isPiAnalyticsEnabled() 

The current state of the PI Analytics enablement override

1public func isPiAnalyticsEnabled() -> Bool

isLocationEnabled() 

The current state of the Location enablement override

1public 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.

1public func setLocationEnabled(_ locationEnabled: Bool)

isInboxEnabled() 

The current state of the Inbox enablement override

1public 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.

1public func setInboxEnabled(_ inboxEnabled: Bool)

InboxMessages 

getAllMessages() 

Returns an array of all messages that includes read, unread , deleted messages Public properties in inbox message dictionary

1public 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

1public func getUnreadMessages() -> [Any]?

getReadMessages() 

Returns an array of read messages Public properties in inbox message dictionary

1public func getReadMessages() -> [Any]?

getDeletedMessages() 

Returns an array of deleted messages Public properties in inbox message dictionary

1public func getDeletedMessages() -> [Any]?

getAllMessagesCount() 

Returns all messages count

1public func getAllMessagesCount() -> UInt

getUnreadMessagesCount() 

Returns unread messages count

1public func getUnreadMessagesCount() -> UInt

getReadMessagesCount() 

Returns read messages count

1public func getReadMessagesCount() -> UInt

getDeletedMessagesCount() 

Returns deleted messages count

1public func getDeletedMessagesCount() -> UInt

markMessageRead(_:) 

Mark the unread messages as read

1public func markMessageRead(_ messageDictionary: [AnyHashable : Any]) -> Bool

markMessageDeleted(_:) 

Mark the messages as deleted

1public func markMessageDeleted(_ messageDictionary: [AnyHashable : Any]) -> Bool

markMessageWithIdRead(messageId:) 

Mark the message with specific messageId as read

1public func markMessageWithIdRead(messageId: String) -> Bool

markMessageWithIdDeleted(messageId:) 

Mark the message with specific messageId as deleted

1public func markMessageWithIdDeleted(messageId: String) -> Bool

markAllMessagesRead() 

Mark all the messages with specific messageId as read

1public func markAllMessagesRead() -> Bool

markAllMessagesDeleted() 

Mark all the messages with specific messageId as deleted

1public 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

1public func refreshMessages() -> Bool

Intelligence 

setPiIdentifier(_:) 

Set String identifier

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

piIdentifier() 

Returns piIdentifier

1public func piIdentifier() -> String?

trackMessageOpened(_:) 

Track the inbox messages that are opened in the app

1public func trackMessageOpened(_ inboxMessage: [AnyHashable : Any])

trackPageView(url:title:item:search:) 

Track the pageview visited in the page

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

trackCartContents(_:) 

Track contents in the cart

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

trackCartConversion(_:) 

Track Conversion on the items in the cart

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

cartItemDictionary(price:quantity:item:uniqueId:) 

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

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

cartDictionary(cartItem:) 

Returns cart Dictionary with cartItem

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

orderDictionary(orderNumber:shipping:discount:cart:) 

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

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

Location 

setLocationDelegate(_:) 

Set location delegate

1public func setLocationDelegate(_ delegate: LocationDelegate?)

regionFrom(dictionary:) 

Returns region from collection of region

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

locationEnabled() 

Returns if location is enabled in the SDK

1public func locationEnabled() -> Bool

startWatchingLocation() 

Enables the co-ordinates tracking on the device

1public func startWatchingLocation()

stopWatchingLocation() 

Disables the co-ordinates tracking on the device

1public func stopWatchingLocation()

watchingLocation() 

Returns if location watching is enabled or not

1public func watchingLocation() -> Bool

lastKnownLocation() 

Returns last known location

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