Вот мой PHP
код для отправки нисходящего сообщения с использованием FCM
:
$headers = array('Authorization: key=AIzaSyCih_9lGZ...syoftqE', 'Content-Type: application/json');
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://fcm.googleapis.com/fcm/send');
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($json));
echo "result: ". json_encode((array) json_decode(curl_exec($ch)), JSON_PRETTY_PRINT). "\n";
При обработке уведомлений в iOS AppDelegate
происходит следующее:
func userNotificationCenter(_ center: UNUserNotificationCenter, didReceive response: UNNotificationResponse, withCompletionHandler completionHandler: @escaping () -> Void) {
NotificationHandler.shared.userDidClickNotification(response.notification, with: response)
completionHandler()
}
func userNotificationCenter(_ center: UNUserNotificationCenter, willPresent notification: UNNotification, withCompletionHandler completionHandler: @escaping (UNNotificationPresentationOptions) -> Void) {
NotificationHandler.shared.application(UIApplication.shared, didReceiveRemoteNotification: notification.request.content.userInfo)
completionHandler([.alert, .sound, .badge])
}
func application(_ application: UIApplication, didReceiveRemoteNotification userInfo: [AnyHashable : Any], fetchCompletionHandler completionHandler: @escaping (UIBackgroundFetchResult) -> Void) {
NotificationHandler.shared.application(application, didReceiveRemoteNotification: userInfo)
completionHandler(.newData)
}
Уведомление доставляется в приложение с помощью этого метода
userNotificationCenter(_:willPresent:withCompletionHandler:)
, когда я определяю $json
переменную в моем PHP
коде -
$json = array(
"to" => "dE9KdhVWjEXmhigMML0gbx:APA91bHnRSGX49MPlQu_AqkIkVkW2GiMwAOQI2yF8q1dZDIA3PXK43IVFhwGD1zKtAH9VvbfqxUkr52ACDkl2wJgz2S9bd2kKaQGA-_VBFscC9nmzfW1jB_NYqXMFfe-H3cSwdEgN14c",
"content_available" => true,
"mutable_content" => true,
"data" => array(
"message" => "This is a simple test message."
),
"notification" => array(
"body" => "This is a simple test message.",
"sound" => "default"
)
);
Но когда я определить $json
переменную как -
$json = array(
"to" => "dE9KdhVWjEXmhigMML0gbx:APA91bHnRSGX49MPlQu_AqkIkVkW2GiMwAOQI2yF8q1dZDIA3PXK43IVFhwGD1zKtAH9VvbfqxUkr52ACDkl2wJgz2S9bd2kKaQGA-_VBFscC9nmzfW1jB_NYqXMFfe-H3cSwdEgN14c",
"priority" => "high",
"content_available" => true,
"data" => array(
"message" => "This is a simple test message."
)
);
ожидаемый метод AppDelegate
application(_:didReceiveRemoteNotification:fetchCompletionHandler:)
не вызывается, и ни
userNotificationCenter(_:willPresent:withCompletionHandler:)
не получает вызывается, хотя я получаю статус успешного выполнения от FCM
в обоих случаях, таких как:
result: {
"multicast_id": 6631824525571351017,
"success": 1,
"failure": 0,
"canonical_ids": 0,
"results": [
{
"message_id": "1588239092465052"
}
]
}
Я поддерживаю приложение в состоянии foreground
и тестирую с использованием iOS 13.3.1
на iPhone X
и Xcode 11.3.1
on Mac OS 10.15.4
.
Что-то мне не хватает, или это не ожидаемое поведение?