gpt4 book ai didi

javascript - 触发iOS的本地通知-Cordova/Phonegap

转载 作者:行者123 更新时间:2023-12-01 16:36:21 25 4
gpt4 key购买 nike

我正在使用此插件,并尝试使用Local notifications plugin为我的Cordova iOS应用触发本地通知。

我dd遵循以下步骤:

  • 已安装的插件:cordova plugin add de.appplant.cordova.plugin.local-notification@0.7.7
  • 更新了config.xml:gap:plugin name="de.appplant.cordova.plugin.local-notification"
  • 的head标签中添加了以下JavaScript

    index.html
    plugin.notification.local.promptForPermission(function (granted) {
    alert("promptForPermission: "+granted);
    });

    plugin.notification.local.hasPermission(function (granted) {
    alert("hasPermission: "+granted);
    });
  • 在5秒钟后,在index.html中具有一个按钮以创建本地通知。

  • 该代码如下所示:
    function setLocalNotification()
    {
    alert("from setLocalNotification");
    var t = new Date();
    t.setSeconds(t.getSeconds() + 3);

    window.plugin.notification.local.add({
    title: 'Scheduled with delay',
    message: 'Test Message ',
    date: t
    });

    alert("alert set");
    };

    我确实看到提示用户输入权限的消息,并且hasPermission方法的警报将值显示为true。但是我仍然无法通过单击按钮来获取要设置的实际本地通知。我已经通过复制 this issue修复程序更新了 this的APPLocalNotification.m文件。

    我在控制台日志中看不到任何其他错误,但是我仍然无法触发本地通知。

    最佳答案

    您应该检查设备是否准备就绪(document.addEventListener('deviceready',function(){
    ),并检查插件是否正确添加。$ cordova plugin ls。

    确保您具有“<脚本类型=“text / javascript” src =“cordova.js”>
    “在您的html中。

    祝好运!

    关于javascript - 触发iOS的本地通知-Cordova/Phonegap,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27879983/

    25 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com