如何使用Urban Airship Deep链接与PHP

时间:2015-12-28 11:43:48

标签: php push-notification apple-push-notifications deep-linking urbanairship.com

我尝试使用Urban Airship PHP libraray实现深层链接消息传递,但我找不到文档或相关代码。 现在我有这个

require_once 'vendor/autoload.php';
use UrbanAirship\Airship;
use UrbanAirship\AirshipException;
use UrbanAirship\UALog;
use UrbanAirship\Push as P;
use Monolog\Logger;
use Monolog\Handler\StreamHandler;

$droidToken = "my-device-token" ;

UALog::setLogHandlers(array(new   StreamHandler("php://stdout",Logger::INFO)));
$airship = new Airship("key", "Secret");

    $req = $airship->push()
          ->setAudience(P\apid($droidToken))
          ->setMessage(P\message("This is the title",
               "<html><body><h1>This is the message</h1></body></html>",
               "text/html",
               "utf-8",
               array("value"=>"agh://myAppName.app/preferences23")))
          ->setDeviceTypes(P\all);
        $response = $req->send();

其中agh://myAppName.app是模板,preferences23应该是值

understand我需要将其添加到actions标记中:

{
   "actions": {
      "open": {
         "type": "deep_link",
         "content": "prefs"
      }
   }
}

但在哪里?

当我运行上面的代码时,我会在手机中收到该消息,但是,消息中没有深层链接。

1 个答案:

答案 0 :(得分:0)

发现它! 您只需要在通知结构中添加action

type: deep_link,  content:是深层链接网址。

$req = $airship->push()
       ->setAudience(P\apid($deviceToken))
       ->setNotification(P\notification("my message',
                                         array("actions" => array(
                                                   "open" => array(
                                                      "type" => "deep_link",
                                                      "content" => "js://myapp.app/deepLink" 
                                                    )))))
       ->setDeviceTypes(P\all);