APNS Pu sh Фон уведомлений больше не работает - PullRequest
1 голос
/ 09 марта 2020

Извините, что перепостил этот вопрос, как его задавали несколько раз, но для меня не было никакого ответа. Мое приложение больше не просыпается при фоновом уведомлении. Поэтому я обновил свой сценарий php и добавил поле HEADERs, как описано здесь и здесь Но не повезло.

Вот мой пример кода:

<?php

$device_token = 'd98e1d488acac56305a9f83b...b616bc5b5b3bf238dc'; 
//$device_token = '27b296397f81f48590a....fe2742e0b2a051ae2cefffded85d7';

// Put your private key's passphrase here:
$pem_secret = '';
$pem_file = 'pushcert.pem';
$url = "https://api.development.push.apple.com/3/device/$device_token";


//$body = '{"aps":{"alert":"balbla","badge":0,"sound":"default"}}';
$body = '{"aps":{"content-available":1},"acme1":"bar"}';
$header = ['apns-topic'=>'com.blabla.bla',
    'apns-push-type'=>'background',
    'apns-priority'=>'5'
];

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,$url);
curl_setopt($ch, CURLOPT_POST,1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $body);
curl_setopt($ch, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_2_0);
curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
curl_setopt($ch, CURLOPT_SSLCERT, $pem_file);
curl_setopt($ch, CURLOPT_SSLCERTPASSWD, $pem_secret);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);


$information = curl_getinfo($ch);
$response = curl_exec($ch);
$httpcode = curl_getinfo($ch, CURLINFO_HTTP_CODE);

//On successful response you should get true in the response and a status code of 200
//A list of responses and status codes is available at 
//https://developer.apple.com/library/ios/documentation/NetworkingInternet/Conceptual/RemoteNotificationsPG/Chapters/TheNotificationPayload.html#//apple_ref/doc/uid/TP40008194-CH107-SW1
//var_dump($header);
//var_dump($information);
var_dump($response);
var_dump($httpcode);

?>

Я никогда не ввожу метод iOS, чтобы перехватить это уведомление:

-(void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo fetchCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler {
[[NSUserDefaults standardUserDefaults] setValue:userInfo forKey:@"testtesttest"];
// Method called when user click on notification and application is in background
application.applicationIconBadgeNumber = 0;
NSLog(@"did received remote notification");  }

Также в консоли моего устройства кажется, что устройство отменяет мои уведомления или что-то в этом роде не получить enter image description here

Кроме того, стандартные уведомления (не в фоновом режиме) работают нормально. тестирование iOS 13.3.1

Большое спасибо за любую помощь, которую вы можете получить.

Включен фоновый режим:

<key>UIBackgroundModes</key>
<array>
    <string>fetch</string>
    <string>location</string>
    <string>processing</string>
    <string>remote-notification</string>
</array>

enter image description here

Настройки приложения также настроены: enter image description here

1 Ответ

0 голосов
/ 09 марта 2020

Мне удалось сделать это Работа с этим примером кода:

<?php

// open connection
if (!defined('CURL_HTTP_VERSION_2_0')) {
    define('CURL_HTTP_VERSION_2_0', 3);
}
$device_token = 'd56e9ef8b5ea558f07584cf8...498824ece60a36229446a2003116'; //David

// Put your private key's passphrase here:
$pem_secret = '';
$pem_file = 'pushcert.pem';
$url = "https://api.development.push.apple.com/3/device/$device_token";
$app_bundle_id = "com.blabla.blabla";

//$body = '{"aps":{"alert":"balbla","badge":0,"sound":"default"}}';
$body = '{  
            "aps":{"content-available":1},
            "type":"LOCATION",
            "idRequest":"538EAC3E765A4BDC89B554C40F5B14EF"
        }';

$headers = array(
    "apns-topic: {$app_bundle_id}",
    "User-Agent: My Sender",
    "apns-push-type:background",
    "apns-priority:5"
);

 var_dump($body);
$ch = curl_init();
curl_setopt($ch, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_2_0);
curl_setopt($ch, CURLOPT_URL,$url);
curl_setopt($ch, CURLOPT_PORT,443);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_POST,TRUE);
curl_setopt($ch, CURLOPT_POSTFIELDS, $body);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($ch, CURLOPT_TIMEOUT, 30);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_SSLCERT, $pem_file);
curl_setopt($ch, CURLOPT_HEADER, TRUE);

$response = curl_exec($ch);
$information = curl_getinfo($ch,CURLOPT_HTTPHEADER);
$httpcode = curl_getinfo($ch, CURLINFO_HTTP_CODE);

//On successful response you should get true in the response and a status code of 200
//A list of responses and status codes is available at 
//https://developer.apple.com/library/ios/documentation/NetworkingInternet/Conceptual/RemoteNotificationsPG/Chapters/TheNotificationPayload.html#//apple_ref/doc/uid/TP40008194-CH107-SW1
//var_dump($header);
var_dump($information);
var_dump($response);
var_dump($httpcode); 

?>

Ну, по крайней мере, кажется, что приложение просыпается (видно в журнале устройства)

  • Итак, сегодня утром я запускаю код со вчерашнего дня (без каких-либо изменений), и он работал несколько раз, например 4 или 5 раз.
  • Теперь он не работает больше. То же, что и вчера (iOS система, кажется, перехватывает полезную нагрузку, но приложение не активируется)

-> вывод, это системное ограничение, и это так запутанно, когда вам нужно выполнить тесты , Я собираюсь запустить его в производство без уверенности, что он будет работать правильно ...

...