答案 0 :(得分:2)
您需要将content_available
参数发送到true
https://developers.google.com/cloud-messaging/http-server-ref
您还需要在应用remote-notifications
文件中为UIBackgroundMode
添加Info.plist
。 https://developer.apple.com/library/ios/documentation/General/Reference/InfoPlistKeyReference/Articles/iPhoneOSKeys.html#//apple_ref/doc/uid/TP40009252-SW22
答案 1 :(得分:0)
只是因为没有显示通知,通知需要保持沉默。为此,您不能在邮件中包含任何标题,正文或副标题。
默认情况下,iOS会忽略没有标题,正文或副标题的邮件,因此需要额外的参数content_available: true
。
因此,如果您发送的此邮件没有任何标题,正文和副标题,但content_available: true
仍未发生任何事情。
要回复此问题,应用程序需要获得在收到scilent
通知后在后台运行小任务的权限。
要获得此权限,您需要编辑.plist文件并添加值为Required background modes
的字段remote-notifications
。或者您可以选择项目并转到Capabilities tab -> Background Modes -> Remote notifications
。这将为您添加.plist条目。
现在,您可以在接收通知时在后台执行小任务。就像解析通知有效载荷中的一些自定义数据或进行一些轻型网络调用等。
您希望在AppDelegate中查找:
func application(_ application: UIApplication, didReceiveRemoteNotification userInfo: [AnyHashable : Any], fetchCompletionHandler completionHandler: @escaping (UIBackgroundFetchResult) -> Void)
您可以在此解析userInfo
数据。