Unsubscribe all subscriptions on logout #Quickblox APNS & APNS.VOIP

196 views Asked by At

I am trying to Unsubscribe subscriptions APNS & APNS.VOIP on logout in iOS swift Quickblox project. It unsubscribes only one of them can anyone please guide me.

Here's my code for logout.

@objc func didTapLogout(_ sender: UIBarButtonItem) {
        if QBChat.instance.isConnected == false {
            SVProgressHUD.showError(withStatus: "Error")
            return
        }
        SVProgressHUD.show(withStatus: "SA_STR_LOGOUTING".localized)
        SVProgressHUD.setDefaultMaskType(.clear)
        
        guard let identifierForVendor = UIDevice.current.identifierForVendor else {
            return
        }
        let uuidString = identifierForVendor.uuidString
        #if targetEnvironment(simulator)
        disconnectUser()
        #else
        QBRequest.subscriptions(successBlock: { (response, subscriptions) in
            if let subscriptions = subscriptions {
                for subscription in subscriptions {
                    if let subscriptionsUIUD = subscriptions.first?.deviceUDID,
                        subscriptionsUIUD == uuidString,
                        subscription.notificationChannel == .APNS {
                        self.unregisterSubscription(forUniqueDeviceIdentifier: uuidString)
                        return
                    }
                }
            }
            self.disconnectUser()
            
        }) { response in
            if response.status.rawValue == 404 {
                self.disconnectUser()
            }
        }
        #endif
    }
    
    private func unregisterSubscription(forUniqueDeviceIdentifier uuidString: String) {
        QBRequest.unregisterSubscription(forUniqueDeviceIdentifier: uuidString, successBlock: { response in
            self.disconnectUser()
        }, errorBlock: { error in
            if let error = error.error {
                SVProgressHUD.showError(withStatus: error.localizedDescription)
                return
            }
            SVProgressHUD.dismiss()
        })
    }

Environment details

  • Info Value
  • iOS Version 13.0
  • Quickblox iOS SDK version 2.17.4
  • QuickbloxWebRTC SDK version 2.7.4
  • Xcode Version e.g. Xcode 12.0
1

There are 1 answers

0
Victor Morei On

Make sure you are connected to chat when removing subscriptions and logout only when all unsubscribe completions are called. You can also simply unsubscribe from remote notifications and PushKit in the app.