Created
March 15, 2018 13:28
-
-
Save alexruperez/7882fbeea6c3b0a2f1c27b5cefdc44f1 to your computer and use it in GitHub Desktop.
BranchUniversalObject subclass with BranchActivityItemProviderDelegate custom or default implementation.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Branch | |
public protocol BranchActivityObjectDelegate: BranchActivityItemProviderDelegate {} | |
public class BranchActivityObject: BranchUniversalObject { | |
private weak var delegate: BranchActivityObjectDelegate? | |
private var params: [AnyHashable : Any]! | |
private var linkProperties: BranchLinkProperties! | |
public init(delegate: BranchActivityObjectDelegate? = nil) { | |
super.init() | |
self.delegate = delegate | |
} | |
public init(title: String, delegate: BranchActivityObjectDelegate? = nil) { | |
super.init(title: title) | |
self.delegate = delegate | |
} | |
public init(canonicalIdentifier: String, delegate: BranchActivityObjectDelegate? = nil) { | |
super.init(canonicalIdentifier: canonicalIdentifier) | |
self.delegate = delegate | |
} | |
public override func getBranchActivityItem(with linkProperties: BranchLinkProperties) -> UIActivityItemProvider? { | |
params = getParamsForServerRequest(withAddedLinkProperties: linkProperties) | |
if linkProperties.matchDuration > 0 { | |
params[BRANCH_REQUEST_KEY_URL_DURATION] = linkProperties.matchDuration | |
} | |
if let campaign = linkProperties.campaign, !campaign.isEmpty { | |
params[BRANCH_REQUEST_KEY_URL_CAMPAIGN] = linkProperties.campaign | |
} | |
self.linkProperties = linkProperties | |
return Branch.getActivityItem(withParams: params, feature: linkProperties.feature, stage: linkProperties.stage, tags: linkProperties.tags, alias: linkProperties.alias, delegate: self) | |
} | |
} | |
extension BranchActivityObject: BranchActivityObjectDelegate { | |
public func activityItemParams(forChannel channel: String) -> [AnyHashable : Any] { | |
return delegate?.activityItemParams?(forChannel: channel) ?? params | |
} | |
public func activityItemTags(forChannel channel: String) -> [Any] { | |
return delegate?.activityItemTags?(forChannel: channel) ?? linkProperties.tags | |
} | |
public func activityItemFeature(forChannel channel: String) -> String { | |
return delegate?.activityItemFeature?(forChannel: channel) ?? linkProperties.feature | |
} | |
public func activityItemStage(forChannel channel: String) -> String { | |
return delegate?.activityItemStage?(forChannel: channel) ?? linkProperties.stage | |
} | |
public func activityItemCampaign(forChannel channel: String) -> String { | |
return delegate?.activityItemCampaign?(forChannel: channel) ?? linkProperties.campaign | |
} | |
public func activityItemAlias(forChannel channel: String) -> String { | |
return delegate?.activityItemAlias?(forChannel: channel) ?? linkProperties.alias | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment