javascript - 我找不到这个语法错误

标签 javascript push-notification phonegap-build

一旦有人向我指出这一点,我就会觉得自己像个十足的白痴,但我遇到了语法错误,我无法弄清楚问题出在哪里。这是我的代码(错误出现在最后一行,但我怀疑是该行导致的):

// handle GCM notifications for Android
 function onNotificationGCM(e) {
 switch( e.event )
 {
     case 'registered':
     if ( e.regid.length > 0 )
     {
         // Your GCM push server needs to know the regID before it can push to this device
         // here is where you might want to send it the regID for later use.
         PushWoosh.appCode = "33F93-5013B";
         PushWoosh.register(e.regid, function(data) {
                     alert("PushWoosh register success: " + JSON.stringify(data));
                 }, function(errorregistration) {
                     alert("Couldn't register with PushWoosh" +  errorregistration);
                 });

     }
 break;

谢谢大家,我感觉自己像个白痴,度过了令人沮丧的一天。

最佳答案

您的 onNotificationGCM() 函数未关闭,并且其中包含的 switch block 也未关闭。 JavaScript 解析器期望看到两个额外的右大括号 (}),但输入文件在看到它们之前就终止了。

我的猜测是,您需要在 break; 语句之后、在分配 PushNotification.prototype.register 之前添加这两个大括号。

关于javascript - 我找不到这个语法错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16286983/

相关文章:

cordova - Phonegap Build——无闪屏

javascript - Meteor 客户端中 mongodb 选择器的替代方案

javascript - 如何在 Angular2 应用程序中使 Facebook og 标签动态化?

ios - 当应用程序位于前台时,如何在点击推送通知时执行操作而不是自行执行操作?

ios - Firebase:即使应用程序退出,也会收听 ChildEventListener

cordova - 命名空间前缀 android 未定义

javascript - AngularJS:上传图像并保存在本地存储中

javascript - 关注表单中的所有元素

javascript - Google 跟踪代码管理器 API 示例在控制台中抛出 "Uncaught RangeError: Maximum call stack size exceeded"错误

ios - 当应用程序未处于事件状态时,GCM 推送通知不适用于 iOS