我正在尝试使用LocalNotification插件(适用于ios或android),但无法找到正确的文档。有谁知道我做错了什么或我需要添加什么?我正在尝试以下方法:
使用命令行中的以下内容添加插件
phonegap local plugin add https://github.com/katzer/cordova-plugin-local-notifications.git
在config.xml中尝试了以下两种方法:
<plugin name="LocalNotification" value="LocalNotification" />
和
<feature name="LocalNotification">
<param name="ios-package" value="LocalNotification"/>
</feature>
将local-notification.js添加到www文件夹中,并将其包含在index.html文件中,其中包含以下内容:
<script src="local-notification.js"></script>
并在控制器中使用插件(我正在使用Angular):
$scope.localNotify = function(){
var d = new Date();
d = d.getTime() + 5*1000; //60 seconds from now
d = new Date(d);
window.plugins.localNotification.add({
date: d,
repeat:'daily',
message: 'This just fired after a minute!',
hasAction: true,
badge: 1,
id: '1',
sound:'horn.caf',
background:'app.background',
foreground:'app.running'
});
};
我在自述文件中看到https://github.com/simplec-dev/LocalNotification/blob/45867c94ee96aaa90966d22b62acabfc03807cb3/README.md他们说要修改CDVPlugin.m和CDVPlugin.h,但我在项目的任何地方都看不到这些文件。
任何帮助将不胜感激,谢谢!
答案 0 :(得分:3)
搞定了!我不确定是不是因为我使用的版本是针对早期版本的PhoneGap,但我发现这个回购 https://github.com/hiattp/Phonegap-LocalNotification,遵循那里的指示,现在它正在发挥作用。不需要对config.xml进行任何编辑,添加localnotification.js文件,或对index.html进行任何更改。只需按照该链接的指示进行操作即可!
答案 1 :(得分:0)
您需要安装Cordova设备插件:
phonegap local plugin add org.apache.cordova.device
答案 2 :(得分:0)
记录(因为我被困在这里)。
您正在构建PhoneGap iOS项目而不是Cordova iOS项目
然后使用Cordova(仅)项目。
构建PhoneGap:
phonegap build ios
在Cordova建造:
cordova platform add ios
您引用的PhoneGap插件:https://github.com/hiattp/Phonegap-LocalNotification
最新的是这样使用它!