Setup
Installation
- Add the
Com.CleverPush
NuGet PackageInstall-Package Com.CleverPush -Version 1.3.1
Setup iOS
Enable the required capabilities
Go to your iOS project and open the
Entitlements.plist
file. At the bottom you can change to the second tab to see the settings UI.Enable "Push Notifications"
Open the
Info.plist
file. At the bottom you can change to the second tab to see the settings UI.Set the deployment target to at least iOS 9 or higher. We also recommend setting the Provisioning to Automatic Provisioning.
Add Notification Service Extension
This is required for correctly tracking notification deliveries and for displaying big images or videos in notifications.
- Right click on the project in the navigator on the left, then select Add ->
Add New Project
. - Select
iOS
->Extension
->Notification Service Extension
. - Go to your new Service Extension project and open the
Entitlements.plist
file. At the bottom you can change to the second tab to see the settings UI. - Enable "Push Notifications"
- Open the
Info.plist
file. At the bottom you can change to the second tab to see the settings UI. - Set the deployment target to at least iOS 10 or higher. We also recommend setting the Provisioning to Automatic Provisioning.
- Open the new Project's Options.
- Under
iOS Build
setLinker behaviour
toLink all
(for Debug and Release configuration). - Right click on new Project’s References then select Edit References.
- Add the
CleverPush
NuGet. - Replace the
NotificationService.cs
file with the following contents:
```csharp
using System;
using Foundation;
using UIKit;
using UserNotifications;
using Com.CleverPush;
using Com.CleverPush.Abstractions;
namespace CleverPushNotificationServiceExtension
{
[Register("NotificationService")]
public class NotificationService : UNNotificationServiceExtension
{
Action<UNNotificationContent> ContentHandler { get; set; }
UNMutableNotificationContent BestAttemptContent { get; set; }
UNNotificationRequest ReceivedRequest { get; set; }
protected NotificationService(IntPtr handle) : base(handle)
{
}
public override void DidReceiveNotificationRequest(UNNotificationRequest request, Action<UNNotificationContent> contentHandler)
{
ReceivedRequest = request;
ContentHandler = contentHandler;
BestAttemptContent = (UNMutableNotificationContent)request.Content.MutableCopy();
(CleverPush.Current as CleverPushImplementation).DidReceiveNotificationExtensionRequest(request, BestAttemptContent);
ContentHandler(BestAttemptContent);
}
public override void TimeWillExpire()
{
(CleverPush.Current as CleverPushImplementation).ServiceExtensionTimeWillExpireRequest(ReceivedRequest, BestAttemptContent);
ContentHandler(BestAttemptContent);
}
}
}
```
Create your iOS push certificate
- Open Keychain Access on your Mac. (Application > Utilities > Keychain Access).
- Select Keychain Access > Certificate Assistant > Request a Certificate From a Certificate Authority...
- Select the "Save to disk" option and enter any information in the required fields
- Go to the Apple developer portal, select your app and press "Edit"
- Enable "Push notifications" and press "Done"
- Go to the Create new certificate page, select "Apple Push Notification service SSL" and press "Continue"
- Select your Application Bundle ID and press "Continue"
- Press "Choose File...", select the previously generated "certSigningRequest" file and then press "Generate"
- Press "Download" and save your certificate
- Click on the downloaded .cer file, Keychain Access should open
- Select Login > My Certificates then right click on your key and click "Export (Apple Production iOS Push Services: com.your.bundle)..."
- Give the file a unique name and press save, be sure to leave the password field blank!
- Upload your certificate in the CleverPush channel settings
Add AppGroup (optional but recommended)
This is required for getting the received notifications via the
GetNotifications
method and also for automatic Badge Counting (i.e. when usingSetIncrementBadge(true)
).- Select your iOS target in Visual Studio
- Go to
Capabilities
and activateApp Groups
- Create a new App Group with the following Scheme:
group.YOUR.BUNDLE.ID.cleverpush
(replaceYOUR.BUNDLE.ID
with your application's bundle identifier). - Enable the created App Group by checking the checkbox next to it
- Select the
CleverPushNotificationServiceExtension
target and also enable the created App Group underCapabilities
Setup Android
Add these additional NuGet packages:
GoogleGson Xamarin.Firebase.Messaging Xamarin.GooglePlayServices.Base Xamarin.Google.Dagger
Set the minimum Android Version to API level 27
Add the google-services.json file which can be downloded from the Firebase console like described here: https://docs.microsoft.com/en-us/xamarin/android/data-cloud/google-messaging/remote-notifications-with-fcm?tabs=macos#add-googleplayservices-json
Setup Huawei on Android
Please see these following docs from Huawei to setup the HMS libs.
Setup HMS: https://developer.huawei.com/consumer/en/doc/HMS-Plugin-Guides-V1/libbinding-0000001050138443-V1
Integrate HMS Bindings: https://developer.huawei.com/consumer/en/doc/HMS-Plugin-Guides-V1/integratelibs-0000001050136494-V1
Integrate HMS SDK: https://developer.huawei.com/consumer/en/doc/HMS-Plugin-Guides-V1/integrating-sdk-0000001050138445-V1
Badge icon (Android)
You can place your custom badge icon with the correct sizes in this Resources folders, then the SDK will automatically use it:
/drawable-[SIZE]/cleverpush_notification_icon.png
Custom sounds
Android + iOS both support wav
audio files with a maximum length of 30 seconds.
- Add the sound file(s) to Resources (Resources root for iOS,
res/raw/
for Android) in the project. - When sending a notification you can enter the filename (with extension) in the field "Sound" in the advanced settings.
- If you send notifications via the API you can use the parameter "soundFilename".