SDK's voor campagnes integreren met uw app integrate-campaign-sdk

Met de SDK's voor campagnes voor iOS en Android kunt u de integratie van uw mobiele toepassing in het Adobe Campaign-platform vergemakkelijken.

Ondersteunde versies voor Android en iOS en compatibele versies voor Campagne-SDK's voor Campagne v8 worden weergegeven in de Compatibiliteitsmatrix.

Als Campagnebeheerder kunt u Campagne-SDK's downloaden van de Softwaredistributie Experience Cloud. Neem voor meer informatie contact op met Klantenservice Adoben.

NOTE
U kunt de Adobe Experience Platform Mobile SDK ook gebruiken door de Adobe Campaign-extensie te configureren in de gebruikersinterface voor gegevensverzameling. Meer informatie in documentatie voor ontwikkelaars.

Integratie-instellingen declareren declaring-integration-settings

Als u de campagne-SDK wilt integreren in de mobiele toepassing, moet de functionele beheerder de ontwikkelaar de volgende informatie geven:

  • Een integratiesleutel: om het Adobe Campaign-platform in staat te stellen de mobiele toepassing te identificeren.

    note note
    NOTE
    Deze integratiesleutel wordt ingevoerd in de Adobe Campaign-console, in de Information servicetabblad voor de mobiele toepassing.
  • Een URL voor bijhouden: dat overeenkomt met het adres van de Adobe Campaign-trackingserver.

  • Een marketing-URL: om het verzamelen van abonnementen toe te laten.

  • In Android:

    code language-sql
    Neolane.getInstance().setIntegrationKey("your Adobe mobile app integration key");
    Neolane.getInstance().setMarketingHost("https://yourMarketingHost:yourMarketingPort/");
    Neolane.getInstance().setTrackingHost("https://yourTrackingHost:yourTrackingPort/");
    
  • In iOS:

    code language-sql
    Neolane_SDK *nl = [Neolane_SDK getInstance];
    [nl setMarketingHost:strMktHost];
    [nl setTrackingHost:strTckHost];
    [nl setIntegrationKey:strIntegrationKey];
    

Android-SDK integreren

Android SDK is een jar-bibliotheek geschreven in JAVA. Hiermee kunnen Android-ontwikkelaars integreren met Adobe Campaign: een nieuw apparaat registreren, het apparaat koppelen aan een gebruiker, gedrag bijhouden en meer.

In deze sectie leert u hoe u de Android-SDK kunt gebruiken in een Android-toepassing die Google Firebase Cloud Messaging (FCM).

CAUTION
Voor Campagne v8 gebruikt u Campagne Android SDK v1.1.1.

FCM configureren

Als u de pushmelding wilt gebruiken op Android, moet u een FCM-account hebben, uw Android-toepassing configureren om uw melding te ontvangen en uw toepassing aan de FCM-account te koppelen. Meer informatie in Google-documentatie.

Zie Google-documentatie om Firebase toe te voegen aan uw Android-project.

Leer hoe u FCM kunt implementeren in uw toepassing in Google-documentatie.

NOTE
  • Vergeet niet google-services.json aan uw project te downloaden en toe te voegen.

  • De apiKey moet overeenkomen met de projectKey ingesteld in de Adobe Campaign Mobile-toepassing die is gekoppeld aan deze Android-toepassing.

