DidReceiveNotificationRequest中没有被调用 [英] DidReceiveNotificationRequest in not getting called
问题描述
我有一个xamarin表单应用程序,并且从服务器接收通知时未调用ios Notification Service扩展.
I have a xamarin forms application and ios Notification service extension is not getting called when I receive notification from server.
到目前为止,我已经做了以下事情:
I have done the following things so far:
-
已在apns有效负载中添加了
mutable-content = 1
.
这就是我在服务中操纵apns有效载荷的方式
This is how I manipulate the apns payload in the service
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
I also have the the notification service extension bundle id done.(My app bundle id is
com.companyname.appname.test
and the extension bundle id iscom.companyname.appname.test.xxxxServiceExtension
在Finishlaunching方法的AppDelegate类中,我还添加了权限代码.
In the AppDelegate class in Finishlaunching method I also have the permission code added.
UNUserNotificationCenter.Current.RequestAuthorization(UNAuthorizationOptions.Alert, (approved, err) => {
});
还有什么需要做的吗?
推荐答案
仅当远程通知的有效负载包含以下信息时,系统才会执行通知内容应用扩展:
The system executes your notification content app extension only when a remote notification’s payload contains the following information:
有效负载必须包含值为1的可变内容密钥.
The payload must include the mutable-content key with a value of 1.
有效负载必须包括带有标题,副标题或正文信息的警报字典.
The payload must include an alert dictionary with title, subtitle, or body information.
清单2显示了包含加密数据的通知有效负载的JSON数据.设置了可变内容标志,以便用户设备知道运行相应的服务应用扩展程序,其代码显示在.
Listing 2 shows the JSON data for a notification payload containing encrypted data. The mutable-content flag is set so that the user’s device knows to run the corresponding service app extension, the code for which is shown in .
清单2 指定远程通知有效负载
Listing 2 Specifying the remote notification payload
{
"aps" : {
"category" : "SECRET",
"mutable-content" : 1,
"alert" : {
"title" : "Secret Message!",
"body" : "(Encrypted)"
},
},
"ENCRYPTED_DATA" : "Salted__·öîQÊ$UDì_¶Ù∞è Ω^¬%gq∞NÿÒQùw"
}
确定要指定警报键吗?
这篇关于DidReceiveNotificationRequest中没有被调用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!