1

我正在实施 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'
    );
4

1 回答 1

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。所以也要注意拼写。

于 2017-08-05T14:12:54.070 回答