Xamarin iOS SDK

How to integrate Pushwoosh SDK into your Xamarin iOS project

Module Source Geozones Module Source Download Sample

iOS Simulator can neither subscribe to nor receive push notifications.

To integrate Pushwoosh with your Xamarin iOS application:

1. Add Pushwoosh.Xamarin.iOS nuget package to your solution.

2. In your project, open AppDelegate.cs and connect Pushwoosh by adding the using Pushwoosh line.

3. In your Info.plist add Pushwoosh_APPID key with your Pushwoosh Application ID string value.

4. Organize the following imports:

  • using Pushwoosh;

  • using UserNotifications;

5. Add the methods below to AppDelegate class:

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. Add the code below to public override bool FinishedLaunching(UIApplication app, NSDictionary launchOptions) method:

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. Add the following class to the 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);
           }
       }

8. To use Geozones, add Pushwoosh.Geozones.Xamarin.iOS nuget package to your project. Add the following line to the same method:

PWGeozonesManager.SharedManager.StartLocationTracking(); 

Share your feedback with us

Your feedback helps us create a better experience, so we would love to hear from you if you have any issues during the SDK integration process. If you face any difficulties, please do not hesitate to share your thoughts with us via this form.

Last updated

#1600: moved in-app statistics to in-apps, added a link to statistics

Change request updated