4

Since the public release of iOS 13 push notifications appear to no longer work for my Xamarin.Forms iOS project. I currently use Azure Notification Hub to send test notifications and previously, my iPhones would get notifications with no problem. Since iOS13 this is no longer happening.

I don't use OneSignal but they did post an article about the changes that were made for Push Notifications: https://onesignal.com/blog/ios-13-introduces-4-breaking-changes-to-notifications/

Is this problem still present? Or has anyone got any sources to confirm this issue other than SignalOne?

public override void RegisteredForRemoteNotifications(UIApplication application, NSData deviceToken) {
    if (Hub == null) {
        Hub = new SBNotificationHub(ApiConstants.ListenConnectionString, ApiConstants.NotificationHubName);
    }

    // Following from the comments with FreakyAli, I have added these 3 lines
    Byte[] result = new byte[deviceToken.Length];
    Marshal.Copy(deviceToken.Bytes, result, 0, (Int32)deviceToken.Length);
    String token = BitConverter.ToString(result).Replace("-", "");

    // Update registration with Azure Notification Hub
    Hub.UnregisterAllAsync(token, (error) => {
        if (error != null) {
            Debug.WriteLine($"Unable to call unregister {error}");
        }

        NSSet tags = null;

        Hub.RegisterNativeAsync(deviceToken, tags, (errorCallback) => {
            if (errorCallback != null) {
                Debug.WriteLine($"RegisterNativeAsync error: {errorCallback}");
            }
        });
    });
}

The code above worked all the time but during debugging I have noticed it no longer steps into Hub.UnregisterAllAsync() and I believe it is causing some error? (Can't make any sense of it though)

=================================================================
    Basic Fault Address Reporting
=================================================================
Memory around native instruction pointer (0x1bffaaf44):
0x1bffaaf34  c0 03 
5f d6 1f 
20 03 d5 
1f 20 
03 d5 01 ec 
7c 92  
.._.. 
...
 ..
..|
.
0x1bffaaf44  20 00 c0 3d c3 f9 ff 10 
62 04 c1 3c 02 0c 40 92 
  ..=.
..
.b.
.<.
.@.

0x1bffaaf54  
63 00 02 
cb 61 00 
c0 3d 00 1c a1 4e 
05 00 
00 
14 
 c.
..
a.
.=.
.
.
N....
0x1bffaaf64  1f 20 03 d5 
1f 20 03 d5 1f 20 03 d5 20 0c 
c1 3c  . ..
. ... .. ..<

I have found these though - but I'm unsure how related these are to my current problem. https://github.com/Azure/azure-notificationhubs-dotnet/issues/88 https://github.com/Azure/azure-notificationhubs-dotnet/issues/96

MattVon
  • 481
  • 1
  • 8
  • 25
  • Did you check whether or not you are receiving the token? – FreakyAli Oct 07 '19 at 13:04
  • `deviceToken` is populated and it does not even step into the method to check whether or not `error` was populated. – MattVon Oct 07 '19 at 13:10
  • I have a feeling deviceToken is not getting generate as that was the thing that actually recently got changed in iOS 13 https://stackoverflow.com/a/58028222/7462031 – FreakyAli Oct 07 '19 at 13:16
  • Using the code from that example, I am now passing the token value in `Hub.UnregisterAllAsync()` but there has been no change to my problem. Would this be an expected token format? `83E24287B4BA49AC26AB6B6095561DE574EBA55989384EDD01725A2D72A813B0` – MattVon Oct 07 '19 at 13:25
  • Yeah it looks like it, Is it working though? – FreakyAli Oct 07 '19 at 13:27
  • Nope, no change in the slightest, during debugging it hits `Hub.UnregisterAllAsync(token, (error) => {` line, but if you step to the next line it exits the method with no noticeable errors. – MattVon Oct 07 '19 at 13:29
  • Umm can add a try catch see if you can catch anything? – FreakyAli Oct 07 '19 at 13:33
  • Let us [continue this discussion in chat](https://chat.stackoverflow.com/rooms/200508/discussion-between-mattvon-and-freakyali). – MattVon Oct 07 '19 at 13:38
  • 1
    I've made some progress on this issue - I noticed I was referencing `Xamarin.Azure.NotificationHubs.iOS-updated` (v. 1.2.5.3) which has not been updated for over a year ago (https://www.nuget.org/packages/Xamarin.Azure.NotificationHubs.iOS-updated/) Now I am referencing `Xamarin.Azure.NotificationHubs.iOS` (v 2.0.4 - https://www.nuget.org/packages/Xamarin.Azure.NotificationHubs.iOS/2.0.4) and despite my minor error, I can actually register and receive notifications again. I can only assume currently, this is the root source of my problem. – MattVon Oct 07 '19 at 14:36
  • The UnregisterAllAsync method is giving me an error: "No overload for method UnregisterAllAsync takes two arguments". It has no second callback argument. The non-async method does work. I'm using the same version of Xamarin.Azure.NotificationHubs.iOS (2.0.4). I wonder what the difference is? – Jasper Nov 18 '19 at 13:06
  • 1
    @Jasper Xamarin made some [changes to the Hub methods](https://forums.xamarin.com/discussion/comment/397095/#Comment_397095): `on iOS there are some changes to the async method signatures for methods such as UnregisterAllAsync, RegisterNativeAsync, and RegisterTemplateAsync. These methods used to have a second parameter that took a callback. They no longer do... It is easier to use the non-async versions of these methods than to rewrite to be properly Async/Await. The non-async versions have the same signature so the only code change would be to remove the Async suffix from the method calls.` – Phil Seeman Dec 09 '19 at 04:03

1 Answers1

1

They recently changed their token , you need to make minor changes follow this link https://dev.to/codeprototype/correctly-capture-ios-13-device-token-in-xamarin-1968

Shubham Tyagi
  • 798
  • 6
  • 21