栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

当应用程序在iOS中处于后台模式时,无法接收GCM通知

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

当应用程序在iOS中处于后台模式时,无法接收GCM通知

我已经添加了

 'content_available' => true,//to trigger when iOS app is in background 'priority' => 'high', 'notification' => $data, $data = array( 'message' => 'Hello World!', 'body' => 'Hello World!');

您的代码。请尝试以下代码;

<?php// Payload data you want to send to iOSdevice(s)// (it will be accessible via intent extras)    $data = array( 'message' => 'Hello World!', 'body' => 'Hello World!');// The recipient registration tokens for this notification// http://developer.android.com/google/gcm/ $ids = array( 'kucy6xoUmx********eeRsla' );// Send a GCM pushsendGoogleCloudMessage(  $data, $ids );function sendGoogleCloudMessage( $data, $ids ){    // Insert real GCM API key from Google APIs Console    // https://pre.google.com/apis/console/ $apiKey = 'AIz******9JA';    // Define URL to GCM endpoint    $url = 'https://gcm-http.googleapis.com/gcm/send';    // Set GCM post variables (device IDs and push payload)         $post = array(         'registration_ids'  => $ids,         'data'   => $data,          'content_available'    => true,    'priority'   => 'high',  'notification' => $data,  );    // Set CURL request headers (authentication and type)$headers = array(   'Authorization: key=' . $apiKey,  'Content-Type: application/json'         );    // Initialize curl handle$ch = curl_init();    // Set URL to GCM endpoint          curl_setopt( $ch, CURLOPT_URL, $url );    // Set request method to POSTcurl_setopt( $ch, CURLOPT_POST, true );    // Set our custom headerscurl_setopt( $ch, CURLOPT_HTTPHEADER, $headers );    // Get the response back as string instead of printing itcurl_setopt( $ch, CURLOPT_RETURNTRANSFER, true );    // Set JSON post data    curl_setopt( $ch, CURLOPT_POSTFIELDS, json_enpre( $post ) );    // Actually send the push       $result = curl_exec( $ch );    // Error handling    if ( curl_errno( $ch ) )    {        echo 'GCM error: ' . curl_error( $ch );    }    // Close curl handle    curl_close( $ch );    // Debug GCM responseecho $result;}?>

在IOS方面;遵循GCM网站上的订单

编辑1: 您可以尝试发送ios通知;

我在上面编辑了您的php代码;变化是;

‘通知’=> $ data,

$ data = array(’message’=>’Hello World!’,’body’=>’Hello World!’);



转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/597097.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号