Skip to main content

Swift Package Manager

Learn how to add Shake to your iOS app using Swift Package Manager.

Install the Shake Package

Select File โ†’ Swift Packages โ†’ Add Package Dependency. Enter the Shake repository URL when prompted:

https://github.com/shakebugs/shake-ios

Choose the appropriate cloning details and optionally specify the exact Shake version or branch.

Click Finish to add Shake to your project.

Initialize Shake SDK

Initialize Shake in the didFinishLaunchingWithOptions callback of your AppDelegate. Replace your-api-client-id and your-api-client-secret with the actual values you have in your workspace settings:

AppDelegate.swift
import UIKit
import Shake
@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {
func application(
_ application: UIApplication,
didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
Shake.start(clientId: "your-api-client-id", clientSecret: "your-api-client-secret")
return true
}
}
note

Some of the Shake features use swizzling. To avoid swizzling conflicts, call Shake.start() before initializing other frameworks.

Now select Product โ†’ Run in the menu bar. This first run will automatically add your app to your Shake Dashboard based on your app bundle ID.

A know issue and a temporary workaround

note

Shake is distributed as a binary framework. There is a known issue with SPM signing the binary packages which will pop up when running your app on the real device. The issue has been fixed in the Xcode Version 12.2 beta 3.

Select your app target, and add a new Copy Files phase to the Build Phases. Make sure to change the destination to Frameworks folder.

Add a new Run Script phase and paste the following script to force the deep signing of frameworks with your own identity:

find "${CODESIGNING_FOLDER_PATH}" -name '*.framework' -print0 | while read -d $'\0' framework
do
codesign --force --deep --sign "${EXPANDED_CODE_SIGN_IDENTITY}" --preserve-metadata=identifier,entitlements --timestamp=none "${framework}"
done

Conditional initialization

We recommend initializing Shake in the entry point of your app. However, depending on your app, you'll want to initialize Shake just in a specific conditions, depending on your app data. You can do it as shown in the example below when your app data is available:

Main.swift
import UIKit
import Shake
class MainVC: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
title = "Main"
if User.isTester() {
Shake.start(clientId: "_client_id_", clientSecret: "_client_secret_")
}
}
}

Visit your Shake dashboard

Follow the instructions there to send your first feedback with Shake and you're all set.

SDK customizations

Now that Shake SDK is in your app and you have sent the first feedback for fun, everything else is optional. As the next step, try the three most popular SDK customizations: