Introduction
Welcome to the documentation for the Branch SDK for macOS! Here, you will find everything you need to integrate Branch’s powerful deep linking and attribution features into your macOS applications.
Installation
Follow the steps below to install the Branch SDK in your macOS application:
- Open your project in Xcode.
- In the project navigator, right-click on the group or folder where you want to add the Branch SDK.
- Select “Add Files to [Your Project Name]”.
- Navigate to the directory where you downloaded the Branch SDK.
- Select the “Branch.framework” file and click “Add”.
- In the dialog that appears, make sure “Copy items if needed” is selected and click “Finish”.
Getting Started
To start using the Branch SDK in your macOS application, follow the steps below:
- Import the Branch module by adding the following import statement at the top of your Swift file:
- Initialize the Branch session by adding the following code to your app’s entry point, such as the AppDelegate:
- Start using the Branch SDK in your application to take advantage of deep linking and attribution features.
// Import the Branch module
import Branch
func applicationDidFinishLaunching(_ aNotification: Notification) {
// Initialize Branch
Branch.getInstance().initSession(launchOptions: nil) { [weak self] (params, error) in
// Handle the initialization response
if let error = error {
print("Branch initialization failed with error: \(error.localizedDescription)")
} else {
print("Branch initialized successfully!")
}
}
}
Branch Methods
The Branch SDK provides various methods to handle deep linking and attribution. Here are some important methods:
setIdentity
Sets the identity of a user. This can be used for tracking referrals and handling user-specific deep links.
Parameters:
userId
(String): The unique identifier of the user. Example: “12345”
// Set user identity
Branch.getInstance().setIdentity("12345") { (params, error) in
// Handle the set identity response
if let error = error {
print("Identity set failed with error: \(error.localizedDescription)")
} else {
print("Identity set successfully!")
}
}
getFirstReferringParams
Returns the deep link parameters associated with the first referrer for the user.
// Get first referring parameters
if let params = Branch.getInstance().getFirstReferringParams() {
// Handle the first referring parameters
print("First referring parameters: \(params)")
}
handleUniversalLink
Handles the deep link when the app is launched through a Universal Link.
Parameters:
link
(URL): The URL of the deep link.
// Handle deep link from Universal Link
func application(_ application: NSApplication, continue userActivity: NSUserActivity, restorationHandler: @escaping ([NSUserActivityRestoring]) -> Void) -> Bool {
if let url = userActivity.webpageURL {
Branch.getInstance().handleUniversalLink(url)
}
return true
}
Troubleshooting
If you are facing any issues or have any questions regarding the Branch SDK for macOS, consult the troubleshooting guide at: https://yourtroubleshootingguide.com.
Conclusion
Congratulations! You have successfully integrated the Branch SDK for macOS into your application. Now you can leverage the power of deep linking and attribution to improve user experience and grow your business.