Adding custom data
User email
When you already have your users identified within your app, you might want to add their email automatically attached to the bug report. Bugsee provides APIs for setting, getting and clearing the email.
!Objective-C
// setting email
[Bugsee setEmail:@"name@example.com"]
// getting email, nil will be returned if email was never set
NSString *email = [Bugsee getEmail];
// clearing email
[Bugsee clearEmail];
!Swift
// setting email
Bugsee.setEmail("name@example.com")
// getting email, nil will be returned if email was never set
var email = Bugsee.getEmail()
// clearing email
Bugsee.clearEmail()
Session/User Attributes
Besides email, any arbitrary attributes can be attached to the report as well. Issues are searchable by these attributes in the Bugsee dashboard as well.
!Objective-C
[Bugsee setAttribute:@"name" withValue:@"John Doe"];
[Bugsee setAttribute:@"age" withValue:@23];
[Bugsee setAttribute:@"married" withValue:@YES];
!Swift
Bugsee.setAttribute("name", value: "John Doe")
Bugsee.setAttribute("age", value: 23)
Bugsee.setAttribute("married", value: false)
Once set, attributes persist until the application is uninstalled from the device. They can be cleared however using the following API.
!Objective-C
// Clear a single attribute by name
[Bugsee clearAttribute:@"name"];
// .. or clear all of them
[Bugsee clearAllAttributes];
!Swift
// Clear a single attribute by name
Bugsee.clearAttribute("name")
// .. or clear all of them
Bugsee.clearAllAttributes()
Custom Traces
Traces may be useful when you want to trace how a specific variable or state changes over time right before the problem happens.
There are two ways available to trace a property, manually setting a value or automatically setting an observer on a property of an object.
!Objective-C
// Manually set value of @15 to property named "credit_balance"
// any time it changes
[Bugsee traceKey:@"credit_balance" withValue:@15];
!Swift
// Manually set value of @15 to property named "credit_balance"
// any time it changes
Bugsee.trace(key:"credit_balance", value:15)
Custom Events
Events are identified by a string and can have an optional dictionary of parameters that will be stored and passed along with the report.
!Objective-C
// Without any additional parameters
[Bugsee registerEvent:@"payment_processed"];
// ...or with additional custom parameters
[Bugsee registerEvent:@"payment_processed"
withParams:@{
@"amount": @125,
@"currency": @"USD"
}];
!Swift
// Without any additional parameters
Bugsee.event("payment_processed")
// ...our with additional custom parameters
Bugsee.event("payment_processed", params:["amount": 125, "currency": "USD"])
File Attachments
Binary files (attachments) can also be added to the report right before it is being sent. The attachment will be available for download right from the issue viewer. Currently both the amount of attachments and their size is limited. Max of 3 attachments, 3MB each (size increased from 1MB starting from v3.4.0).
Your class should implement BugseeDelegate protocol and it must set itself as the delegate for Bugsee.
Note, that in Swift, when inheriting from BugseeDelegate
protocol, you should also add the NSObject
as a base class. This will let you avoid,
implementing the responds(to: aSelector)
method and many others.
!Objective-C
-(NSArray<BugseeAttachment *> *)bugseeAttachmentsForReport:(BugseeReport *)report
{
// Only if it's a blocker and on every crash
if ((report.severity == BugseeSeverityBlocker) ||
([report.type isEqualToString:BugseeReportTypeCrash])) {
BugseeAttachment * att = [BugseeAttachment attachmentWithName:@"internal app db" filename:@"custom.db" data:[NSData dataWithContentsOfFile:pathToMyFile]];
// Return array with one attachment
return @[att];
}
return @[];
}
// ..somewhere within the class
[Bugsee sharedInstance].delegate = self;
!Swift
// Note the NSObject as a base class. This will let you avoid,
// implementing the responds(to: aSelector) method and many others.
public class BugseeCustomDelegate: NSObject, BugseeDelegate {
// .. other methods
func bugseeAttachments(for report: BugseeReport) -> [BugseeAttachment] {
// Only if it's a blocker and on every crash
if (report.severity == BugseeSeverityBlocker ||
report.type == BugseeReportTypeCrash) {
if let att = BugseeAttachment(name:"internal app db", filename:"custom.db", data:Data(contentsOf: URL(string: pathToMyFile)!)) {
// Return array with one attachment
return [att]
}
}
return []
}
// ..somewhere within the class
func initBugseeDelegate() {
Bugsee.sharedInstance()?.delegate = self;
}
}
In cases when you need to perform some asynchronous operation to gather attachments information, you can use the async variant instead:
!Objective-C
- (void) bugseeAttachmentsForReport:(nonnull BugseeReport *)report completionHandler:(nonnull BugseeAttachmentsDecisionBlock)decisionBlock
{
// Do some async stuff...
NSMutableArray<BugseeAttachment*>* attachments = ...
// Decision block can receive nil as argument.
decisionBlock(attachments);
}
!Swift
func bugseeAttachments(for report: BugseeReport, completionHandler decisionBlock: @escaping BugseeAttachmentsDecisionBlock) {
let attachments = ...
decisionBlock(attachments)
}
View hierarchy
By default, Bugsee automatically captures view hierarchy upon bug or error report generation. This feature is controlled by the BugseeViewHierarchyEnabledKey
launch option (Refer to configuration section for more details on launch options).
You can also trigger view hierarchy capture manually using the following API:
!Objective-C
[Bugsee captureViewHierarchy];
!Swift
Bugsee.captureViewHierarchy()
This API can be called multiple times and all the captured view hierarchies will be attached to the next report. Be aware, that depending on the depth of your view hierarchy and the number of snapshots, the resulting size of the report bundle may be significantly increased.
Also note, that if BugseeViewHierarchyEnabledKey
launch option is set to false
, this API will have no effect.