Android-SDK configureren

  1. De SDK initialiseren

    Voordat u de Android-SDK kunt gebruiken, moet u deze initialiseren. De SDK-initialisatie kan worden uitgevoerd in het dialoogvenster onCreate functie van een activiteit.

    code language-sql
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
    
        // initialize Campaign SDK
        SharedPreferences settings = getSharedPreferences(YourApplicationActivity.APPLICATION_PREF_NAME, Context.MODE_PRIVATE);
    
        Neolane.getInstance().setIntegrationKey(settings.getString(YourApplicationActivity.APPUUID_NAME, YourApplicationActivity.DFT_APPUUID));
        Neolane.getInstance().setMarketingHost(settings.getString(YourApplicationActivity.SOAPRT_NAME, YourApplicationActivity.DFT_SOAPRT));
        Neolane.getInstance().setTrackingHost(settings.getString(YourApplicationActivity.TRACKRT_NAME, YourApplicationActivity.DFT_TRACKRT));
        ...
    }
    

    De IntegrationKey moet overeenkomen met de integratiesleutel die is ingesteld in de Adobe Campaign Mobile-toepassing die is gekoppeld aan deze Android-toepassing.

  2. Het mobiele apparaat registreren op de Adobe Campaign-server

    Met de registratiefunctie kunt u:

    • Stuur de bericht-id of push-id (deviceToken voor iOS en registrationID voor Android) naar Adobe Campaign.
    • de afstemmingssleutel of de gebruikersnaam herstellen (bijvoorbeeld e-mail- of accountnummer)

    U moet uw apparaat registreren bij Adobe Campaign, bij de initialisatie van de app of bij actie van de gebruiker. Het kan gemakkelijk worden gedaan gebruikend registerDevice methode.

    code language-sql
    public void onClick(View v)
    {
    SharedPreferences settings = this.context.getSharedPreferences(YourApplicationActivity.APPLICATION_PREF_NAME, Context.MODE_PRIVATE);
    EditText mailEdit = (EditText) this.context.findViewById(R.id.editText1);
    
    final String FCMRegistrationId = FirebaseInstanceId.getInstance().getToken();
    if (FCMRegistrationId != null)
        NeoTripActivity.registerOnNeolane(this.context, FCMRegistrationId, mailEdit.getText().toString());
    
    }
    

    YourApplicationActivity.java

    code language-sql
    public static void registerOnNeolane(final Context ctx, String registrationId, String userKey)
    {
        NeolaneAsyncRunner neolaneAs = new NeolaneAsyncRunner(Neolane.getInstance());
        // Additional Subscription Parameters
        Map<String,Object> additionnalParam = new HashMap<String, Object>();
        additionnalParam.clear();
        SharedPreferences settings = ctx.getSharedPreferences(YourApplicationActivity.APPLICATION_PREF_NAME, Context.MODE_PRIVATE);
        if (settings.getBoolean(YourApplicationActivity.SUBPARAMEN1_NAME, false))
        {
            additionnalParam.put(settings.getString(YourApplicationActivity.SUBPARAMNAME1_NAME, "") , settings.getString(YourApplicationActivity.SUBPARAMVALUE1_NAME, ""));
        }
        if (settings.getBoolean(YourApplicationActivity.SUBPARAMEN2_NAME, false))
        {
            additionnalParam.put(settings.getString(YourApplicationActivity.SUBPARAMNAME2_NAME, "") , settings.getString(YourApplicationActivity.SUBPARAMVALUE2_NAME, ""));
        }
        if ( additionnalParam.isEmpty() )
        {
            additionnalParam = null;
        }
        // Campaign Registration
        neolaneAs.registerDevice(registrationId, userKey, additionnalParam, ctx, new RequestListener() {
        public void onComplete(String e, Object obj)
        {
            Intent upd = new Intent();
            upd.setAction(BROADCAST_NEWREGISTER_ACTION);
            ctx.sendBroadcast(upd);
        }
    
        public void onNeolaneException(NeolaneException e, Object obj)
        {
            sendErrorMsg(e.getErrorString());
        }
    
        public void onIOException(IOException e, Object obj)
        {
            sendErrorMsg(e.getMessage());
        }
    
        public void sendErrorMsg(String err)
        {
            SharedPreferences.Editor edit = ctx.getSharedPreferences(YourApplicationActivity.APPLICATION_PREF_NAME, Context.MODE_PRIVATE).edit();
            edit.putBoolean(YourApplicationActivity.REGISTRATION_ERROR_NEOLANE_KEYNAME, true);
            edit.commit();
            Intent toast = new Intent();
            toast.setAction(BROADCAST_TOAST_DISPLAY_TEXT);
            toast.putExtra("text", "An error happened, please register again (" + err + ")");
            ctx.sendBroadcast(toast);
        }
        });
    }
    
  3. Campagne waarschuwen wanneer het token van het mobiele apparaat van de gebruiker verandert

    We raden u aan de registerDevice functie wanneer het roepen van onTokenRefresh om Adobe Campaign op de hoogte te brengen van de wijziging in het token voor mobiele apparaten van de gebruiker.

    Bijvoorbeeld:

    YourApplicationFirebaseInstanceIDService.java

    code language-sql
    package com.android.YourApplication;
    
    import android.content.Context;
    import android.content.SharedPreferences;
    import android.util.Log;
    
    import com.google.firebase.iid.FirebaseInstanceId;
    import com.google.firebase.iid.FirebaseInstanceIdService;
    
    import static android.content.SharedPreferences.*;
    
    public class YourApplicationFirebaseInstanceIDService extends FirebaseInstanceIdService
    {
        @Override
        public void onTokenRefresh()
        {
        SharedPreferences settings = getSharedPreferences(YourApplicationActivity.APPLICATION_PREF_NAME, Context.MODE_PRIVATE);
        if (!settings.getBoolean(YourApplicationActivity.USE_GCM, false))
            {
            String refreshedToken = FirebaseInstanceId.getInstance().getToken();
            String userKey = settings.getString(YourApplicationActivity.USERKEY_NAME, "");
            Editor edit = settings.edit();
            edit.putString(YourApplicationActivity.FCM_REGISTRATIONID_NAME, refreshedToken);
            edit.commit();
            YourApplicationActivity.registerOnNeolane(this, refreshedToken, userKey);
            }
        }
    }
    
  4. Firebase Messaging Service configureren

    Breid uit FirebaseMessagingService in de onMessageReceived callback om berichten te ontvangen. We raden u aan de notifyReceive wanneer de onMessageReceived callback wordt geroepen om het volgen van de berichtontvangst op het mobiele apparaat toe te laten. In Adobe Campaign heet dit afdrukken melding: deze functie moet worden aangeroepen vlak voordat het besturingssysteem wordt gevraagd het bericht weer te geven.

    YourApplicationMessagingService.java

    code language-sql
    package com.android.YourApplication;
    
    import android.content.Context;
    import android.content.SharedPreferences;
    import android.os.Bundle;
    import android.util.Log;
    
    import com.google.firebase.messaging.FirebaseMessagingService;
    import com.google.firebase.messaging.RemoteMessage;
    
    import java.util.Iterator;
    import java.util.Map;
    import java.util.Map.Entry;
    
    public class YourApplicationFirebaseMessagingService extends FirebaseMessagingService
        {
        private static final String TAG = "MyFirebaseMsgService";
    
        @Override
        public void onMessageReceived(RemoteMessage message)
            {
            Log.d(TAG, "Receive message from: " + message.getFrom());
            Map<String,String> payloadData = message.getData();
            final Bundle extras = new Bundle();
            final Iterator<Entry<String, String>> iter = payloadData.entrySet().iterator();
            while(iter.hasNext())
            {
            final Entry<String, String>  entry =iter.next();
            extras.putString(entry.getKey(), entry.getValue());
            }
    
            SharedPreferences settings = this.getSharedPreferences(YourApplicationActivity.APPLICATION_PREF_NAME, Context.MODE_PRIVATE);
            String mesg = payloadData.get("_msg");
            String title = payloadData.get("title");
            String url = payloadData.get("url");
            String messageId = payloadData.get("_mId");
            String deliveryId = payloadData.get("_dId");
            YourApplicationActivity.handleNotification(this, mesg, title, url, messageId, deliveryId, extras);
            }
        }
    
    code language-sql
    public static void handleNotification(Context context, String message, String title, String url, String messageId, String deliveryId, Bundle extras)
    {
        if( message == null ) message = "No Content";
        if( title == null )   title = "No title";
        if( url == null )     url = "http://www.tripadvisor.fr";
        int iconId = R.drawable.notif_neotrip;
    
        // notify Adobe Campaign that a notification just arrived
        SharedPreferences settings = context.getSharedPreferences(NeoTripActivity.APPLICATION_PREF_NAME, Context.MODE_PRIVATE);
        Neolane.getInstance().setIntegrationKey(settings.getString(NeoTripActivity.APPUUID_NAME, NeoTripActivity.DFT_APPUUID));
        Neolane.getInstance().setMarketingHost(settings.getString(NeoTripActivity.SOAPRT_NAME, NeoTripActivity.DFT_SOAPRT));
        Neolane.getInstance().setTrackingHost(settings.getString(NeoTripActivity.TRACKRT_NAME, NeoTripActivity.DFT_TRACKRT));
    
        NeolaneAsyncRunner nas = new NeolaneAsyncRunner(Neolane.getInstance());
        nas.notifyReceive(messageId, deliveryId, new NeolaneAsyncRunner.RequestListener() {
        public void onNeolaneException(NeolaneException arg0, Object arg1) {}
        public void onIOException(IOException arg0, Object arg1) {}
        public void onComplete(String arg0, Object arg1){}
        });
        if (yourApplication.isActivityVisible())
        {
        Log.i("INFO", "The application has the focus" );
        ...
        }
        else
        {
        // notification creation
        NotificationManager notificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
        Notification notification;
    
        // Activity to start
        Intent notifIntent = new Intent(context.getApplicationContext(), NotificationActivity.class);
        notifIntent.putExtra("notificationText", message);
        notifIntent.putExtra(NotificationActivity.NOTIFICATION_URL_KEYNAME, url);
        notifIntent.putExtra("_dId", deliveryId);
        notifIntent.putExtra("_mId", messageId);
        notifIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        PendingIntent contentIntent = PendingIntent.getActivity(context, 1, notifIntent, PendingIntent.FLAG_UPDATE_CURRENT);
    
        notification = new Notification.Builder(context)
                .setContentTitle(title)
                .setContentText(message)
                .setSmallIcon(iconId)
                .setContentIntent(contentIntent)
                .build();
    
        // launch the notification
        notification.flags |= Notification.FLAG_AUTO_CANCEL;
        notificationManager.notify(1234, notification);
        }
    }
    
  5. Het spoor opent gegevensberichten

    Voor gegevensberichten kunt u bijhouden wanneer een gebruiker op een bericht klikt om het te openen, met de knop notifyOpening functie. De meldingsactiviteit wordt gemaakt wanneer de gebruiker op het bericht klikt (gemaakt tijdens onMessageReceivedfunctieaanroep)

    code language-sql
    public class NotificationActivity extends Activity {
        public void onCreate(Bundle savedBundle) {
            [...]
            Bundle extra = getIntent().getExtras();
            if (extra != null) {
                // reinit the Campaign sdk
                SharedPreferences settings = getSharedPreferences(NeoTripActivity.APPLICATION_PREF_NAME, Context.MODE_PRIVATE);
                Neolane.getInstance().setIntegrationKey(settings.getString(NeoTripActivity.APPUUID_NAME, NeoTripActivity.DFT_APPUUID));
                Neolane.getInstance().setMarketingHost(settings.getString(NeoTripActivity.SOAPRT_NAME, NeoTripActivity.DFT_SOAPRT));
                Neolane.getInstance().setTrackingHost(settings.getString(NeoTripActivity.TRACKRT_NAME, NeoTripActivity.DFT_TRACKRT));
    
                // Get the messageId and the deliveryId to perform tracking
                String deliveryId = extra.getString("_dId");
                String messageId = extra.getString("_mId");
    
                if (deliveryId != null && messageId != null)
                {
                    try {
                    Neolane.getInstance().notifyOpening(messageId, Integer.valueOf(deliveryId));
                    } catch (NeolaneException e) {
                    // ...
                    } catch (IOException e) {
                    // ...
                    }
                }
            }
        }
    }
    
  6. Het spoor opent en klikt op berichtberichten

    Voor berichtberichten moet het openen/klikken het volgen met notifyOpening functie binnen de startactiviteit van de toepassing, zoals hieronder:

    code language-sql
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
    
        SharedPreferences settings = getSharedPreferences(NeoTripActivity.APPLICATION_PREF_NAME, Context.MODE_PRIVATE);
    
        // initialize Campaign SDK
        Neolane.getInstance().setIntegrationKey(settings.getString(NeoTripActivity.APPUUID_NAME, NeoTripActivity.DFT_APPUUID));
        Neolane.getInstance().setMarketingHost(settings.getString(NeoTripActivity.SOAPRT_NAME, NeoTripActivity.DFT_SOAPRT));
        Neolane.getInstance().setTrackingHost(settings.getString(NeoTripActivity.TRACKRT_NAME, NeoTripActivity.DFT_TRACKRT));
    ...
    ...
    ...
    
        // Manage opening/receive tracking of message notification
        Intent intent = getIntent();
        Bundle data = intent.getExtras();
        String messageId = null, deliveryId = null;
        if( data != null ) {
        if (data.containsKey("_mId")) messageId = data.get("_mId").toString();
        if (data.containsKey("_dId")) deliveryId = data.get("_dId").toString();
        if ( messageId != null && deliveryId != null) {
            Log.i(TAG, "Notify opening from backgroun click_action");
            NeolaneAsyncRunner nas = new NeolaneAsyncRunner(Neolane.getInstance());
            nas.notifyOpening(messageId, deliveryId, new NeolaneAsyncRunner.RequestListener() {
            public void onNeolaneException(NeolaneException arg0, Object arg1) {
                toastMessage( "error", getString(R.string.open_track_sdk_error) + arg0.getErrorCode());
            }
            public void onIOException(IOException arg0, Object arg1) {
                toastMessage( "error", getString(R.string.open_track_io_error) +  arg0.getLocalizedMessage());
            }
            public void onComplete(String arg0, Object arg1) {
                toastMessage( "error", getString(R.string.open_track_ok));
            }
            });
            nas.notifyReceive(messageId, deliveryId, new NeolaneAsyncRunner.RequestListener() {
            public void onNeolaneException(NeolaneException arg0, Object arg1) {
                toastMessage( "error", getString(R.string.rec_track_sdk_error) + arg0.getErrorCode());
            }
            public void onIOException(IOException arg0, Object arg1) {
                toastMessage( "error", getString(R.string.rec_track_io_error) +  arg0.getLocalizedMessage());
            }
            public void onComplete(String arg0, Object arg1) {
                toastMessage( "error", getString(R.string.rec_track_ok));
            }
            });
        }
        }
    }
    
    note note
    NOTE
    Vergelijkbaar beheer moet worden uitgevoerd als de gebruiker click_action in de doelactiviteit.
  7. Tracking ontvangen voor gegevensberichten

    Voor gegevensberichten, wordt het volgen ontvangen bij onMessageReceived oproepniveau. De functie notifyReceive moet worden aangeroepen.

    YourApplicationMessagingService.java

    code language-sql
    package com.android.YourApplication;
    
    import android.content.Context;
    import android.content.SharedPreferences;
    import android.os.Bundle;
    import android.util.Log;
    
    import com.google.firebase.messaging.FirebaseMessagingService;
    import com.google.firebase.messaging.RemoteMessage;
    
    import java.util.Iterator;
    import java.util.Map;
    import java.util.Map.Entry;
    
    
    public class YourApplicationFirebaseMessagingService extends FirebaseMessagingService {
    private static final String TAG = "MyFirebaseMsgService";
    
    @Override
    public void onMessageReceived(RemoteMessage message)
        {
            Log.d(TAG, "Receive message from: " + message.getFrom());
            Map<String,String> payloadData = message.getData();
            final Bundle extras = new Bundle();
            final Iterator<Entry<String, String>> iter = payloadData.entrySet().iterator();
            while(iter.hasNext())
            {
            final Entry<String, String>  entry =iter.next();
            extras.putString(entry.getKey(), entry.getValue());
            }
    
            SharedPreferences settings = this.getSharedPreferences(YourApplicationActivity.APPLICATION_PREF_NAME, Context.MODE_PRIVATE);
            String mesg = payloadData.get("_msg");
            String title = payloadData.get("title");
            String url = payloadData.get("url");
            String messageId = payloadData.get("_mId");
            String deliveryId = payloadData.get("_dId");
            YourApplicationActivity.handleNotification(this, mesg, title, url, messageId, deliveryId, extras);
        }
    }
    
    code language-sql
    public static void handleNotification(Context context, String message, String title, String url, String messageId, String deliveryId, Bundle extras){
        .....
        .....
            // notify Campaign that a notification just arrived
            SharedPreferences settings = context.getSharedPreferences(NeoTripActivity.APPLICATION_PREF_NAME, Context.MODE_PRIVATE);
            Neolane.getInstance().setIntegrationKey(settings.getString(NeoTripActivity.APPUUID_NAME, NeoTripActivity.DFT_APPUUID));
            Neolane.getInstance().setMarketingHost(settings.getString(NeoTripActivity.SOAPRT_NAME, NeoTripActivity.DFT_SOAPRT));
            Neolane.getInstance().setTrackingHost(settings.getString(NeoTripActivity.TRACKRT_NAME, NeoTripActivity.DFT_TRACKRT));
    
            NeolaneAsyncRunner nas = new NeolaneAsyncRunner(Neolane.getInstance());
            nas.notifyReceive(messageId, deliveryId, new NeolaneAsyncRunner.RequestListener() {
                public void onNeolaneException(NeolaneException arg0, Object arg1) {}
                public void onIOException(IOException arg0, Object arg1) {}
                public void onComplete(String arg0, Object arg1){}
        });
    }
    
  8. Tracking ontvangen voor berichtberichten

    Voor berichtberichten, moet de volgende ontvangst op twee niveau worden gevormd:

    • onMessageReceived (toepassing niet op de achtergrond): de implementatie is uitgevoerd in het vorige gedeelte
    • onCreate van de lanceeractiviteit (of de doelactiviteit indien click_actionfunctie wordt gebruikt.) (Toepassing niet op de achtergrond).

    U dient dit op hetzelfde moment te doen als klikken op bijhouden of openen.

    code language-sql
    /** Called when the activity is first created. */
        @Override
        public void onCreate(Bundle savedInstanceState)
        {
            super.onCreate(savedInstanceState);
    
            SharedPreferences settings = getSharedPreferences(NeoTripActivity.APPLICATION_PREF_NAME, Context.MODE_PRIVATE);
    
            // initialize Campaign SDK
            Neolane.getInstance().setIntegrationKey(settings.getString(NeoTripActivity.APPUUID_NAME, NeoTripActivity.DFT_APPUUID));
            Neolane.getInstance().setMarketingHost(settings.getString(NeoTripActivity.SOAPRT_NAME, NeoTripActivity.DFT_SOAPRT));
            Neolane.getInstance().setTrackingHost(settings.getString(NeoTripActivity.TRACKRT_NAME, NeoTripActivity.DFT_TRACKRT));
    ...
    ...
    ...
    
        // Manage opening/receive tracking of message notification
        Intent intent = getIntent();
        Bundle data = intent.getExtras();
        String messageId = null, deliveryId = null;
        if( data != null ) {
        if (data.containsKey("_mId")) messageId = data.get("_mId").toString();
        if (data.containsKey("_dId")) deliveryId = data.get("_dId").toString();
        if ( messageId != null && deliveryId != null) {
            Log.i(TAG, "Notify opening from backgroun click_action");
            NeolaneAsyncRunner nas = new NeolaneAsyncRunner(Neolane.getInstance());
            nas.notifyOpening(messageId, deliveryId, new NeolaneAsyncRunner.RequestListener() {
            public void onNeolaneException(NeolaneException arg0, Object arg1) {
                toastMessage( "error", getString(R.string.open_track_sdk_error) + arg0.getErrorCode());
            }
            public void onIOException(IOException arg0, Object arg1) {
                toastMessage( "error", getString(R.string.open_track_io_error) +  arg0.getLocalizedMessage());
            }
            public void onComplete(String arg0, Object arg1) {
                toastMessage( "error", getString(R.string.open_track_ok));
            }
            });
            nas.notifyReceive(messageId, deliveryId, new NeolaneAsyncRunner.RequestListener() {
            public void onNeolaneException(NeolaneException arg0, Object arg1) {
                toastMessage( "error", getString(R.string.rec_track_sdk_error) + arg0.getErrorCode());
            }
            public void onIOException(IOException arg0, Object arg1) {
                toastMessage( "error", getString(R.string.rec_track_io_error) +  arg0.getLocalizedMessage());
            }
            public void onComplete(String arg0, Object arg1) {
                toastMessage( "error", getString(R.string.rec_track_ok));
            }
            });
        }
        }
    }
    

