Cet article donne aux développeurs les informations nécessaires à l'installation du gestionnaire de message personnalisé.
Table des matières
Introduction
Les marketeurs ont l'opportunité de configurer les contenus des données utiles (payload) JSON d'une campagne de l'intérieur des paramètres de création de campagne sur le compte Emarsys. Afin que les données additionnelles transmises à l'app aient le résultat désiré, un gestionnaire d'événement personnalisé doit être implémenté.

Les exemples de code ci-dessous montrent comment il est possible de gérer les données utiles (payload) JSON si la clé a été réglée sur campaign_id
avec la valeur de summer_sale.
iOS
Objectifs-C
AppDelegate.h @interface AppDelegate : UIResponder <UIApplicationDelegate, EMSEventHandler> // @end AppDelegate.m @implementation AppDelegate - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { // [UNUserNotificationCenter.currentNotificationCenter setDelegate: Emarsys.notificationCenterDelegate]; [Emarsys.notificationCenterDelegate setEventHandler: self]; [Emarsys.inApp setEventHandler: self]; // } // - (void)handleEvent:(NSString *)eventName payload:(nullable NSDictionary<NSString *, NSObject *> *)payload { if ([eventName isEqual: @"OpenSalesCampaign"]) { NSString *campaignId = (NSString *)payload[@"campaign_id"]; if (campaignId != nil) { // navigate to the Sales campaign view } } }
Swift
class AppDelegate: UIResponder, UIApplicationDelegate, EMSEventHandler { func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool { // UNUserNotificationCenter.current().delegate = Emarsys.notificationCenterDelegate Emarsys.notificationCenterDelegate.eventHandler = self Emarsys.inApp.eventHandler = self // } // func handleEvent(_ eventName: String, payload: [String : NSObject]?) { if eventName == "OpenSalesCampaign", let campaignId = payload?["campaign_id"] as? String { // navigate to the Sales campaign view } } }
Android
Java
public class ApplicationClass extends Application implements EventHandler { @Override public void onCreate() { super.onCreate(); // Emarsys.getPush().setNotificationEventHandler(this); Emarsys.getInApp().setEventHandler(this); // ... } // @Override public void handleEvent(@NotNull Context context, @NotNull String eventName, @Nullable JSONObject payload) { if ("OpenSalesCampaign".equals(eventName)) { try { String campaignId = payload.getString("campaign_id"); if (campaignId != null) { // navigate to the Sales campaign view } } catch (ex: Exception) { // ... } } } }
Kotlin
class ApplicationClass : Application(), EventHandler { override fun onCreate() { super.onCreate() // Emarsys.push.setNotificationEventHandler(this) Emarsys.inApp.setEventHandler(this) // } // override fun handleEvent(context: Context, eventName: String, payload: JSONObject?) { if ("OpenSalesCampaign".equals(eventName)) { try { payload?.getString("campaign_id").let { // navigate to the Sales campaign view } } catch (ex: Exception) { // ... } } } }