将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 (将#修改为@)