ibm-bluemix-mobile-services/bms-clientsdk-swift-push

Crash in BMSPushClient.swift:726

Closed this issue · 4 comments

We've also picked this one up as well.

Any help much appreciated.
Thanks
Scott

Using BMSAnalyticsAPI (2.2.0)
Using BMSCore (2.3.1)
Using BMSPush (3.1.1)

BMSPush-Crash-2.txt

We think the problem is because we are calling:

  • get tags
  • unsubscribe
  • subscribe

and they are happening async

So, we just put a dispatch queue around and made them serialised.

We'll see how it goes.

Here's the code:

`//Initialize client Push SDK for Swift
let push = BMSPushClient.sharedInstance
push.initializeWithAppGUID(appGUID: weatherGodsBluemixAppGUID, clientSecret: weatherGodsBluemixClientSecret)

    log.info("Subscribing with tag: \(tag)")
    let tags = [tag]
    var orphanedTags = [String]()
    let group = DispatchGroup()
    group.enter()
    BMSPushClient.sharedInstance.retrieveSubscriptionsWithCompletionHandler { (availableTagsArray, statusCode, error) in
        if error.isEmpty {
            log.info( "Response during retrieve subscriptions : \(String(describing: availableTagsArray?.description))")
            log.info( "status code during retrieve subscriptions : \(String(describing: statusCode))")
            if let tagsToCheck = availableTagsArray?.copy() as? [String] {
                for tagToCheck in tagsToCheck {
                    if tagToCheck.hasPrefix("weather-gods-heartbeat") && tagToCheck != tag {
                        log.debug("Will unsubscribe from \(tagToCheck)")
                        orphanedTags.append(tagToCheck)
                    }
                }
                if orphanedTags.count > 0 {
                    BMSPushClient.sharedInstance.unsubscribeFromTags(tagsArray: orphanedTags as NSArray, completionHandler: { (response, statusCode, error) in
                        if error.isEmpty {
                            log.info( "Response during unsubscribing from tags : \(String(describing: response?.description))")
                            log.info( "status code during unsubscribing from tags : \(String(describing: statusCode))")
                        } else {
                            log.error( "Error during unsubscribing from tags \(error) ")
                            log.error( "Error during unsubscribing from tags \n  - status code: \(String(describing: statusCode)) \n Error :\(error) \n")
                        }
                        group.leave()
                    })
                } else {
                    group.leave()
                }
            }
        } else {
            log.error( "Error during retrieve subscriptions \(error) ")
            log.error( "Error during retrieve subscriptions \n  - status code: \(String(describing: statusCode)) \n Error :\(error) \n")
            group.leave()
        }
    }
    
    group.wait()
    BMSPushClient.sharedInstance.subscribeToTags(tagsArray: tags as NSArray) { (response, statusCode, error) in
        if error.isEmpty {
            log.info( "Response during Subscribing to tags : \(String(describing: response?.description))")
            log.info( "status code during Subscribing tags : \(String(describing: statusCode))")
        } else {
            log.error( "Error during Subscribing tags \(error) ")
            log.error( "Error during Subscribing tags \n  - status code: \(String(describing: statusCode)) \n Error :\(error) \n")
        }
    }

`

@meyumeapps Hi, Fix will be available in next release :)

Issue is solved , hence closing the defect