Xamarin Library Integration

How to integrate Pushwoosh Xamarin library into your project

1. Change target framework of your Android project to Android 8.0 or higher. 2. Add the Pushwoosh nuget package to both Android and iOS projects. 3. Make the following changes in the AppDelegate.cs of your iOS project: 3.1. In the beginning of the FinishedLaunching method, put the following line:

Pushwoosh.iOS.PushManager.Init();

3.2. Add these methods to the AppDelegate:

public override void RegisteredForRemoteNotifications(UIApplication application, NSData deviceToken)
{
    Pushwoosh.iOS.PushManager.Instance.RegisteredForRemoteNotifications(deviceToken);
}

public override void FailedToRegisterForRemoteNotifications(UIApplication application, NSError error)
{
    Pushwoosh.iOS.PushManager.Instance.FailedToRegisterForRemoteNotifications(error);
}

public override void ReceivedRemoteNotification(UIApplication application, NSDictionary userInfo)
{
    Pushwoosh.iOS.PushManager.Instance.ReceivedRemoteNotification(userInfo);
}

4. In the Info.plist, change the Pushwoosh_APPID value to your Pushwoosh Application Code. You can find it in your Control Panel. 5. Configure your project in Firebase Console. 6.1. Add google-services.json file to your Android project.

google-services.json

You should've gotten the google-services.json file while creating the app in Firebase console. If you haven't, please consult this thread (section Get a config file for your Android app).

6.2. In Visual Studio, right-click the google-services.json and choose GoogleServicesJson option from the Build Action menu.

7. In the MainActivity.cs of your Android project, before defining the namespace, add these lines:

[assembly:MetaData("com.pushwoosh.appid", Value = "YOUR_PUSHWOOSH_APP_CODE")]
[assembly:MetaData("com.pushwoosh.senderid", Value = "@string/fcm_sender_id")]

Also, in the beginning of onCreate method of the MainActivity class, initialize the PushManager with Pushwoosh.Droid.PushManager.Init(); line.

8. In your Android project, find the Resources/values/strings.xml file or create it. Add your Sender ID string there:

strings.xml
<string name="fcm_sender_id">YOUR_SENDER_ID</string>

9. In the cross-platform part of App.xaml.cs, add the registration to onStart method:

PushManager.Instance.Register();

Geozones Push Notifications

1. To enable location tracking in your application: 1.1. Install the Pushwoosh.Geozones nuget package into your projects.

1.2. For iOS add the following keys to your Info.plist:

  • NSLocationWhenInUseUsageDescription(required) for app to track Geozones only while running in the foreground.

  • NSLocationAlwaysAndWhenInUseUsageDescription - (required) for app to track Geozones in both conditions, and to show a permission request dialog pop-up.

  • NSLocationAlwaysUsageDescription(optional) for app to track Geozones at all times; should be used if your app targets iOS 10 and earlier versions.

1.3. Add the following line to your AppDelegate.cs (after Pushwoosh.iOS.PushManager.Init();):

Pushwoosh.Geozones.iOS.GeozonesManager.Init(); 

1.4. Add the following line to your MainActivity.cs (after Pushwoosh.Droid.PushManager.Init();):

Pushwoosh.Geozones.Droid.GeozonesManager.Init();

2. To start location tracking, simply call:

Pushwoosh.Geozones.GeozonesManager.Instance.StartLocationTracking();

Message Inbox

1. Install the Pushwoosh.Inbox nuget package into your projects. 2.1. For iOS, add the following line to your AppDelegate.cs (after Pushwoosh.iOS.PushManager.Init();):

Pushwoosh.Inbox.iOS.InboxManager.Init();

2.2. For Android, add the following line to your MainActivity.cs (after Pushwoosh.Droid.PushManager.Init();):

Pushwoosh.Inbox.Droid.InboxManager.Init();

3. To show the Inbox UI in your app:

3.1. Create the PushwooshInboxStyle instance:

PushwooshInboxStyle inboxStyle = new PushwooshInboxStyle
{
    AccentColor = Color.Violet,
    BackgroundColor = Color.White,
    BarAccentColor = Color.Blue,
    BarBackgroundColor = Color.WhiteSmoke,
    BarTextColor = Color.DarkGray,
    DateColor = Color.Violet,
    DefaultTextColor = Color.DarkBlue,
    DescriptionColor = Color.DarkBlue,
    SelectionColor = Color.Crimson,
    SeparatorColor = Color.Crimson,
    TitleColor = Color.DarkKhaki,

    DefaultImageName = "inbox_message",
    ListEmptyImageName = "inbox_empty",
    ListErrorImageName = "inbox_error",
    UnreadImageName = "inbox_unread",

    BarTitle = "My custom title",
    ListEmptyMessage = "There are no inbox messages yet",
    ListErrorMessage = "Some error happened",

    DateFormat = "dd.MM.yyyy"
};

3.2. Then call:

InboxManager.Instance.PresentInboxUI(inboxStyle);

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