首页 > 解决方案 > 自 iOS 13 以来,推送通知不再适用于 Xamarin 应用程序

问题描述

由于 iOS 13 推送通知的公开发布似乎不再适用于我的 Xamarin.Forms iOS 项目。我目前使用 Azure Notification Hub 发送测试通知,以前,我的 iPhone 可以毫无问题地收到通知。自 iOS13 以来,这不再发生。

我不使用 OneSignal,但他们确实发布了一篇关于推送通知所做更改的文章:https ://onesignal.com/blog/ios-13-introduces-4-break-changes-to-notifications/

这个问题还存在吗?或者除了 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}");
            }
        });
    });
}

上面的代码一直有效,但在调试过程中我注意到它不再进入Hub.UnregisterAllAsync(),我相信它会导致一些错误?(虽然无法理解)

=================================================================
    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  . ..
. ... .. ..<

虽然我已经找到了这些 - 但我不确定这些与我当前的问题有多大关系。 https://github.com/Azure/azure-notificationhubs-dotnet/issues/88 https://github.com/Azure/azure-notificationhubs-dotnet/issues/96

标签: c#iosxamarin.formsazure-notificationhub

解决方案


他们最近更改了他们的令牌,您需要按照此链接进行细微更改 https://dev.to/codeprototype/correctly-capture-ios-13-device-token-in-xamarin-1968


推荐阅读