静音背景推送iOS无法从服务器访问

问题描述

我收到来自服务器的静后台推送通知,其中包含以下有效负载-(我正在使用版本为ios 14.0.1和XCode版本12.0的ios设备对此进行测试)

{"aps":{"content-available":1},"PushID":"{"PushId":"xxxxxxxxxxx","CreatedOn":000000000,"Operation":"00","OperationName":"OperationName1","Issilentpush":"True"}"}

此外,我已在“签名和功能”的“后台模式”中启用了“后台获取”和“远程通知”,并且还在AppDelegate.m类中添加了以下代码

- (void)application:(UIApplication *)application
didReceiveRemoteNotification:(NSDictionary *)userInfo
fetchCompletionHandler:(void (^)(UIBackgroundFetchResult result))completionHandler
{
 
   //Success
    NSLog(@"userInfo value=%@",userInfo);
    
    completionHandler(UIBackgroundFetchResultNewData);
}
​

要提到的另一点是,如果我通过某些在线APNS测试器传递相同的有效载荷,则我将null的pushContent和Data表示为null,请您帮我解决这个问题,让我知道问题出在哪里吗?

解决方法

您应将AppDelegate设置为UNUserNotificationCenter.current()的代表。

AppDelegate因此需要实现协议UNUserNotificationCenterDelegate。 当您的应用收到远程推送通知时,应调用此协议的方法userNotificationCenter(UNUserNotificationCenter,didReceive: UNNotificationResponse,withCompletionHandler: () -> Void)