---
schema_version: "1"
id: bbeabe7fdefc8868ec45f582a0f1a97c3dd02e8ca51752bf91e232402bb93492
title: MarketingCloudSdk
collection: developer
version: current
locale: en-us
portal_url: https://docs.salesforce.com/developer/current/en-us/marketing-cloud-mobilepush/engagement_sdk/references/ios-sdk-v11/mce-sdk/classes/marketingcloudsdk.md
canonical_url: https://developer.salesforce.com/docs/marketing/mobile-unified-sdk/references/engagement-mobile-sdk-reference/marketingcloudsdk.html
source_site: developer.salesforce.com
content_type: documentation
content_hash: 952374b578f8a4a5b29c94d84ccbfdac4e0e1e71c119e5b28aa413510700aa50
products:
  - Salesforce Engagement SDK
---
# MarketingCloudSdk

`Class`

This class is a Swift Interface for SFMarketingCloudSdk

## Declaration

```swift
@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.

```swift
@objc
public static func requestSdk(_ callback: @escaping (_ marketingCloudSdk: MarketingCloudSdkInterface?) -> Void)
```

---

## Push Methods

### `metadata()`

This method is to get the SDK metadata

```swift
@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.

```swift
public func refresh(fetchCompletionHandler completionHandler: ((UIBackgroundFetchResult) -> Void)?) -> Bool
```

---

## Logging Methods

### `setDebugLoggingEnabled(_:)`

Enable/Disable extra debug logging from the SDK.

```swift
public func setDebugLoggingEnabled(_ enabled: Bool)
```

---

### `getLogger()`

Unified Logger initialized for ‘MarketingCloudSdk’ Module Usage Example: MarketingCloudSdk.shared.getLogger().d(category: .event, message: “Message”)

```swift
@objc
public static func getLogger() -> ModuleLogger
```

---

## Registration Methods

### `contactKey()`

```swift
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.

```swift
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.

```swift
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.

```swift
public func removeTag(_ tag: String) -> Bool
```

**Returns:** YES if removed successfully.

---

### `tags()`

Returns the list of tags for this device.

```swift
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.

```swift
public func attributes() -> [AnyHashable : Any]?
```

---

### `accessToken()`

Returns the Salesforce application accessToken.

```swift
public func accessToken() -> String?
```

---

### `deviceIdentifier()`

Returns the unique device identifier that Salesforce will use to identify the device.

```swift
public func deviceIdentifier() -> String?
```

---

### `setSignedString(_:)`

Add a signedString security token for registration security

```swift
public func setSignedString(_ signedString: String?) -> Bool
```

---

### `signedString()`

Returns the value of last stored signedString security token

```swift
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

```swift
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

```swift
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.

```swift
public func setAnalyticsEnabled(_ analyticsEnabled: Bool)
```

---

### `isAnalyticsEnabled()`

The current state of the Analytics enablement override

```swift
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.

```swift
public func setPiAnalyticsEnabled(_ analyticsEnabled: Bool)
```

---

### `isPiAnalyticsEnabled()`

The current state of the PI Analytics enablement override

```swift
public func isPiAnalyticsEnabled() -> Bool
```

---

### `isLocationEnabled()`

The current state of the Location enablement override

```swift
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.

```swift
public func setLocationEnabled(_ locationEnabled: Bool)
```

---

### `isInboxEnabled()`

The current state of the Inbox enablement override

```swift
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.

```swift
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

```swift
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

```swift
public func getUnreadMessages() -> [Any]?
```

---

### `getReadMessages()`

Returns an array of read messages Public properties in inbox message dictionary

```swift
public func getReadMessages() -> [Any]?
```

---

### `getDeletedMessages()`

Returns an array of deleted messages Public properties in inbox message dictionary

```swift
public func getDeletedMessages() -> [Any]?
```

---

### `getAllMessagesCount()`

Returns all messages count

```swift
public func getAllMessagesCount() -> UInt
```

---

### `getUnreadMessagesCount()`

Returns unread messages count

