Zum Inhalt springen

Xamarin iOS SDK

Modulquelle
Beispiel herunterladen

Um Pushwoosh in Ihre Xamarin iOS-Anwendung zu integrieren:

1. Fügen Sie das NuGet-Paket Pushwoosh.Xamarin.iOS zu Ihrer Solution hinzu.

2. Öffnen Sie in Ihrem Projekt AppDelegate.cs und verbinden Sie Pushwoosh, indem Sie die Zeile using Pushwoosh hinzufügen.

3. Fügen Sie in Ihrer Info.plist den Schlüssel Pushwoosh_APPID mit dem String-Wert Ihrer Pushwoosh Application ID hinzu.

4. Organisieren Sie die folgenden Importe:

  • using Pushwoosh;
  • using UserNotifications;

5. Fügen Sie die folgenden Methoden zur AppDelegate-Klasse hinzu:

public override void RegisteredForRemoteNotifications(UIApplication application, NSData deviceToken)
{
PushNotificationManager.PushManager.HandlePushRegistration (deviceToken);
}
public override void FailedToRegisterForRemoteNotifications(UIApplication application, NSError error)
{
PushNotificationManager.PushManager.HandlePushRegistrationFailure (error);
}
public override void ReceivedRemoteNotification(UIApplication application, NSDictionary userInfo)
{
PushNotificationManager.PushManager.HandlePushReceived (userInfo);
}

6. Fügen Sie den folgenden Code zur Methode public override bool FinishedLaunching(UIApplication app, NSDictionary launchOptions) hinzu:

PushNotificationManager pushmanager = PushNotificationManager.PushManager;
pushmanager.Delegate = new PushDelegate();
UNUserNotificationCenter.Current.Delegate = pushmanager.notificationCenterDelegate;
if (options != null) {
if (options.ContainsKey (UIApplication.LaunchOptionsRemoteNotificationKey)) {
pushmanager.HandlePushReceived(options);
}
}
pushmanager.RegisterForPushNotifications();

7. Fügen Sie die folgende Klasse zum AppDelegate hinzu:

public class PushDelegate : PushNotificationDelegate
{
public override void OnPushAccepted(PushNotificationManager pushManager, NSDictionary pushNotification)
{
Console.WriteLine(“Push accepted: ” + pushNotification);
}
public override void OnPushReceived(PushNotificationManager pushManager, NSDictionary pushNotification, bool onStart)
{
Console.WriteLine(“Push received: ” + pushNotification);
}
public override void OnDidRegisterForRemoteNotificationsWithDeviceToken(NSString token)
{
Console.WriteLine(“Registered for push notifications: ” + token);
}
public override void OnDidFailToRegisterForRemoteNotificationsWithError(NSError error)
{
Console.WriteLine(“Error: ” + error);
}
}

Teilen Sie Ihr Feedback mit uns

Anchor link to

Ihr Feedback hilft uns, eine bessere Erfahrung zu schaffen. Daher würden wir uns freuen, von Ihnen zu hören, wenn Sie während des SDK-Integrationsprozesses auf Probleme stoßen. Wenn Sie auf Schwierigkeiten stoßen, zögern Sie bitte nicht, uns Ihre Gedanken über dieses Formular mitzuteilen.

Was this page useful?