【问题标题】:iOS 10 : Receive Remote Notification in backgroundiOS 10:在后台接收远程通知
【发布时间】:2017-12-28 19:29:33
【问题描述】:

我正在实施 FCM 推送通知。

当应用程序处于前台时,我会收到通知。
但我没有在后台收到通知。

在服务器端我设置了 content-available => true

在 iOS 10 上,我应该实现任何其他方法还是从哪里获得后台通知?

@available(iOS 10.0, *)
func userNotificationCenter(center: UNUserNotificationCenter, willPresentNotification notification: UNNotification, withCompletionHandler completionHandler: (UNNotificationPresentationOptions) -> Void)
{
    print("userNotificationCenter : Forground")

    completionHandler([.Alert,.Sound,.Badge])
}

@available(iOS 10.0, *)
func userNotificationCenter(center: UNUserNotificationCenter, didReceiveNotificationResponse response: UNNotificationResponse, withCompletionHandler completionHandler: () -> Void)
{
    //Code Todo After User presess notification
}

PHP 服务器负载代码:

$payloadFeild = array(
        'registration_ids' => $gotoFcmUidVar,
        'data' => array('MsgKey'=>json_encode($fcmMsgVar)),
        'content_available' => true,
        'priority' => 'high'
    );

【问题讨论】:

标签: ios swift ios10 unusernotificationcenter remote-notifications


【解决方案1】:

经过 2 个月的努力,我终于通过添加 2 件事解决了这个问题:
所有文档中都缺少这一点,旨在帮助所有我不想像我一样挣扎的人

|*|尝试 1):对于 iOS 10 后台通知,在 AppDeligate 中添加以下 deligate 方法:

func application(application: UIApplication, didRegisterUserNotificationSettings notificationSettings: UIUserNotificationSettings)
{
    application.registerForRemoteNotifications()
}

此解决方案来自:https://codentrick.com/firebase-cloud-messaging-ios/


|*|尝试 2):如果使用 Firebase:在 "info.plist"
中设置一个值 属性列表视图:

FirebaseAppDelegateProxyEnabled -> NO

源码查看:

<key>FirebaseAppDelegateProxyEnabled</key>
<false/>

我只提到了 FirebaseAppDelegateProxyEnable。所以也要注意拼写。

【讨论】:

  • 我现在面临同样的问题,但是当应用程序处于后台时通知不起作用
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-02-16
  • 2016-12-24
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多