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 MobilePush attributes and message custom 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 MobilePush 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 key’s for this MobilePush 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}