                     self.commandDelegate!.sendPluginResult(pluginResult, callbackId:command.callbackId)
                 }
             });
-            
-        })
-    }
-    
+
+        })
+    }
+
     func didRegisterForRemoteNotifications(deviceToken: NSData) {
-    
+
         CDVBMSPush.sharedInstance.shouldRegister = true;
         CDVBMSPush.sharedInstance.bmsPushToken = deviceToken;
         if (CDVBMSPush.sharedInstance.registerCallbackId == nil) {

                        CDVBMSPush.sharedInstance.registerCommandDelegate!.send(pluginResult, callbackId:CDVBMSPush.sharedInstance.registerCallbackId)
                    }
                    else {
                        
                        let pluginResult = CDVPluginResult(status: CDVCommandStatus_OK, messageAs: response)
                        // call success callback
                        CDVBMSPush.sharedInstance.registerCommandDelegate!.send(pluginResult, callbackId:CDVBMSPush.sharedInstance.registerCallbackId)
                    }
                }
            }
            
        })
        
    }
    
    
    func unregisterDevice(_ command: CDVInvokedUrlCommand) {
        self.commandDelegate!.run(inBackground: {
            
            BMSPushClient.sharedInstance.unregisterDevice(completionHandler: { (response, statusCode, error) -> Void in
                
                if error.isEmpty {
                    
                    let message = response?.description
                    // call success callback
                    let pluginResult = CDVPluginResult(status: CDVCommandStatus_OK, messageAs: message)
                    // call success callback
                    self.commandDelegate!.send(pluginResult, callbackId:command.callbackId)
                    
                    UIApplication.shared.unregisterForRemoteNotifications()
                }
                else{

                    self.commandDelegate!.send(pluginResult, callbackId:command.callbackId)
                    return
                }

                //use category to handle objective-c exception
                let push = BMSPushClient.sharedInstance;

                push.initializeWithAppGUID(appGUID: appGUID, clientSecret: clientSecret);


                let pluginResult = CDVPluginResult(status: CDVCommandStatus_OK, messageAs: "")
                // call success callback
                self.commandDelegate!.send(pluginResult, callbackId:command.callbackId)
            }

        })

    }


    func registerNotificationsCallback(_ command: CDVInvokedUrlCommand) {
        CDVBMSPush.sharedInstance.notifCallbackId = command.callbackId
        CDVBMSPush.sharedInstance.notifCommandDelegate = self.commandDelegate
    }

    func registerDevice(_ command: CDVInvokedUrlCommand) {

        CDVBMSPush.sharedInstance.registerCallbackId = command.callbackId
        CDVBMSPush.sharedInstance.registerCommandDelegate = self.commandDelegate
       CDVBMSPush.sharedInstance.registerParams = command
        if ( CDVBMSPush.sharedInstance.shouldRegister == true &&  CDVBMSPush.sharedInstance.bmsPushToken.isEmpty == false){

            registerDeviceAfterTokenRecieve(command)
        }
    }
    func registerDeviceAfterTokenRecieve(_ command: CDVInvokedUrlCommand) {


        guard let settings = command.arguments[0] as? NSDictionary else {

            let message = "Registering for Push Notifications failed. Options parameter is Invalid."
            let pluginResult = CDVPluginResult(status: CDVCommandStatus_ERROR, messageAs: message)
            // call success callback
