【发布时间】:2020-02-04 18:39:51
【问题描述】:
由于 iOS 13 推送通知的公开发布似乎不再适用于我的 Xamarin.Forms iOS 项目。我目前使用 Azure Notification Hub 发送测试通知,以前,我的 iPhone 可以毫无问题地收到通知。从 iOS13 开始,这不再发生。
我不使用 OneSignal,但他们确实发布了一篇关于推送通知所做更改的文章:https://onesignal.com/blog/ios-13-introduces-4-breaking-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
【问题讨论】:
-
您是否检查过您是否收到令牌?
-
deviceToken已填充,它甚至没有进入检查error是否已填充的方法。 -
我有一种感觉 deviceToken 没有生成,因为这是最近在 iOS 13 中实际更改的内容stackoverflow.com/a/58028222/7462031
-
我在这个问题上取得了一些进展 - 我注意到我引用了一年多前没有更新的
Xamarin.Azure.NotificationHubs.iOS-updated(v. 1.2.5.3) (nuget.org/packages/Xamarin.Azure.NotificationHubs.iOS-updated) 现在我我引用Xamarin.Azure.NotificationHubs.iOS(v 2.0.4 - nuget.org/packages/Xamarin.Azure.NotificationHubs.iOS/2.0.4) 尽管我犯了小错误,但我实际上可以再次注册并接收通知。我目前只能假设,这是我问题的根源。 -
@Jasper Xamarin 做了一些 changes to the Hub methods:
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.
标签: c# ios xamarin.forms azure-notificationhub