Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/373.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 聚合物铂推送信息元件_Javascript_Push Notification_Polymer - Fatal编程技术网

Javascript 聚合物铂推送信息元件

Javascript 聚合物铂推送信息元件,javascript,push-notification,polymer,Javascript,Push Notification,Polymer,我试图弄明白如何使用聚合物元素,但运气不好。在元素的文档中,它说您需要注册“gcm_sender_id”,然后定义元素本身,如下所示: <platinum-push-messaging title="Application updated" message="The application was updated in the background" icon-url="icon.png" click-url="notification.html"> <

我试图弄明白如何使用聚合物
元素,但运气不好。在元素的文档中,它说您需要注册“gcm_sender_id”,然后定义元素本身,如下所示:

<platinum-push-messaging
   title="Application updated"
   message="The application was updated in the background"
   icon-url="icon.png"
   click-url="notification.html">
</platinum-push-messaging>
<script src="bower_components/webcomponentsjs/webcomponents-lite.min.js"></script>
<link rel="import" href="bower_components/paper-styles/paper-styles.html">
<link rel="import" href="bower_components/paper-styles/classes/global.html">
<link rel="import" href="bower_components/paper-item/paper-item.html">
<link rel="import" href="bower_components/paper-material/paper-material.html">
<link rel="import" href="bower_components/paper-toggle-button/paper-toggle-button.html">
<link rel="import" href="bower_components/platinum-push-messaging/platinum-push-messaging.html">
<link rel="manifest" href="manifest.json">

为了测试它,有一个名为
testPush(message)
的方法,但它总是返回以下错误:

platinum push messaging.html:437未捕获(承诺中)类型错误:无法读取未定义(…)的属性“active”

我不知道我是不是忘了什么东西,这根本没用,我无法让它工作


有人能给我指出正确的方向吗?

白金推送消息元素可用于使用
gcm\u发送者id订阅推送通知(gcm代表)

如果您在Firebase上托管您的项目,您可以在项目>项目设置>云消息中找到您的
gcm\U发送者\U id

否则,您可以在中创建项目,并在设置(项目编号)中查找ID

注意:由于中的要求部分,推送消息目前仅在Google Chrome中可用

但是让我们一步一步地做一个演示(适用于MAC和UNIX,这是官方演示支持的):

  • 创建一个新文件夹并打开其中的终端
  • 运行
    bowerinit
    (对于
    bower.json
  • 运行
    bower安装聚合关系/纸张元素
    (我们将使用的官方演示使用的元素)
  • 运行
    bower安装聚合关系/platinum推送消息
    (您将获得
    bower\u组件
    文件夹,其中包含演示所需的所有内容)
  • 获取白金推送消息和(将这些文件复制到您刚刚创建的文件夹中)
  • index.html
    中,将6
    rel=“imports”
    更改为
    bower\u组件中相应元素的
    .html
    文件,网络组件包括
    bower\u组件/webcomponentsjs/webcomponents lite.min.js
    。导入内容应类似于以下内容:

    <platinum-push-messaging
       title="Application updated"
       message="The application was updated in the background"
       icon-url="icon.png"
       click-url="notification.html">
    </platinum-push-messaging>
    
    <script src="bower_components/webcomponentsjs/webcomponents-lite.min.js"></script>
    <link rel="import" href="bower_components/paper-styles/paper-styles.html">
    <link rel="import" href="bower_components/paper-styles/classes/global.html">
    <link rel="import" href="bower_components/paper-item/paper-item.html">
    <link rel="import" href="bower_components/paper-material/paper-material.html">
    <link rel="import" href="bower_components/paper-toggle-button/paper-toggle-button.html">
    <link rel="import" href="bower_components/platinum-push-messaging/platinum-push-messaging.html">
    <link rel="manifest" href="manifest.json">
    
    
    
  • 转到并创建一个项目

  • 选择“管理所有项目”、“设置”,选择您的项目并复制“项目编号”
  • 打开
    manifest.json
    并将
    gcm\u sender\u id
    设置为复制的编号
  • 返回并打开“API管理器”(左侧边栏)“凭据”
  • 创建一个新的凭证服务器密钥并复制API密钥(您将在稍后的步骤中需要它,因此请将其保存在.txt或类似文件中)
  • 打开“库”并单击“谷歌云消息”,然后单击启用(屏幕顶部)
  • 运行聚合服务--打开
  • 单击
    纸张切换按钮
    以启用推送消息(如果当前订阅没有显示任何内容,请尝试禁用并重新启用它)
  • 复制
    纸张材料底部的
    curl
    命令
  • 将命令粘贴到终端,并用在步骤11中复制的API密钥替换
    [您的\u PUBLIC\u API\u密钥]
  • 当您运行该命令时,您应该会收到一条推送消息 注意:如果您在Google开发者控制台中查找资料时遇到问题,则有一个解决方案


    太棒了!!!这比聚合物网站上的文档要好,非常感谢。。。