ios - DidReceiveNotificationRequest 没有被调用
问题描述
我有一个 xamarin 表单应用程序,当我收到来自服务器的通知时,没有调用 ios 通知服务扩展。
到目前为止,我做了以下事情:
已
mutable-content = 1
在 apns 有效负载中添加了 。这就是我在服务中操作 apns 有效负载的方式
public class NotificationService : UNNotificationServiceExtension
{
Action<UNNotificationContent> ContentHandler { get; set; }
UNMutableNotificationContent BestAttemptContent { get; set; }
protected NotificationService(IntPtr handle) : base(handle)
{
}
public override void DidReceiveNotificationRequest(UNNotificationRequest request, Action<UNNotificationContent> contentHandler)
{
ContentHandler = contentHandler;
BestAttemptContent = (UNMutableNotificationContent)request.Content.MutableCopy();
var newAlertContent = new UNMutableNotificationContent
{
Body = "Body from Service",
Title = "Title from Service",
Sound = BestAttemptContent.Sound,
Badge = 2
};
ContentHandler(newAlertContent);
}
public override void TimeWillExpire()
{
}
}
我还完成了通知服务扩展包 ID。(我的应用包 ID 是
com.companyname.appname.test
,扩展包 ID 是com.companyname.appname.test.xxxxServiceExtension
在 Finishlaunching 方法的 AppDelegate 类中,我还添加了权限代码。
UNUserNotificationCenter.Current.RequestAuthorization(UNAuthorizationOptions.Alert, (approved, err) => {
});
还有什么我需要做的吗?
解决方案
仅当远程通知的有效负载包含以下信息时,系统才会执行您的通知内容应用程序扩展:
有效负载必须包含值为 1 的 mutable-content 键。
有效负载必须包含带有标题、副标题或正文信息的警报字典。
清单 2 显示了包含加密数据的通知负载的 JSON 数据。设置了 mutable-content 标志,以便用户的设备知道运行相应的服务应用程序扩展,其代码显示在 .
清单 2 指定远程通知负载
{
“aps” : {
“category” : “SECRET”,
“mutable-content” : 1,
“alert” : {
“title” : “Secret Message!”,
“body” : “(Encrypted)”
},
},
“ENCRYPTED_DATA” : “Salted__·öîQÊ$UDì_¶Ù∞è Ω^¬%gq∞NÿÒQùw”
}
你确定你指定了警报键吗?
推荐阅读
- scala - 如何重新配置 spark /hadoop 以读取以“_”(下划线)开头的文件?
- cmd - 如何让“发送”向 Windows cmd 终端提供输入?
- python - 如何查找所有长度为 5 且将 1 个数字和 4 个字母划分为所有组组合的字符串
- arrays - 如何选择数组的任何部分是否包含在 Postgres 的数组列中?
- r - R如何从多列表数据结构中提取整数向量
- phpword - PHPWord 单元格中文本的垂直对齐方式
- angular - 使用 Angular 6 从 ASP.NET Web API 方法下载文件
- html - 我们如何使用 VueJS 将相同的消息反转和删除到不同的按钮?
- sql - 在存在条件下使用联合的输出
- ios - UICollectionView - 类似于 Viber 聊天对话的项目插入动画