I use the Branch SDK for deep links to the iOS application. The problem appears in the following cases if you send a deep link to a third-party application (for example, Slack, Facebook) quickly, then an app crash occurs. The console shows the following result [core] SLComposeViewController dealloc <SLComposeViewController: 0x11fbf03a0>.
How can I fix it?
My code
func shareCardDetail(_ cardModel: CardModel) {
let shareText = "What do you think about this?"
let branchUniversalObject = BranchUniversalObject(canonicalIdentifier: ("cardId/\(cardModel.id)"))
branchUniversalObject.title = cardModel.title
branchUniversalObject.contentDescription = ""
branchUniversalObject.imageUrl = cardModel.photoURLsProperties.placeVenuePhoto
branchUniversalObject.addMetadataKey(CardKeys.cardID.rawValue, value: cardModel.id)
if let placeAvatarURLString = cardModel.photoURLsProperties.placeVenuePhoto {
branchUniversalObject.addMetadataKey("placeAvatarURLString", value: placeAvatarURLString)
}
branchUniversalObject.addMetadataKey("title", value: cardModel.title)
branchUniversalObject.addMetadataKey("isAutoGeneratedCard", value: "false")
let fullLocationName = cardModel.location.fullLocationName
branchUniversalObject.addMetadataKey("fullLocationName", value: fullLocationName)
branchUniversalObject.addMetadataKey(CardKeys.ownerID.rawValue, value: cardModel.ownerID)
branchUniversalObject.addMetadataKey(ParametersKeywords.type.rawValue, value: ModeKeywords.shareCard.rawValue)
branchUniversalObject.addMetadataKey("availableSeats", value: cardModel.peopleProperties.availableSeats.description)
if let coordinate = cardModel.location.coordinate {
branchUniversalObject.addMetadataKey("latitude", value: coordinate.latitude.description)
branchUniversalObject.addMetadataKey("longitude",value: coordinate.longitude.description)
}
let linkProperties = BranchLinkProperties()
linkProperties.feature = "sharing"
linkProperties.addControlParam("$desktop_url", withValue: "http://www.example.com")
linkProperties.addControlParam("$ios_url", withValue: "example://")
guard let topViewController = UIApplication.topViewController() else { return }
branchUniversalObject.showShareSheet(with: linkProperties, andShareText: shareText, from: topViewController) { (text, success) in
debugPrint("done showing share sheet!")
}
}
I changed my code and it works.
func shareCardDetail(_ cardModel: CardModel) {
let shareText = "What do you think about this?"
let branchUniversalObject = BranchUniversalObject(canonicalIdentifier: ("cardId/\(cardModel.id)"))
branchUniversalObject.title = cardModel.title
branchUniversalObject.contentDescription = ""
branchUniversalObject.imageUrl = cardModel.photoURLsProperties.placeVenuePhoto
branchUniversalObject.addMetadataKey(CardKeys.cardID.rawValue, value: cardModel.id)
if let placeAvatarURLString = cardModel.photoURLsProperties.placeVenuePhoto {
branchUniversalObject.addMetadataKey("placeAvatarURLString", value: placeAvatarURLString)
}
branchUniversalObject.addMetadataKey("title", value: cardModel.title)
branchUniversalObject.addMetadataKey("isAutoGeneratedCard", value: "false")
let fullLocationName = cardModel.location.fullLocationName
branchUniversalObject.addMetadataKey("fullLocationName", value: fullLocationName)
branchUniversalObject.addMetadataKey(CardKeys.ownerID.rawValue, value: cardModel.ownerID)
branchUniversalObject.addMetadataKey(ParametersKeywords.type.rawValue, value: ModeKeywords.shareCard.rawValue)
branchUniversalObject.addMetadataKey("availableSeats", value: cardModel.peopleProperties.availableSeats.description)
if let coordinate = cardModel.location.coordinate {
branchUniversalObject.addMetadataKey("latitude", value: coordinate.latitude.description)
branchUniversalObject.addMetadataKey("longitude",value: coordinate.longitude.description)
}
let linkProperties = BranchLinkProperties()
linkProperties.feature = "sharing"
linkProperties.addControlParam("$desktop_url", withValue: "http://www.example.com")
linkProperties.addControlParam("$ios_url", withValue: "example://")
guard let topViewController = UIApplication.topViewController() else { return }
guard let branchShareLink = BranchShareLink(universalObject: branchUniversalObject, linkProperties: linkProperties) else { return }
branchShareLink.shareText = shareText
branchShareLink.presentActivityViewController(from: topViewController, anchor: nil)
}