Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/swift/20.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 我无法接收后台应用程序的Firebase消息通知_Ios_Swift_Firebase_Google Cloud Functions - Fatal编程技术网

Ios 我无法接收后台应用程序的Firebase消息通知

Ios 我无法接收后台应用程序的Firebase消息通知,ios,swift,firebase,google-cloud-functions,Ios,Swift,Firebase,Google Cloud Functions,在我的颤振应用程序中,管理员用户可以通过FCM向其他用户发送通知。在安卓系统中已经可以工作了,但在iOS系统中,只有当应用程序打开时才会收到通知。我已经在网上尝试了很多东西,但仍然不起作用 这是管理推送的dart代码: 未来myBackgroundMessageHandler(映射消息)异步{ if(message.containsKey('data')){ //处理数据消息 最终动态数据=消息['data']; } if(message.containsKey('notification'))

在我的颤振应用程序中,管理员用户可以通过FCM向其他用户发送通知。在安卓系统中已经可以工作了,但在iOS系统中,只有当应用程序打开时才会收到通知。我已经在网上尝试了很多东西,但仍然不起作用

这是管理推送的dart代码:

未来myBackgroundMessageHandler(映射消息)异步{ if(message.containsKey('data')){ //处理数据消息 最终动态数据=消息['data']; } if(message.containsKey('notification')){ //处理通知消息 最终动态通知=消息['notification']; } //或者做其他工作。 } 类PushNotificationsManager{ PushNotificationsManager.uz(); factory PushNotificationsManager()=>\u实例; 静态最终PushNotificationsManager _实例=PushNotificationsManager ._(); 最终FirebaseMessaging_FirebaseMessaging=FirebaseMessaging(); 最终通知插件_NotificationPlugin=NotificationPlugin(); Future init()异步{ if(Platform.isIOS){ _firebaseMessaging.requestNotificationPermissions( ioNotificationSettings()); } _firebaseMessaging.configure( //当应用程序位于前台且我们收到推送notif时调用。 onMessage:(映射消息)异步{ 打印(“onMessage:${message}”); 打印(消息['notification']['body']); _notificationPlugin.showNotification( 标题:"测试",, 内容:消息['notification']['body'] ); //发送通知(); }, //当应用程序完全关闭且其已打开时调用 //直接从通知中删除 //onBackgroundMessage:Platform.isAndroid?myBackgroundMessageHandler:null, onBackgroundMessage:myBackgroundMessageHandler, onLaunch:(映射消息)异步{ 打印(“onLaunch:$message”); if(Platform.isIOS){ 消息=_modifyNotificationJson(消息); } }, //当应用程序位于后台且其已从notif打开时调用 onResume:(映射消息)异步{ 打印(“onMessage:${message}”); if(Platform.isIOS){ 消息=_modifyNotificationJson(消息); } }, ); } 映射_modifyNotificationJson(映射消息){ message['data']=Map.from(message???{}); 消息['notification']=消息['aps']['alert']; 返回消息; } 未来发送通知(字符串正文、字符串标题)异步{ 最终字符串url=https://fcm.googleapis.com/fcm/send'; 风险值通知; 通知= {“通知”:{“正文”:“${body}”,“标题”:“${title}”,“内容可用”:“真”,“点击操作”:“颤振通知”{click},“优先级”:“高”,“至”:“我的主题”}; 最终响应=等待http.post( 网址, 标题:{ “内容类型”:“应用程序/json”, “保持活动”:“超时=5”, “授权”:“key=MYKEY” }, 主体:通知 ); 打印(响应.正文); } } AppDelegate.swift:

导入UIKit
进口颤振
进口火基
@UIApplicationMain
@objc类AppDelegate:AppDelegate{
重写func应用程序(
_应用程序:UIApplication,
didFinishLaunchingWithOptions launchOptions:[UIApplication.launchOptions键:任意]?
)->布尔{
如果可用(iOS 10.0,*){
//对于iOS 10显示通知(通过APNS发送)
UnuseNotificationCenter.current().delegate=self
let authOptions:UNAuthorizationOptions=[.alert、.badge、.sound]
UnuseNotificationCenter.current().requestAuthorization(
选项:authOptions,
completionHandler:{{{,{in})
}否则{
let设置:UIUserNotificationSettings=
UIUserNotificationSettings(类型:[.alert、.badge、.sound],类别:nil)
application.registerUserNotificationSettings(设置)
}
应用程序.注册表项更改()
FirebaseApp.configure()
GeneratedPluginRegistrant.register(带:self)
return super.application(application,didfishlaunchingwithoptions:launchOptions)
}
}

我已经在xcode中启用了推送通知和后台模式,已经检查了我的证书,但问题仍然存在。有人能帮我吗?我在这上面花了一个多星期的时间。。我所做的是正确的?

根据提及的文档检查以下几点

一,

要发送后台通知,请使用创建远程通知 仅包含内容可用键的aps字典,如 如清单1所示。您可以在有效负载中包括自定义密钥,但是 aps字典不得包含任何会触发用户 互动

  • 此外,通知的POST请求应包含 值为background的apns推送类型标头字段,以及 apns优先级字段的值为5

    • 如果强制退出或终止应用程序,系统将丢弃该应用程序 已收到通知。如果用户启动应用程序,系统将 立即发送保留的通知
    • 介绍背景 通知,系统将在后台唤醒您的应用程序
  • (我看不到你
    appDelegate
    的代码中有
    didReceiveMotonification
  • 在iOS上,它会调用应用程序代理的
    application(uuquo:didReceiveMemotentification:fetchCompletionHandler:)
    方法

    此外还指出:

    五,

    将后台推送类型用于在中传递内容的通知 背景,并且不会触发任何用户交互。如果你设定 此推送类型的apns主题标题字段必须使用应用程序的捆绑包 ID作为主题。始终使用优先级5。使用优先级10是一个错误

    如果满足上述检查表,则该检查表应有效。您可以提供您正在发送的通知的最终内容,或者您需要的有效负载