Raygun provides crash reporting and error monitoring for iOS, tvOS & macOS. This provider is written in Objective-C and can be used with both Objective-C and Swift applications.
The provider officially supports:
- iOS 12+
- tvOS 12+
- macOS 12+
Note: raygun4apple may work with earlier OS versions, however we recommend updating to the versions we build and test for to avoid experiencing any unexpected issues.
Using the Swift Package Manager
To integrate Raygun into an SPM managed application, update your Package.swift file to include raygun4apple as a dependency.
Here is an example of a macOS CLI application which uses raygun4apple as a dependency:
import PackageDescription let package = Package( name: "macos-cli", dependencies: [ //Note - the version must be atleast 2.0.0 as this is earliest release of this package through SPM. .package(url: "https://github.com/MindscapeHQ/raygun4apple.git", from: "2.0.0"), ], targets: [ .executableTarget( name: "macos-cli", dependencies: ["raygun4apple"]) ] )
Configuring the Raygun client
The configuration step is slightly different if installed via the Swift package manager. Rather than importing the specific header for the target application, simply import
Here is an example which imports raygun4apple, and initializes the provider for Real User Monitoring.
import raygun4apple let raygunClient = RaygunClient.sharedInstance(apiKey: "YOUR_API_KEY_HERE") raygunClient.enableRealUserMonitoring()
To integrate Raygun using CocoaPods, update your
Podfile to include:
Once updated you can run
pod install from Terminal.
Using GitHub releases
The latest release can be found here. The frameworks are attached to each release as a zipped file. This can be downloaded, unzipped and included in you project directory.
Once included, go to your app's target General settings and add the raygun4apple framework to the Frameworks, Libraries, and Embedded Content section. Ensure that the framework is set to Embed & Sign.
note: The Raygun4Apple provider is developed as a “fat” library, which includes architectures for both simulators and devices. You will need to strip out the simulator architectures (x86_64, i386) before releasing. There is a helpful article on how to do this here.
Configuring the Raygun client
AppDelegate class file, import the header for your target platform.
note: For Swift projects you must create an Objective-C bridging header to be able to import the header for your target platform. You can find out how to do this by visiting Apple's documentation for more details.
Initialize the Raygun client by adding the following snippet to your
RaygunClient *raygunClient = [RaygunClient sharedInstanceWithApiKey:@"YOUR_APP_API_KEY"]; [raygunClient enableRealUserMonitoring]; [raygunClient enableNetworkPerformanceMonitoring]; // Optional
let raygunClient = RaygunClient.sharedInstance(apiKey: "YOUR_APP_API_KEY") raygunClient.enableRealUserMonitoring()
Your app API key is displayed when you create a new application in your Raygun account, or can be viewed in the application settings.
By default, each user will be identified with a unique guid and marked as anonymous. The identifier property on the RaygunUserInformation class is what separates one user from another. Be sure to set it with something unique, for example a database id, username or email address. If the user changes, for instance when logging in or out, be sure to update the user information on the shared Raygun client each time. You can assign user information as described below.
The string properties on a User have a maximum length of 255 characters. Users who have fields that exceed this amount will not be processed.
RaygunUserInformation *userInfo = [[RaygunUserInformation alloc] initWithIdentifier:@"firstname.lastname@example.org" withEmail:@"email@example.com" withFullName:@"Test User" withFirstName:@"Test"]; RaygunClient.sharedInstance.userInformation = userInfo;
let userInformation = RaygunUserInformation(identifier: "firstname.lastname@example.org", email: "email@example.com", fullName: "Test User", firstName: "Test") RaygunClient.sharedInstance().userInformation = userInformation