objective-c - 推送通知在前台 IOS 中不起作用
问题描述
当应用程序处于后台时,推送通知工作得非常好,主要问题出现在应用程序处于前台时。我能够接收有效负载,但通知未显示在通知横幅中
下面收到的有效载荷
{"data": {"fcm_options": {"image": "https://importduniya.com/dealer/particular/TrustyCane.jpg"}}, "messageId": "1591459535622805", "mutableContent": true, "notification": {"body": "Test123", "ios": {}, "title": "Test"}, "sentTime": "1591459535"}
我认为当应用程序处于前台时不会调用以下函数
//Called when a notification is delivered to a foreground app.
-(void)userNotificationCenter:(UNUserNotificationCenter *)center willPresentNotification:(UNNotification *)notification withCompletionHandler:(void (^)(UNNotificationPresentationOptions options))completionHandler
{
NSLog(@"will-present");
completionHandler(UNAuthorizationOptionSound | UNAuthorizationOptionAlert | UNAuthorizationOptionBadge);
}
解决方案
您还应该实现application:didReceiveRemoteNotification:fetchCompletionHandler :
推荐阅读
- python - 使用pyodbc将python字典列表插入sql server
- java - Spring-Security:使用自定义身份验证器和自定义登录页面
- xamarin - Xamarin - 如果 CollectionView 为空,则显示文本
- odoo - 我们可以在自定义模块 Odoo 中使用产品配置器吗
- android - Android Studio:XmlRpcClientException 无法解析服务器响应:意外的非空白字符数据
- php - 从 Laravel 查询中获取数据的问题
- optimization - 减少反向传播步骤的数量可以提高训练性能吗?
- arrays - 数组中的Matlab点索引错误填充了一个类中的对象
- pandas - Pandas:使用 ndarray 查找行
- javascript - 如何在 GridFs 中获取上传文件的 ID 以与另一个模型关联