Configure Marketing Cloud Engagement
Runtime Toggles
Add Beacon Support
Enable Background Location Updates
Segment Location Messages
Event Tracking
Handle URLs
Data Protection and Privacy
Changelog
You can deliver location messages to a subset of your audience by using the Salesforce Engagement SDK. When a mobile device breaks a geofence or comes into proximity of a Bluetooth beacon, the SDK triggers a callback to your mobile app. This callback is used to evaluate whether to show the message.
To determine whether to show the message, your app can apply criteria, including information within the message itself. For example, your app can:
1// Adopt the protocol in your app's class, which implements the
2// sfmc_shouldShowLocationMessage:forRegion: method
3class AppDelegate: UIResponder, UIApplicationDelegate, LocationDelegate
4
5...
6// After configuring the SDK, set the location delegate to the class that
7// implements the sfmc_shouldShowLocationMessage:forRegion: method
8MarketingCloudSdk.requestSdk { mc in
9 mc?.setLocationDelegate(self)
10}
11
12// Implement the method to evaluate app logic to determine if a message should
13// be shown. This example uses attributes and custom message keys to
14// implement simple matching logic. Your implementation will vary according to
15// your unique needs.
16func sfmc_shouldShowLocationMessage(
17 _ message: [AnyHashable : Any],
18 forRegion region: [AnyHashable : Any]
19) -> Bool {
20 var shouldShow = false
21 var attributesLoyaltyLevel = ""
22
23 // Get a contact attribute previously set by your app from the SDK
24 // In this example, "loyaltyLevel" indicates a customer contact value that
25 // your app uses.
26 var attributes: [AnyHashable : Any]? = nil
27 MarketingCloudSdk.requestSdk { mc in
28 attributes = mc?.attributes()
29 }
30
31 if attributes?.index(forKey: "loyaltyLevel") != nil {
32 attributesLoyaltyLevel = attributes!["loyaltyLevel"] as! String
33 }
34
35 // Get the custom keys for a location message
36 if (message["keys"] != nil) {
37 let customKeys = message["keys"] as! [AnyHashable : Any]
38 // get the "loyaltyLevel" custom key's value
39 let messageLoyaltyLevel = customKeys["loyaltyLevel"] as! String
40
41 // in this example, if the customer contact attribute is set to "gold"
42 // AND the message's custom key is "gold", return true - this message
43 // is valid to show for this customer
44
45 // the SDK will display the location message, as the critera passed
46 if (attributesLoyaltyLevel == "gold" && messageLoyaltyLevel == "gold") {
47 shouldShow = true
48 }
49 }
50 return shouldShow
51}1// Adopt the protocol in your app's class, which implements the
2// sfmc_shouldShowLocationMessage:forRegion: method
3class AppDelegate: UIResponder, UIApplicationDelegate, LocationDelegate
4
5...
6// After configuring the SDK, set the location delegate to the class that
7// implements the sfmc_shouldShowLocationMessage:forRegion: method
8SFMCSdk.requestPushSdk { mp in
9 mp.setLocationDelegate(self)
10}
11...
12
13// Implement the method to evaluate app logic to determine if a message should
14// be shown. This example uses attributes and message custom keys to
15// implement simple matching logic. Your implementation will vary according to
16// your unique needs.
17func sfmc_shouldShowLocationMessage(
18 _ message: [AnyHashable : Any],
19 forRegion region: [AnyHashable : Any]
20) -> Bool {
21 var shouldShow = false
22 var attributesLoyaltyLevel = ""
23
24 // Get a contact attribute previously set by your app from the SDK
25 // In this example, "loyaltyLevel" indicates a customer contact value that
26 // your app uses.
27 var attributes: [AnyHashable : Any]? = nil
28 SFMCSdk.requestPushSdk { mp in
29 attributes = mp.attributes()
30 }
31
32 if attributes?.index(forKey: "loyaltyLevel") != nil {
33 attributesLoyaltyLevel = attributes!["loyaltyLevel"] as! String
34 }
35
36 // Get the custom keys for a location message
37 if (message["keys"] != nil) {
38 let customKeys = message["keys"] as! [AnyHashable : Any]
39 // get the "loyaltyLevel" custom key's value
40 let messageLoyaltyLevel = customKeys["loyaltyLevel"] as! String
41
42 // in this example, if the customer contact attribute is set to "gold"
43 // AND the message's custom key is "gold", return true - this message
44 // is valid to show for this customer
45
46 // the SDK will display the location message, as the critera passed
47 if (attributesLoyaltyLevel == "gold" && messageLoyaltyLevel == "gold") {
48 shouldShow = true
49 }
50 }
51 return shouldShow
52}1// adopt the protocol in your application's class which will implement the sfmc_shouldShowLocationMessage:forRegion: method
2class AppDelegate: UIResponder, UIApplicationDelegate, MarketingCloudSDKLocationDelegate
3
4...
5// after configuring your SDK, set the location delegate to your class implementing the sfmc_shouldShowLocationMessage:forRegion: method
6MarketingCloudSDK.sharedInstance().sfmc_setLocationDelegate(self)
7...
8
9// Implement the method to evaluate application logic to determine if a message should be shown.
10// This example uses attributes and message custom keys to implement simple matching logic.
11func sfmc_shouldShowLocationMessage(_ message: [AnyHashable : Any], forRegion region: [AnyHashable : Any]) -> Bool {
12 var shouldShow = false
13 var attributesLoyaltyLevel = ""
14
15 // Get a contact attribute previously set by your app from the SDK.
16 // In this example, "loyaltyLevel" indicates a customer contact value your solution uses.
17 var attributes = MarketingCloudSDK.sharedInstance().sfmc_attributes()
18 if attributes?.index(forKey: "loyaltyLevel") != nil {
19 attributesLoyaltyLevel = attributes!["loyaltyLevel"] as! String
20 }
21
22 // Get the custom keys for the location message
23 if (message["keys"] != nil) {
24 let customKeys = message["keys"] as! [AnyHashable : Any]
25 // get the "loyaltyLevel" custom key's value
26 let messageLoyaltyLevel = customKeys["loyaltyLevel"] as! String
27
28 // in this example, if the customer contact attribute is set to "gold"
29 // AND the message's custom key is "gold", return true - this message
30 // is valid to show for this customer
31
32 // the SDK will display the location message, as the critera passed
33 if (attributesLoyaltyLevel == "gold" && messageLoyaltyLevel == "gold") {
34 shouldShow = true
35 }
36 }
37 return shouldShow
38}