IOS SDK integreren

  1. Het mobiele apparaat registreren op de Adobe Campaign-server

    Met de registratiefunctie kunt u:

    • Stuur de bericht-id of push-id (deviceToken voor iOS en registrationID voor Android) naar Adobe Campaign.
    • de afstemmingssleutel of de gebruikersnaam herstellen (bijvoorbeeld e-mail- of accountnummer)
    code language-sql
    // Callback called on successful registration to the APNs
     - (void)application:(UIApplication*)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData*)deviceToken
    {
      // Pass the token to Adobe Campaign
      Neolane_SDK *nl = [Neolane_SDK getInstance];
      [nl registerDevice:tokenString:self.userKey:dic];
    }
    
  2. De functie Tekstspatiëring inschakelen

    Met de functie Tekstspatiëring kunt u bijhouden wanneer meldingen zijn geactiveerd (wordt geopend).

    code language-sql
    (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)launchOptions
    fetchCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler
    {
    if( launchOptions ) { // Retrieve notification parameters here ... // Track application opening Neolane_SDK
    *nl = [Neolane_SDK getInstance]; [nl track:launchOptions:NL_TRACK_CLICK]; }
    ...
    completionHandler(UIBackgroundFetchResultNoData);
    }
    
  3. Beheer van stille meldingen

    Met iOS kunt u meldingen op de achtergrond verzenden, een melding of gegevens die rechtstreeks naar een mobiele toepassing worden verzonden zonder deze weer te geven. Met Adobe Campaign kun je ze volgen.

    Volg het onderstaande voorbeeld om je melding op te volgen:

    code language-sql
    // AppDelegate.m
    ...
    ...
    #import "AppDelegate.h"
    #import "Neolane_SDK.h"
    ...
    ...
    // Callback called when the application is already launched (whether the application is running foreground or background)
    - (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)launchOptions fetchCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler
    {
    NSLog(@"IN didReceiveRemoteNotification:fetchCompletionHandler");
    if (launchOptions) NSLog(@"IN launchOptions: %@", [launchOptions description]);
    NSLog(@"Application state: %ld", (long)application.applicationState);
    
    // Silent Notification (specific case, can use NL_TRACK_RECEIVE as the user does not have click/open the notification)
    if ([launchOptions[@"aps"][@"content-available"] intValue] == 1 )
        {
    NSLog(@"Silent Push Notification");
    ...
    ...
    //Call receive tracking
            Neolane_SDK *nl = [Neolane_SDK getInstance];
    [nl track:launchOptions:NL_TRACK_RECEIVE];
    
    completionHandler(UIBackgroundFetchResultNoData); //Do not show notification
    return;
    }
    ...
    ...
            completionHandler(UIBackgroundFetchResultNoData);
    }
    
  4. Registratiestatus configureren

    Het afgevaardigde protocol staat u toe om het resultaat van te krijgen registerDevice vraag en kan worden gebruikt om te weten of een fout tijdens registratie voorkwam.

    De registerDeviceStatus prototype is:

    code language-sql
    - (void) registerDeviceStatus: (ACCRegisterDeviceStatus) status:(NSString *) errorReason;
    
    • Status Hiermee kunt u zien of een registratie is geslaagd of dat een fout is opgetreden.

    • ErrorReason biedt u meer informatie over de fouten die zijn opgetreden. Raadpleeg de onderstaande tabel voor meer informatie over beschikbare fouten en beschrijvingen.

    table 0-row-3 1-row-3 2-row-3 3-row-3 4-row-3 5-row-3 6-row-3 layout-auto
    Status Beschrijving ErrorReason
    ACCRegisterDeviceStatusSuccess Registratie voltooid LEEG
    ACCRegisterDeviceStatusFailedMarketingServerHostnameEmpty De hostnaam van de ACC-marketingserver is leeg of niet ingesteld. LEEG
    ACCRegisterDeviceStatusFailedIntegrationKeyEmpty De integratietoets is leeg of niet ingesteld. LEEG
    ACCRegisterDeviceStatusFailedConnectionIssue Verbindingsprobleem met ACC Meer informatie (in huidige taal van besturingssysteem)
    ACCRegisterDeviceStatusFailedUnknownUID De opgegeven UUID (integratiesleutel) is onbekend. LEEG
    ACCRegisterDeviceStatusFailedUnexpectedError Onverwachte fout die aan server ACC is teruggekeerd. The error message returned to ACC.

    Neolane_SDKDelegate protocol en registerDeviceStatus gedelegeerde definitie is als volgt:

    code language-sql
    //  Neolane_SDK.h
    //  Campaign SDK
    ..
    ..
    // Register Device Status Enum
    typedef NS_ENUM(NSUInteger, ACCRegisterDeviceStatus) {
    ACCRegisterDeviceStatusSuccess,                               // Resistration Succeed
    ACCRegisterDeviceStatusFailureMarketingServerHostnameEmpty,   // The Campaign marketing server hostname is Empty or not set
    ACCRegisterDeviceStatusFailureIntegrationKeyEmpty,            // The integration key is empty or not set
    ACCRegisterDeviceStatusFailureConnectionIssue,                // Connection issue with Campaign, more information in errorReason
    ACCRegisterDeviceStatusFailureUnknownUUID,                    // The provided UUID (integration key) is unknown
    ACCRegisterDeviceStatusFailureUnexpectedError                 // Unexpected error returned by Campaign server, more information in errorReason
    };
    // define the protocol for the registerDeviceStatus delegate
    @protocol Neolane_SDKDelegate <NSObject>
    @optional
    - (void) registerDeviceStatus: (ACCRegisterDeviceStatus) status :(NSString *) errorReason;
    @end
    @interface Neolane_SDK: NSObject {
    }
    ...
    ...
    // registerDeviceStatus delegate
    @property (nonatomic, weak) id <Neolane_SDKDelegate> delegate;
    ...
    ...
    @end
    

    Om registerDeviceStatus afgevaardigde, volg deze stappen:

    1. Implementeer de setDelegate tijdens de SDK-initialisatie.

      code language-sql
      // AppDelegate.m
      ...
      ...
      - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
      {
      ...
      ...
          // Get the stored settings
      
          NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
          NSString *strMktHost = [defaults objectForKey:@"mktHost"];
          NSString *strTckHost = [defaults objectForKey:@"tckHost"];
          NSString *strIntegrationKey = [defaults objectForKey:@"integrationKey"];
          userKey = [defaults objectForKey:@"userKey"];
      
          // Configure Campaign SDK on first launch
          Neolane_SDK *nl = [Neolane_SDK getInstance];
          [nl setMarketingHost:strMktHost];
          [nl setTrackingHost:strTckHost];
          [nl setIntegrationKey:strIntegrationKey];
          [nl setDelegate:self];    // HERE
      ...
      ...
      }
      
    2. Voeg het protocol in toe @interface van uw klas.

      code language-sql
      //  AppDelegate.h
      
      #import <UIKit/UIKit.h>
      #import <CoreLocation/CoreLocation.h>
      #import "Neolane_SDK.h"
      
      @class LandingPageViewController;
      
      @interface AppDelegate : UIResponder <UIApplicationDelegate, CLLocationManagerDelegate, Neolane_SDKDelegate> {
          CLLocationManager *locationManager;
          NSString *userKey;
          NSString *mktServerUrl;
          NSString *tckServerUrl;
          NSString *homeURL;
          NSString *strLandingPageUrl;
          NSTimer *timer;
      }
      
    3. Voer de afgevaardigde in uit AppDelegate.

      code language-sql
      //  AppDelegate.m
      
      #import "AppDelegate.h"
      #import "Neolane_SDK.h"
      #import "LandingPageViewController.h"
      #import "RootViewController.h"
      ...
      ...
      - (void) registerDeviceStatus: (ACCRegisterDeviceStatus) status :(NSString *) errorReason
      {
          NSLog(@"registerStatus: %lu",status);
      
          if ( errorReason != nil )
              NSLog(@"errorReason: %@",errorReason);
      
          if( status == ACCRegisterDeviceStatusSuccess )
          {
              // Registration successful
              ...
              ...
          }
          else { // An error occurred
              NSString *message;
              switch ( status ){
                  case ACCRegisterDeviceStatusFailureUnknownUUID:
                      message = @"Unkown IntegrationKey (UUID)";
                      break;
                  case ACCRegisterDeviceStatusFailureMarketingServerHostnameEmpty:
                      message = @"Marketing URL not set or Empty";
                      break;
                  case ACCRegisterDeviceStatusFailureIntegrationKeyEmpty:
                      message = @"Integration Key not set or empty";
                      break;
                  case ACCRegisterDeviceStatusFailureConnectionIssue:
                      message = [NSString stringWithFormat:@"%@ %@",@"Connection issue:",errorReason];
                      break;
                  case ACCRegisterDeviceStatusFailureUnexpectedError:
                  default:
                      message = [NSString stringWithFormat:@"%@ %@",@"Unexpected Error",errorReason];
                      break;
              }
          ...
          ...
          }
      }
      @end
      

