Hello,
As in topic, "Opens" counter on push notification isn't working for iOS.
"Sends" counter work's as it should for both platforms but "Opens" works only for Android.
It's same for Production and Stage environment.
Here's my code for iOS:
private void RegisterPushNotification()
{
// Register your app for remote notifications.
if (UIDevice.CurrentDevice.CheckSystemVersion(10, 0))
{
// iOS 10 or later
var authOptions = UNAuthorizationOptions.Alert | UNAuthorizationOptions.Badge | UNAuthorizationOptions.Sound;
UNUserNotificationCenter.Current.RequestAuthorization(authOptions, (granted, error) =>
{
_pushNotificationService.UpdatePushNotificationsPermission();
});
// For iOS 10 display notification (sent via APNS)
UNUserNotificationCenter.Current.Delegate = this;
// For iOS 10 data message (sent via FCM)
Messaging.SharedInstance.Delegate = this;
}
else
{
// iOS 9 or before
var allNotificationTypes = UIUserNotificationType.Alert | UIUserNotificationType.Badge | UIUserNotificationType.Sound;
var settings = UIUserNotificationSettings.GetSettingsForTypes(allNotificationTypes, null);
UIApplication.SharedApplication.RegisterUserNotificationSettings(settings);
_pushNotificationService.UpdatePushNotificationsPermission();
}
UIApplication.SharedApplication.RegisterForRemoteNotifications();
Messaging.SharedInstance.ShouldEstablishDirectChannel = true;
var token = InstanceId.SharedInstance.Token;
}
public override void DidReceiveRemoteNotification(UIApplication application, NSDictionary userInfo, Action<UIBackgroundFetchResult> completionHandler)
{
var aps = userInfo.ObjectForKey(new NSString("aps")) as NSDictionary;
if (aps.ContainsKey(new NSString("alert")))
{
var data = aps[new NSString("alert")];
_pushNotificationService.RaiseNotificationReceived(new PushNotificationData
{
Title = data.ValueForKey(new NSString("title")).ToString(),
Message = data.ValueForKey(new NSString("body")).ToString(),
Url = userInfo.ValueForKey(new NSString(_settingsProvider.NotificationUrlKey))?.ToString()
});
}
}
#pragma warning disable XI0002 // Notifies you from using newer Apple APIs when targeting an older OS version
// To receive notifications in foreground on iOS 10 devices.
[Export("userNotificationCenter:willPresentNotification:withCompletionHandler:")]
public void WillPresentNotification(UNUserNotificationCenter center, UNNotification notification, Action<UNNotificationPresentationOptions> completionHandler)
{
completionHandler(UNNotificationPresentationOptions.Alert | UNNotificationPresentationOptions.Badge | UNNotificationPresentationOptions.Sound);
}
//Workaround for iOS 10, which doesn't call DidReceiveRemoteNotification method
[Export("userNotificationCenter:didReceiveNotificationResponse:withCompletionHandler:")]
public void DidReceiveNotificationResponse(UNUserNotificationCenter center, UNNotificationResponse response, Action completionHandler)
{
HandleNotification(response.Notification.Request.Content);
}
#pragma warning restore XI0002 // Notifies you from using newer Apple APIs when targeting an older OS version
private void HandleNotification(UNNotificationContent content)
{
_pushNotificationService.RaiseNotificationReceived(new PushNotificationData
{
Title = content.Title,
Message = content.Body,
Url = content.UserInfo.ValueForKey(new NSString(_settingsProvider.NotificationUrlKey))?.ToString()
});
}