如何解决将OneSignal文档中的javascript代码添加到Cordova应用时出错
尝试将OneSignal的推送通知添加到我的cordova编译的应用程序中。我现在正在测试空项目。
摘自文档(摘录):“ 复制此代码,粘贴到index.js中,设置您的APP_ID,进行编译”。可以,但是在粘贴并设置了AppID之后,我在控制台中出现了错误,而不是正在运行的应用程序:)
代码:
receivedEvent: function(id) {
//START ONESIGNAL CODE
//Remove this method to stop OneSignal Debugging
window.plugins.OneSignal.setLogLevel({logLevel: 6,visualLevel: 0});
var notificationOpenedCallback = function(jsonData) {
console.log('notificationOpenedCallback: ' + JSON.stringify(jsonData));
};
// Set your iOS Settings
var iosSettings = {};
iosSettings["kOSSettingsKeyAutoPrompt"] = false;
iosSettings["kOSSettingsKeyInAppLaunchURL"] = false;
window.plugins.OneSignal
.startInit("YOUR_ONESIGNAL_APP_ID")
.handleNotificationOpened(notificationOpenedCallback)
.iOSSettings(iosSettings)
.inFocusDisplaying(window.plugins.OneSignal.OSInFocusDisplayOption.Notification)
.endInit();
// The promptForPushNotificationsWithUserResponse function will show the iOS push notification prompt. We recommend removing the following code and instead using an In-App Message to prompt for notification permission (See step 6)
window.plugins.OneSignal.promptForPushNotificationsWithUserResponse(function(accepted) {
console.log("User accepted notifications: " + accepted);
});
//END ONESIGNAL CODE
}
第一行代码错误:
“未捕获的SyntaxError:函数语句需要函数名称”
我不知道这种函数命名(用冒号),所以我试图将第一行更改为
function receivedEvent(id) {
但它也不起作用。
文档在这里:https://documentation.onesignal.com/docs/cordova-sdk-setup 我在做什么错了?
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。