【发布时间】:2020-06-01 02:52:33
【问题描述】:
我知道这个问题被问了多次。所以请耐心等待。
我正在尝试使用 Xamarin Forms 与我的 Android/iOS 客户端实现 Azure 通知中心。
对于 Android,一切正常,但对于 iOS,我没有收到任何通知。
这是我为 iOS 所做的清单
- 生成证书和配置文件
- 在 MacOS 上注册了证书
- 导出 p12 文件并导入 Azure Hub
- 我还在 Info.plist 中添加了权限(后台远程通知)
- Entitlements.plist 文件中没有更改
- 我能够从 APN 服务获取设备令牌
- 我可以在获得 Token 后注册到 Azure Hub
但我无法收到任何通知,也没有调用任何函数(DidRegisterUserNotificationSettings,WillPresentNotification,ReceivedRemoteNotification,DidRegisterUserNotificationSettings,FailedToRegisterForRemoteNotifications,DidReceiveRemoteNotification)
但是RegisteredForRemoteNotifications被调用了
我还测试了 devicetoken 是否删除了 '<> ',但没有成功。
可能是什么问题?
这是我的代码
public override void RegisteredForRemoteNotifications(UIApplication application, NSData deviceToken)
{
GlobalVariables.Instance.PnsToken = deviceToken.Description
.Replace("<", string.Empty)
.Replace(">", string.Empty)
.Replace(" ", string.Empty)
.ToUpper();
RegisteredForHub(application, deviceToken);
}
public void RegisteredForHub(UIApplication application, NSData deviceToken)
{
string pnsHandle = deviceToken.Description
.Replace("<", string.Empty)
.Replace(">", string.Empty)
.Replace(" ", string.Empty)
.ToUpper();
_hub = new SBNotificationHub(Constant.ListenConnectionString, Constant.NotificationHubName);
_hub.UnregisterNative((error) =>
{
if (error != null)
{
Debug.WriteLine($"Unable to call unregister Native {error}");
}
});
_hub.UnregisterTemplate("defaultTemplate",(error) =>
{
if (error != null)
{
Debug.WriteLine($"Unable to call unregister Template {error}");
}
});
// update registration with Azure Notification Hub
_hub.UnregisterAll(deviceToken, (error) =>
{
if (error != null)
{
Debug.WriteLine($"Unable to call unregister {error}");
return;
}
var tags = new NSSet(Constant.SubscribeTags);
_hub.RegisterNative(pnsHandle, tags, (errorCallback) =>
{
if (errorCallback != null)
{
Debug.WriteLine($"RegisterNativeAsync error: {errorCallback}");
}
});
var templateExpiration = DateTime.Now.AddDays(120)
.ToString(System.Globalization.CultureInfo.CreateSpecificCulture("en-US"));
//_hub.RegisterTemplate(deviceToken, "defaultTemplate", Constant.ApnTemplateBody, templateExpiration,
// tags, (errorCallback) =>
// {
// if (errorCallback != null)
// {
// Debug.WriteLine($"RegisterTemplateAsync error: {errorCallback}");
// }
// });
});
【问题讨论】:
标签: azure xamarin.forms xamarin.ios apple-push-notifications