Variabelen variables

Met de variabelen kunt u het gedrag van mobiele toepassingen definiëren nadat u een melding hebt ontvangen. Deze variabelen moeten worden gedefinieerd in de code van de mobiele toepassing en in de Adobe Campaign-clientconsole, in de Variables in de toegewezen mobiele toepassing.

Hieronder ziet u een voorbeeld van een code waarmee een mobiele toepassing toegevoegde variabelen in een melding kan verzamelen. In ons voorbeeld gebruiken we de variabele "VAR".

  • In Android:

    code language-sql
    public void onReceive(Context context, Intent intent) {
         ...
        String event = intent.getStringExtra("VAR");
         ...
    }
    
  • In iOS:

    code language-sql
    - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
    {
        ....
        if( launchOptions )
        {
            // When application is not already launched, the notification data if any are stored in the key 'UIApplicationLaunchOptionsRemoteNotificationKey'
            NSDictionary *localLaunchOptions = [launchOptions objectForKey:@"UIApplicationLaunchOptionsRemoteNotificationKey"];
            if( localLaunchOptions )
            {
             ...
             [localLaunchOptions objectForKey:@"VAR"];
            ...
            }
       }
    }
    
    // Callback called when the application is already launched (whether the application is running foreground or background)
    - (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)launchOptions
    {
        if( launchOptions )
        {
         ...
            [launchOptions objectForKey:@"VAR"];
        }
    }
    
