SDK Xamarin iOS
Source du module
Télécharger l’exemple
Pour intégrer Pushwoosh à votre application Xamarin iOS :
1. Ajoutez le paquet nuget Pushwoosh.Xamarin.iOS à votre solution.
2. Dans votre projet, ouvrez AppDelegate.cs et connectez Pushwoosh en ajoutant la ligne using Pushwoosh
.
3. Dans votre Info.plist, ajoutez la clé Pushwoosh_APPID
avec votre ID d’application Pushwoosh comme valeur de chaîne.
4. Organisez les importations suivantes :
- using Pushwoosh;
- using UserNotifications;
5. Ajoutez les méthodes ci-dessous à la classe 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. Ajoutez le code ci-dessous à la méthode 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. Ajoutez la classe suivante à l’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); } }
Partagez vos commentaires avec nous
Anchor link toVos commentaires nous aident à créer une meilleure expérience, nous serions donc ravis de connaître votre avis si vous rencontrez des problèmes lors du processus d’intégration du SDK. Si vous rencontrez des difficultés, n’hésitez pas à nous faire part de vos réflexions via ce formulaire.