1

Background

  1. I installed PushPlugin. According to the docs I used automatic installation. But when I run cordova run android, JavaScript returns the error, 'Cannot read property pushNotification of undefined'

  2. If I add

    <script type="text/javascript" charset="utf-8" src="PushNotification.js"></script>
    

    then the error changes to the one in this question's title.

  3. This is how my HTML loads the scripts

    <script type="text/javascript" src="cordova.js"></script>
    
    <script src="js/libs/jquery-1.10.2.js"></script>
    <script src="js/libs/handlebars-1.1.2.js"></script>
    <script src="js/libs/ember-1.5.1.js"></script>
    
    <script type="text/javascript" src="js/index.js"></script>
    <script type="text/javascript" src="js/model.js"></script>
    <script type="text/javascript" src="js/router.js"></script>
    <script type="text/javascript" src="js/controller.js"></script>
    <script type="text/javascript" src="js/view.js"></script>
    

    Initialization code is in index.js where after deviceready I call pushNotification.register.

    After the register completes, I call MyEmberApp.deferReadiness()

  4. After automatically installing the plugin, I just have to run register, according to the docs. But this still leads to 'Cannot read pushNotification....'

  5. It seems that PushNotification.js is automatically inserted after deviceready fires. But the plugin is not doing so. If I insert the script in index.html, the error Object has no method 'exec' occurs because deviceready hasn't fired yet.

  6. deviceready

    if ('device is android') {
        document.addEventListener("deviceready", this.onDeviceReady(), false);
    }
    

Question

What am I doing wrong? How should I do this?

Update

I just realized that I have only tried the automatic installation. I have not tried the manual steps. But that is no reason why the direct plugin install shouldn't work


SQL Server After Update Trigger Not firing

Kindly help, I have been trying to create an update trigger to insert data into a specific table once it's updated with a certain value. "Accepted". for somewhat reason the trigger is not firing

IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[TRGIU_CLEARING_SAMPLE_RESULT]') and OBJECTPROPERTY(id, N'IsTrigger') = 1)
DROP TRIGGER [dbo].[TRGIU_CLEARING_SAMPLE_RESULT]
GO

CREATE TRIGGER [dbo].[TRGIU_CLEARING_SAMPLE_RESULT] ON [dbo].[CLEARING_BATCH]               
AFTER INSERT                
AS                

IF UPDATE(QM_STATUS)                
BEGIN                
  Declare @QM_Status Varchar(12),                
          @QM_Status_Old Varchar(12),                
          @Submission_Pk Uniqueidentifier            
                
  SELECT @QM_Status = I.QM_STATUS,                
         @QM_Status_old = D.QM_STATUS,                
         @Submission_Pk = I.PK               
         --@Lab_used = LE.ID                            
    FROM CLEARING_BATCH CB                
    LEFT JOIN SAMPLE_RESULT SR ON CB.PK = SR.PPK                 
    JOIN INSERTED I ON SR.PK = I.PPK                 
    JOIN DELETED D ON I.PK = D.PK 

             
  IF(@QM_Status = 'Accepted' and (@QM_Status <> @QM_Status_old or @QM_Status_old is null))                
  
  
  begin

  INSERT INTO BATCH(PPK,BATCH_ID)

  SELECT CB.PK,CB.BATCH_ID
  FROM LABORATORY L
  JOIN CLEARING_BATCH CB ON L.PK = CB.PPK
  JOIN CLEARING_SAMPLE_RESULT CSR ON CB.PK = CSR.PPK
  LEFT JOIN BATCH B ON CB.PK = B.PPK
  WHERE B.PPK IS NULL
 

  UPDATE BATCH
  SET BATCH_ID = CB.BATCH_ID

  FROM BATCH B
  JOIN CLEARING_BATCH CB ON B.PPK = CB.PPK

  END
  end
  GO

4

2 回答 2

2

我终于意识到错误是由于EventListenerfor deviceready。我变了

  if ('device is android') {
        document.addEventListener("deviceready", this.onDeviceReady(), false);
  }

  document.addEventListener("deviceready", this.onDeviceReady, false);

一切都到位了。虽然这是一个粗心的错误,但我仍然留下这个问题,它是其他可能遇到此问题的人的答案

于 2014-12-20T06:21:14.750 回答
1

我真的不明白,为什么你的解决方案不起作用。我唯一能提供的就是我的工作解决方案。那里可能有一些冗余或不必要的东西,因为我自己在开始工作之前尝试了 35 个版本:

第一件事是我在 App Initializer 中附加到 pg 事件并注册我的通知服务:

Ember.Application.initializer({
    name: 'phonegap',

    /* ...... */

    initialize: function(container, application){
        // Push
        container.register('notification:manager', GambifyApp.NotificationManager, { singleton: true });
        container.register('notification:handler', GambifyApp.NotificationHandler, { instantiate: false });
        container.injection('notification:handler', 'appController', 'controller:application');
        container.injection('notification:handler', 'commentRoute', 'route:usergroup.comment');
    }
}

然后我的经理服务正在注册设备:

GambifyApp.NotificationManager = window.GambifyApp.NotificationManager = Ember.Object.extend({
    init: function(){
        //var self = this;
        var pushNotification = Ember.get(window, 'plugins.pushNotification');
        if(!Ember.isEmpty(pushNotification)){
            if ( device.platform == 'android' || device.platform == 'Android' )
            {
                pushNotification.register(
                    this.successHandler,
                    this.errorHandler, {
                        "senderID":GambifyApp.config.android_sender_id,
                        "ecb":"window.GambifyApp.NotificationHandler.onNotificationGCM"
                    });
            }
        } else {
            Ember.Logger.error('pushNotification Plugin not running');
        }
        GambifyApp.NotificationHandler.manager = this;
    },

    successHandler: function (result) { },

    errorHandler: function (error) {
        Ember.Logger.error('Error while registering with push:' + error);
    },
});

然后在成功的情况下,使用我的处理程序可以使用的设备 ID 调用 ECB:

GambifyApp.NotificationHandler =  window.GambifyApp.NotificationHandler = {

    manager: null,

    onNotificationGCM: function(e){
        console.log('---------- GCM Event:-----------');
        console.log(e);

        if(e.event === "registered") {
            console.log(e.regid); // Registraion ID
        }
    },

};

希望这可能会有所帮助。

于 2014-11-26T11:57:00.410 回答