【发布时间】:2021-08-03 07:25:26
【问题描述】:
我在 Xamarin Forms 项目中让推送通知在 iOS 中工作完全没有运气。
在 AppDelegate.cs 中,我在 FinishedLaunching 覆盖中调用以下内容:
MSNotificationHub.Start("Endpoint=sb://[redacted].servicebus.windows.net/;SharedAccessKeyName=DefaultListenSharedAccessSignature;SharedAccessKey=[redacted]",
"[redacted]");
用户在应用程序生命周期中进一步登录后,我还使用他们的用户标签注册用户,如下所示:
public async Task UpdateTags(string token)
{
await Task.Run(() =>
{
try
{
// No point registering tags until the user has signed in and we have a device token
if (CurrentAccount == null)
{
Console.WriteLine($"UpdateTags cancelled: Account is null");
return;
}
var tag = $"user:{CurrentAccount.UserName}";
Console.WriteLine($"Registering tag: {tag}");
MSNotificationHub.AddTag(tag);
}
catch (Exception e)
{
Console.WriteLine($"Error registering tag: {e.ToString()}");
}
});
}
我已在通知中心正确配置 Apple (APNS) 设置,使用令牌身份验证模式(多次验证四个字段)。证书(签名身份)是“iOS 分发”,标识符包与我在配置中的完全匹配(不使用通配符),密钥启用了 Apple 推送通知服务(APN),配置文件具有平台:iOS 和类型:应用商店。
我将应用程序推送到 TestFlight,因为我无法访问物理 Mac(我们使用 Cloud mac 进行开发)。当我从安装了应用程序的个人 iPhone 查看设备日志时,我在运行它时看到以下内容:
<Notice>: Registered for push notifications with token: [redacted]
<Notice>: Registering tag: user:[redacted]
日志中根本没有“错误注册标签”或“更新标签被取消”的实例,这告诉我方法调用成功无一例外。但是,当我尝试向空白/空标签或我的测试用户的特定标签发送测试通知时,不会收到任何通知,并且消息仅显示“消息已成功发送,但没有匹配的目标”。
另外,当我使用 var registrations = await hub.GetAllRegistrationsAsync(0); 提取所有注册时,我只看到我在 Android 方面的成功测试中的 FCM(Firebase/Android)注册。
我完全不知所措并且碰壁了,因为没有抛出异常,而且似乎没有办法解决幕后发生的事情。
这也是我的第二次尝试 - 我使用了更复杂的 SBNotificationHub 实现并且得到了相同的结果 - 没有例外,一切看起来都很好。
【问题讨论】:
-
Here 是一个类似的线程。您可以尝试答案中的步骤。
标签: xamarin.forms xamarin.ios apple-push-notifications azure-notificationhub