首页 | 新闻 | 新品 | 文库 | 方案 | 视频 | 下载 | 商城 | 开发板 | 数据中心 | 座谈新版 | 培训 | 工具 | 博客 | 论坛 | 百科 | GEC | 活动 | 主题月 | 电子展
返回列表 回复 发帖

iOS 普通推送和静默推送(4)

iOS 普通推送和静默推送(4)

服务端(我们公司是PHP)配置静默推送的格式如下(非常严格,非常严格,非常严格,一项不满足,就不是静默推送,那就变成了普通的有文字有声音的推送):

1.传入的alertMsg对应的值一定为空或者压根就不传alertMsg字段。

$apn->alertMsg="";

    contentAvailable的值一定为1

$apn->contentAvailable=1;

3.sound对应的值一定为com.gexin.ios.silence.改成其他的字符串的话,应用在后台收到推送时,会听到"铛"的一声。 或者sound对应的值为任意常量也可以实现静音(真机测试过一次,发现确实没有声音。测试次数过少,不是太敢断定,如果有想测试的,可以将sound的值设置成常量试一下)。

     
    $apn->sound="com.gexin.ios.silence";

4.其他的倒无关紧要了,不影响静默推送的格式。
综合1.2.3.4,静默推送,php服务端要设置的核心代码必定是下面的这种格式:

        $apn->alertMsg="";// alertMsg一定不要有值
        $apn->sound="com.gexin.ios.silence";
        $apn->contentAvailable=1;// 一定为1

以我们项目中静默推送的实战演练
关键代码如下:

    function IGtTransmissionTemplateDemo($appid,$appkey,$msgContent,$keyType,$keyId,$temp_ietm="",$client_notice="default"){
        $msg = array(
            'keyType' => $keyType,
            'keyId' => $keyId,
            'msg' => $msgContent,
            'nickname' => $temp_ietm
        );
        $msg = json_encode($msg);
        $template =  new IGtTransmissionTemplate();
        $template->set_appId($appid);//应用appid
        $template->set_appkey($appkey);//应用appkey
        $template->set_transmissionType(2);//透传消息类型
        $template->set_transmissionContent($msg);//透传内容
      
        $apn = new IGtAPNPayload();
        $alertmsg=new DictionaryAlertMsg();
        $alertmsg->body=$msgContent;
        $alertmsg->actionLocKey="ActionLockey";
        $alertmsg->locKey=$msgContent;
        $alertmsg->locArgs=array("locargs");
        $alertmsg->launchImage="launchimage";
        //        IOS8.2 支持
        $alertmsg->title=SYS_ZH_NAME;
        $alertmsg->titleLocKey=SYS_ZH_NAME;
        $alertmsg->titleLocArgs=array("TitleLocArg");
        // $apn->alertMsg=$alertmsg;
        $apn->alertMsg="";
        $apn->sound="com.gexin.ios.silence";
        $apn->contentAvailable=1;
        $apn->badge=1;
        $apn->add_customMsg("payload","payload");
        $apn->add_customMsg("keyType",$keyType);
        $apn->add_customMsg("keyId",$keyId);
        $apn->add_customMsg("nickname",$nickname);
        $apn->add_customMsg("msg",$msgContent);
     
        $apn->category="ACTIONABLE";
        $template->set_apnInfo($apn);
     
        return $template;
    }
     

来来来,一起截图圈重点。
返回列表