Commit 14e811d6 authored by Nadya Atanasova's avatar Nadya Atanasova Committed by EddyVerbruggen
Browse files

Add unregister channel

If user want to open new channel they have to have the option to close the current one.
Update the error text.
Remove the channel field as it is not necessary.
parent 2071e52a
Loading
Loading
Loading
Loading
+26 −4
Changes for src/wp8/PushPlugin.cs: 26 added lines, 4 removed lines.
Original line number Diff line number Diff line
@@ -11,10 +11,9 @@ namespace WPCordovaClassLib.Cordova.Commands
{
    public class PushPlugin : BaseCommand
    {
        private const string InvalidRegistrationError = "Unable to open a channel with the specified name. The most probable cause is that you have already registered a channel with a different name.";

        private const string InvalidRegistrationError = "Unable to open a channel with the specified name. The most probable cause is that you have already registered a channel with a different name. Call unregister(old-channel-name) or uninstall and redeploy your application.";
        private const string MissingChannelError = "Couldn't find a channel with the specified name.";
        private Options pushOptions;
        private HttpNotificationChannel pushChannel;

        public void register(string options)
        {
@@ -24,7 +23,7 @@ namespace WPCordovaClassLib.Cordova.Commands
                return;
            }

            pushChannel = HttpNotificationChannel.Find(this.pushOptions.ChannelName);
            var pushChannel = HttpNotificationChannel.Find(this.pushOptions.ChannelName);
            if (pushChannel == null)
            {
                pushChannel = new HttpNotificationChannel(this.pushOptions.ChannelName);
@@ -52,6 +51,29 @@ namespace WPCordovaClassLib.Cordova.Commands
            this.DispatchCommandResult(new PluginResult(PluginResult.Status.OK, result));
        }

        public void unregister(string options)
        {
            Options unregisterOptions;
            if (!TryDeserializeOptions(options, out unregisterOptions))
            {
                this.DispatchCommandResult(new PluginResult(PluginResult.Status.JSON_EXCEPTION));
                return;
            }
            var pushChannel = HttpNotificationChannel.Find(unregisterOptions.ChannelName);
            if (pushChannel != null)
            {
                pushChannel.UnbindToShellTile();
                pushChannel.UnbindToShellToast();
                pushChannel.Close();
                pushChannel.Dispose();
                this.DispatchCommandResult(new PluginResult(PluginResult.Status.OK, "Channel " + unregisterOptions.ChannelName + " is closed!"));
            }
            else
            {
                this.DispatchCommandResult(new PluginResult(PluginResult.Status.ERROR, MissingChannelError));
            }
        }

        void PushChannel_ChannelUriUpdated(object sender, NotificationChannelUriEventArgs e)
        {
            // return uri to js
+2 −4
Changes for www/PushNotification.js: 2 added lines, 4 removed lines.
Original line number Diff line number Diff line
@@ -20,7 +20,7 @@ PushNotification.prototype.register = function(successCallback, errorCallback, o
};

// Call this to unregister for push notifications
PushNotification.prototype.unregister = function(successCallback, errorCallback) {
PushNotification.prototype.unregister = function(successCallback, errorCallback, options) {
    if (errorCallback == null) { errorCallback = function() {}}

    if (typeof errorCallback != "function")  {
@@ -33,10 +33,8 @@ PushNotification.prototype.unregister = function(successCallback, errorCallback)
        return
    }

     cordova.exec(successCallback, errorCallback, "PushPlugin", "unregister", []);
     cordova.exec(successCallback, errorCallback, "PushPlugin", "unregister", [options]);
};
 
 
// Call this to set the application icon badge
PushNotification.prototype.setApplicationIconBadgeNumber = function(successCallback, errorCallback, badge) {
    if (errorCallback == null) { errorCallback = function() {}}