Windows phone 8 notification hub unregister

466 Views Asked by At

Can someone show me or tell some example how to unregister from notification hub in windows phone 8. I tried on this way but it doesn't work.

public void registerForNotifications(string[] tags)
    {
        var channel = HttpNotificationChannel.Find("xxx");
        if (channel == null)
        {
            channel = new HttpNotificationChannel("xxx");
            channel.Open();
            channel.BindToShellToast();
        }

        string[] tagsToSubscribeTo = tags;


        channel.ChannelUriUpdated += new EventHandler<NotificationChannelUriEventArgs>(async (o, args) =>
        {
            var hub = new NotificationHub("xxx", "xxx");
            await hub.RegisterNativeAsync(args.ChannelUri.ToString(), tagsToSubscribeTo);
         });

    }

public async void unregisterFromNotifications()
    {

        var channel = HttpNotificationChannel.Find("xxx");
        var hub = new NotificationHub("xxx", "xxx");
        await hub.UnregisterAllAsync(channel.ChannelUri.ToString());
    }
1

There are 1 best solutions below

0
On

You didn't say what "it didn't work" means. Did you get an error message? Did it report success but actually fail? In your questions, it really helps more if you share those things. But I'll take a stab at this anyway.

I suspect that you might be using the DefaultListenSharedAccessSignature endpoint from your Windows Phone 8 app.

According to http://msdn.microsoft.com/en-us/library/dn495373.aspx, the Listen access level grants permission to:

  • Create/Update registration.

  • Read registration.

  • Read all registrations for a handle.

  • Delete registration.

Reading that last one, I wonder if the UnregisterAllAsync method might require a higher access level to delete all registrations, rather than just one.

But rather than use the DefaultFullSharedAccessSignature endpoint, I would rather just try the UnregisterAsync method instead of UnregisterAllAsync.

Disclaimer: I have not tried this out. It may not help at all.