在英特尔 xdk 上实现 pushwoosh
implementing pushwoosh on intel xdk
如何在英特尔 xdk 上为 android 应用程序实现 pushwoosh。网上有没有一步一步的教程。我已将以下代码放到索引页面上,添加了插件,构建了应用程序并将其安装在我的 phone 上,但推送通知没有通过。请帮忙
<script>
function onDeviceReady() {
if( navigator.splashscreen && navigator.splashscreen.hide ) { // Cordova API detected
navigator.splashscreen.hide() ;
}
if( window.intel && intel.xdk && intel.xdk.device ) { // Intel XDK device API detected, but...
if( intel.xdk.device.hideSplashScreen ) // ...hideSplashScreen() is inside the base plugin
intel.xdk.device.hideSplashScreen() ;
}
initPushwoosh();
}
document.addEventListener("deviceready", onDeviceReady, false) ;
function initPushwoosh()
{
var pushNotification = cordova.require("com.pushwoosh.plugins.pushwoosh.PushNotification");
//set push notification callback before we initialize the plugin
document.addEventListener('push-notification', function(event) {
//get the notification payload
var notification = event.notification;
//display alert to the user for example
alert(notification.aps.alert);
//clear the app badge
pushNotification.setApplicationIconBadgeNumber(0);
});
//initialize the plugin
pushNotification.onDeviceReady({pw_appid:"****-****"});
//register for pushes
pushNotification.registerDevice(
function(status) {
var deviceToken = status['deviceToken'];
console.warn('registerDevice: ' + deviceToken);
},
function(status) {
console.warn('failed to register : ' + JSON.stringify(status));
alert(JSON.stringify(['failed to register ', status]));
}
);
//reset badges on app start
pushNotification.setApplicationIconBadgeNumber(0);
}
</script>
我昨天也刚刚实现了这个并且运行良好。这是我为简化操作所做的工作。
- 在项目选项卡中添加第三方插件。我使用注册的 cordova 插件来简化 github 插件。
- 获取相应配置指南中概述的证书 (iOS) 和凭据 (Android)。 (iOShttps://www.pushwoosh.com/programming-push-notification/ios/ios-configuration-guide/ and Android https://www.pushwoosh.com/programming-push-notification/android/android-gcm-api-configuration/
- 然后按照 iOS 和 android phonegap / cordova 实现的说明进行操作。我没有完全使用说明,我基本上下载了示例文件并在我的项目中创建了相同的文件(index.js、PushwooshAndroid.js、PushwooshiOS.js)
- 在 index.js 文件中为您的平台更改应用 ID 和其他特定 ID。
在 index.html 文件中我添加了这些脚本
我把它们放在 body 而不是 header。然后在 deviceready 下将此行添加到我的 init 函数中:document.addEventListener("deviceready", initPushwoosh, true);
就是这样。有效。我确实在每次初始化时遇到问题,但除此之外它还有效。
如何在英特尔 xdk 上为 android 应用程序实现 pushwoosh。网上有没有一步一步的教程。我已将以下代码放到索引页面上,添加了插件,构建了应用程序并将其安装在我的 phone 上,但推送通知没有通过。请帮忙
<script>
function onDeviceReady() {
if( navigator.splashscreen && navigator.splashscreen.hide ) { // Cordova API detected
navigator.splashscreen.hide() ;
}
if( window.intel && intel.xdk && intel.xdk.device ) { // Intel XDK device API detected, but...
if( intel.xdk.device.hideSplashScreen ) // ...hideSplashScreen() is inside the base plugin
intel.xdk.device.hideSplashScreen() ;
}
initPushwoosh();
}
document.addEventListener("deviceready", onDeviceReady, false) ;
function initPushwoosh()
{
var pushNotification = cordova.require("com.pushwoosh.plugins.pushwoosh.PushNotification");
//set push notification callback before we initialize the plugin
document.addEventListener('push-notification', function(event) {
//get the notification payload
var notification = event.notification;
//display alert to the user for example
alert(notification.aps.alert);
//clear the app badge
pushNotification.setApplicationIconBadgeNumber(0);
});
//initialize the plugin
pushNotification.onDeviceReady({pw_appid:"****-****"});
//register for pushes
pushNotification.registerDevice(
function(status) {
var deviceToken = status['deviceToken'];
console.warn('registerDevice: ' + deviceToken);
},
function(status) {
console.warn('failed to register : ' + JSON.stringify(status));
alert(JSON.stringify(['failed to register ', status]));
}
);
//reset badges on app start
pushNotification.setApplicationIconBadgeNumber(0);
}
</script>
我昨天也刚刚实现了这个并且运行良好。这是我为简化操作所做的工作。
- 在项目选项卡中添加第三方插件。我使用注册的 cordova 插件来简化 github 插件。
- 获取相应配置指南中概述的证书 (iOS) 和凭据 (Android)。 (iOShttps://www.pushwoosh.com/programming-push-notification/ios/ios-configuration-guide/ and Android https://www.pushwoosh.com/programming-push-notification/android/android-gcm-api-configuration/
- 然后按照 iOS 和 android phonegap / cordova 实现的说明进行操作。我没有完全使用说明,我基本上下载了示例文件并在我的项目中创建了相同的文件(index.js、PushwooshAndroid.js、PushwooshiOS.js)
- 在 index.js 文件中为您的平台更改应用 ID 和其他特定 ID。
在 index.html 文件中我添加了这些脚本
我把它们放在 body 而不是 header。然后在 deviceready 下将此行添加到我的 init 函数中:document.addEventListener("deviceready", initPushwoosh, true);
就是这样。有效。我确实在每次初始化时遇到问题,但除此之外它还有效。