```swift
public func getUnreadMessagesCount() -> UInt
```

---

### `getReadMessagesCount()`

Returns read messages count

```swift
public func getReadMessagesCount() -> UInt
```

---

### `getDeletedMessagesCount()`

Returns deleted messages count

```swift
public func getDeletedMessagesCount() -> UInt
```

---

### `markMessageRead(_:)`

Mark the unread messages as read

```swift
public func markMessageRead(_ messageDictionary: [AnyHashable : Any]) -> Bool
```

---

### `markMessageDeleted(_:)`

Mark the messages as deleted

```swift
public func markMessageDeleted(_ messageDictionary: [AnyHashable : Any]) -> Bool
```

---

### `markMessageWithIdRead(messageId:)`

Mark the message with specific messageId as read

```swift
public func markMessageWithIdRead(messageId: String) -> Bool
```

---

### `markMessageWithIdDeleted(messageId:)`

Mark the message with specific messageId as deleted

```swift
public func markMessageWithIdDeleted(messageId: String) -> Bool
```

---

### `markAllMessagesRead()`

Mark all the messages with specific messageId as read

```swift
public func markAllMessagesRead() -> Bool
```

---

### `markAllMessagesDeleted()`

Mark all the messages with specific messageId as deleted

```swift
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

```swift
public func refreshMessages() -> Bool
```

---

## Intelligence

### `setPiIdentifier(_:)`

Set String identifier

```swift
public func setPiIdentifier(_ identifier: String?) -> Bool
```

---

### `piIdentifier()`

Returns piIdentifier

```swift
public func piIdentifier() -> String?
```

---

### `trackMessageOpened(_:)`

Track the inbox messages that are opened in the app

```swift
public func trackMessageOpened(_ inboxMessage: [AnyHashable : Any])
```

---

### `trackPageView(url:title:item:search:)`

Track the pageview visited in the page

```swift
public func trackPageView(url: String, title: String?, item: String?, search: String?)
```

---

### `trackCartContents(_:)`

Track contents in the cart

```swift
public func trackCartContents(_ cartDictionary: [AnyHashable : Any])
```

---

### `trackCartConversion(_:)`

Track Conversion on the items in the cart

```swift
public func trackCartConversion(_ orderDictionary: [AnyHashable : Any])
```

---

### `cartItemDictionary(price:quantity:item:uniqueId:)`

Returns cartItem Dictionary with specific price, quantity, item and Id

```swift
public func cartItemDictionary(price: NSNumber, quantity: NSNumber, item: String, uniqueId: String?) -> [AnyHashable : Any]?
```

---

### `cartDictionary(cartItem:)`

Returns cart Dictionary with cartItem

```swift
public func cartDictionary(cartItem: [Any]) -> [AnyHashable : Any]?
```

---

### `orderDictionary(orderNumber:shipping:discount:cart:)`

Returns order Dictionary with ordernumber, shipping number, discount, cart dictionary

```swift
public func orderDictionary(orderNumber: String, shipping: NSNumber, discount: NSNumber, cart: [AnyHashable : Any]) -> [AnyHashable : Any]?
```

---

## Location

### `setLocationDelegate(_:)`

Set location delegate

```swift
public func setLocationDelegate(_ delegate: LocationDelegate?)
```

---

### `regionFrom(dictionary:)`

Returns region from collection of region

```swift
public func regionFrom(dictionary: [AnyHashable : Any]) -> CLRegion?
```

---

### `locationEnabled()`

Returns if location is enabled in the SDK

```swift
public func locationEnabled() -> Bool
```

---

### `startWatchingLocation()`

Enables the co-ordinates tracking on the device

```swift
public func startWatchingLocation()
```

---

### `stopWatchingLocation()`

Disables the co-ordinates tracking on the device

```swift
public func stopWatchingLocation()
```

---

### `watchingLocation()`

Returns if location watching is enabled or not

```swift
public func watchingLocation() -> Bool
```

---

### `lastKnownLocation()`

Returns last known location

```swift
public func lastKnownLocation() -> [String : String]?
```

---