CAUTION
Adobe raadt u aan korte variabelenamen te kiezen, omdat de berichtgrootte voor iOS en Android beperkt is tot 4 kB.

Meldingsservice-extensie notification-service-extension

Voor iOS

De media moeten worden gedownload op het niveau van de berichtdienst uitbreiding.

#import "NotificationService.h"

@interface NotificationService ()

@property (nonatomic, strong) void (^contentHandler)(UNNotificationContent *contentToDeliver);
@property (nonatomic, strong) UNMutableNotificationContent *bestAttemptContent;

@end

@implementation NotificationService

- (void)didReceiveNotificationRequest:(UNNotificationRequest *)request withContentHandler:(void (^)(UNNotificationContent * _Nonnull))contentHandler {
    NSDictionary *userInfo = nil;
    NSString *url = nil;

    self.contentHandler = contentHandler;
    self.bestAttemptContent = [request.content mutableCopy];

    userInfo = request.content.userInfo;
    if ( userInfo != nil )
    {
        url = userInfo[@"mediaUrl"];  // Get the url of the media to download (Adobe Campaign additional variable)
    }
    ...
    // Perform the download to local storage

Extensie meldingsinhoud notification-content-extension

Voor iOS

Op dit niveau moet u:

  • Wijs de extensie van de inhoud toe aan de categorie die door Adobe Campaign is verzonden:

    Als u een afbeelding wilt weergeven in uw mobiele toepassing, kunt u de categoriewaarde instellen op "image" in Adobe Campaign en in uw mobiele toepassing, maakt u een meldingsextensie met de optie UNNotificationExtensionCategory parameter ingesteld op "image". Wanneer het pushbericht op het apparaat wordt ontvangen, wordt de extensie aangeroepen op basis van de gedefinieerde categoriewaarde.

  • De lay-out voor uw melding definiëren

    U moet een lay-out definiëren met de relevante widgets. Voor een afbeelding krijgt de widget de naam UIImageView.

  • Uw media weergeven

    U moet code toevoegen om de mediagegevens aan de widget te kunnen doorgeven. Hier volgt een voorbeeld van code voor een afbeelding:

    code language-sql
    #import "NotificationViewController.h"
    #import <UserNotifications/UserNotifications.h>
    #import <UserNotificationsUI/UserNotificationsUI.h>
    
    @interface NotificationViewController () <UNNotificationContentExtension>
    
    @property (strong, nonatomic) IBOutlet UIImageView *imageView;
    @property (strong, nonatomic) IBOutlet UILabel *notifContent;
    @property (strong, nonatomic) IBOutlet UILabel *label;
    
    @end
    
    @implementation NotificationViewController
    
    - (void)viewDidLoad {
        [super viewDidLoad];
        // Do any required interface initialization here.
    }
    
    - (void)didReceiveNotification:(UNNotification *)notification {
        self.label.text = notification.request.content.title;
        self.notifContent.text = notification.request.content.body;
        UNNotificationAttachment *attachment = [notification.request.content.attachments objectAtIndex:0];
        if ([attachment.URL startAccessingSecurityScopedResource])
        {
          NSData * imageData = [[NSData alloc] initWithContentsOfURL:attachment.URL];
          self.imageView.image =[UIImage imageWithData: imageData];
          [attachment.URL stopAccessingSecurityScopedResource];
        }
    }
    @end
    
recommendation-more-help
35662671-8e3d-4f04-a092-029a056c566b