Xamarin iOS SDK
Исходный код модуля
Скачать пример
Чтобы интегрировать Pushwoosh в ваше приложение Xamarin iOS:
1. Добавьте nuget-пакет Pushwoosh.Xamarin.iOS в ваше решение.
2. В вашем проекте откройте AppDelegate.cs и подключите Pushwoosh, добавив строку using Pushwoosh
.
3. В файле Info.plist добавьте ключ Pushwoosh_APPID
со строковым значением вашего Pushwoosh Application ID.
4. Организуйте следующие импорты:
- using Pushwoosh;
- using UserNotifications;
5. Добавьте приведенные ниже методы в класс AppDelegate:
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. Добавьте приведенный ниже код в метод public override bool FinishedLaunching(UIApplication app, NSDictionary launchOptions)
:
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. Добавьте следующий класс в AppDelegate:
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); } }
Поделитесь с нами своим мнением
Anchor link toВаши отзывы помогают нам работать лучше, поэтому мы будем рады, если вы сообщите о любых проблемах, возникших в процессе интеграции SDK. Если вы столкнетесь с какими-либо трудностями, пожалуйста, не стесняйтесь поделиться своими мыслями с нами через эту форму.