Destroying a push channel

Our sample application destroys the push channel to the PPG to stop receiving push messages.

If you chose to subscribe with the Push Service SDK when you configured our application, the Push Initiator requires a username and password that it authenticates before unsubscribing. Our sample application provides an Unregister dialog box where the user can type any username and password. For your application, check with your push content provider to get a valid username and password.

You can open the Unregister dialog box by tapping Unregister at the bottom of the device screen. The Unregister dialog box appears.

Unregister dialog box where you type a username and password.

After you type the username and password, and tap Unregister in the dialog box, our sample application tries to destroy the channel.

If you're not subscribing with the Push Service SDK, you don't need to provide a username and password. You can tap Unregister at the bottom of the device screen, and our sample application tries to destroy the channel.

Connect a slot to the destroyChannelCompleted () signal

Since the call to destroy a channel is asynchronous, our sample application connects a slot to the destroyChannelCompleted() signal.

AppHeadless::AppHeadless()
{
// ...
checkConnectResult(QObject::connect(m_pushNotificationService, 
  SIGNAL(destroyChannelCompleted(const bb::network::PushStatus&)),
  this, SLOT(onDestroyChannelCompleted(const 
  bb::network::PushStatus&))));
// ...
}

Call destroyChannel()

Our sample application calls destroyChannel() from the PushNotificationService object to destroy a channel.

void PushNotificationService::destroyChannel()   
{
  m_pushService->destroyChannel();   
}

Call unsubscribeFromPushInitiator()

If the destroy channel is successful, our sample application calls unsubscribeFromPushInitiator() from the PushNotificationService object to unsubscribe from the Push Initiator, and passes off the call to the UnregisterService object. The parameter list includes the username and password that you typed in the Unregister dialog box. If you're not subscribing with the Push Service SDK, our sample application doesn't call unsubscribeFromPushInitiator().

void PushNotificationService::unsubscribeFromPushInitiator(const 
     User &user)
{
  m_unregisterService.unsubscribeFromPushInitiator(user);
}

Handle the unsubscribe operation from the Push Initiator

The UnregisterService object handles the unsubscribe operation from the Push Initiator.

void UnregisterService::unsubscribeFromPushInitiator(const 
   User& user)
{
   // Keep track of the current user's information.
   // If it matches the one stored then it will be removed on success. 
   m_currentUser = user;
 
   const Configuration config = m_configurationService.configuration();
 
   QUrl url(config.pushInitiatorUrl() + "/unsubscribe");
   url.addQueryItem("appid",config.providerApplicationId());
   url.addQueryItem("username",user.userId());
   url.addQueryItem("password",user.password());
     
   m_reply = m_accessManager.get(QNetworkRequest(url));
 
   // Connect to the reply finished signal.
    
   checkConnectResult(connect(m_reply, SIGNAL(finished()), this, 
     SLOT(httpFinished())));
}

Last modified: 2013-12-21

comments powered by Disqus