Joh*_*ong 6 plugins notifications android ios cordova
谢谢道森!下面提到的问题已在android中解决.但遗憾的是,当我在ios中构建项目时它不起作用,任何人都可以帮忙吗?
我将使用这个插件来构建一个带有本地通知的android/ios应用程序. https://github.com/katzer/cordova-plugin-local-notifications/wiki
首先,我创建了一个phonegap项目
phonegap create notification
Run Code Online (Sandbox Code Playgroud)
添加插件
cordova plugin add https://github.com/katzer/cordova-plugin-local-notifications.git
Run Code Online (Sandbox Code Playgroud)
修改/www/config.xml
<gap:plugin name="de.appplant.cordova.plugin.local-notification" />
Run Code Online (Sandbox Code Playgroud)
我将local-notification.js复制到/ www目录并在index.html中引用它
<html>
<head>
<meta charset="utf-8" />
<meta name="format-detection" content="telephone=no" />
<!-- WARNING: for iOS 7, remove the width=device-width and height=device-height attributes. See https://issues.apache.org/jira/browse/CB-4323 -->
<meta name="viewport" content="user-scalable=no, initial-scale=1, maximum-scale=1, minimum-scale=1, width=device-width, height=device-height, target-densitydpi=device-dpi" />
<link rel="stylesheet" type="text/css" href="css/index.css" />
<title>Hello World</title>
</head>
<body>
<div class="app">
<h1>PhoneGap</h1>
<div id="deviceready" class="blink">
<p class="event listening">Connecting to Device</p>
<p class="event received">Device is Ready</p>
</div>
</div>
<script type="text/javascript" src="cordova.js"></script>
<script type="text/javascript" src="local-notification.js"></script>
<script type="text/javascript">]
window.plugin.notification.local.add({ message: 'Great app!' });
</script>
</body>
Run Code Online (Sandbox Code Playgroud)
我使用命令构建了android应用程序
phonegap build android
Run Code Online (Sandbox Code Playgroud)
我可以成功构建Android应用程序,但没有按预期加速通知.在上面的介绍中,有谁能知道我的错吗?非常感谢你们所有人.
在触发deviceReady事件之后,您将无法调用该函数.
为了进行测试,我总是采用我的插件功能,并将其作为点击操作添加到"设备就绪"标签中.
例:
<p class="event received">Device is Ready</p>
Run Code Online (Sandbox Code Playgroud)
改成:
<p class="event received" onclick="window.plugin.notification.local.add({ message: 'Great app!' });">Device is Ready</p>
Run Code Online (Sandbox Code Playgroud)
我使用默认的cordova示例应用程序执行此操作,因为我知道"设备就绪"将在deviceReady事件触发后才会显示.在您对项目进行任何实际工作之前,这是测试插件是否正常工作的好方法.
大家好,以防万一这是另一个例子...它有自定义声音和其他属性,如标题,徽章类型很有趣这个插件文档尚未完成,创建本地通知为Android工作绝对美丽与最新cordova(3.4. x)只需创建一个var并分配你的包名(你在使用命令行创建phonegap/cordova项目时使用的名称就像这样:
cordova create LocalNotification com.example.localnotification LocalNotification
Run Code Online (Sandbox Code Playgroud)
应该在插件中使用这些值:
var package_name = "com.example.localnotification";
window.plugin.notification.local.add({
date : Math.round(new Date().getTime()/1000 + 5),
title : "Android App Tes Local Notification",
message : "This is a new local notification.",
repeat : "daily",
sound : 'android.resource://' + package_name + '/raw/beep',
badge : 0,
id : 666,
foreground : function(notificationId){
console.log("Hello World! This alert was triggered by notification " + notificationId);
},
background : function(notificationId){
console.log("Hello World! This alert was triggered by notification " + notificationId);
}
});
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
12601 次 |
最近记录: |