Skip to content
Open
Show file tree
Hide file tree
Changes from 13 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 55 additions & 7 deletions Backtrace.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

27 changes: 15 additions & 12 deletions Examples/Example-iOS-ObjC/AppDelegate.m
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,21 @@ @interface AppDelegate () <BacktraceClientDelegate>
@implementation AppDelegate

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {


/* Enable crash loop detector.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wouldn't be better if we describe the story what someone want to use it?

You can pass crashes count threshold (maximum amount of launching events to evaluate) here.
If threshold is not specified or you pass 0 - default value '5' will be used.
*/
[BacktraceClient enableCrashLoopDetection: 0];

if([BacktraceClient isSafeModeRequired]) {
// When crash loop is detected we need to reset crash loop counter to restart crash loop detection from scratch
[BacktraceClient resetCrashLoopDetection];
// TODO: Perform any custom checks if necessary and decide if Backtrace should be launched
return NO;
}

NSArray *paths = @[[[NSBundle mainBundle] pathForResource: @"test" ofType: @"txt"]];
NSString *fileName = @"myCustomFile.txt";
NSURL *libraryUrl = [[[NSFileManager defaultManager] URLsForDirectory:NSLibraryDirectory
Expand All @@ -32,18 +47,6 @@ - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(
BacktraceClient.shared.attributes = @{@"foo": @"bar", @"testing": @YES};
BacktraceClient.shared.attachments = [NSArray arrayWithObjects:fileUrl, nil];

// sending NSException
@try {
NSArray *array = @[];
array[1]; // will throw exception
} @catch (NSException *exception) {
[[BacktraceClient shared] sendWithAttachmentPaths: [NSArray init] completion: ^(BacktraceResult * _Nonnull result) {
NSLog(@"%@", result);
}];
} @finally {

}

//sending NSError
[[BacktraceClient shared] sendWithAttachmentPaths: paths completion: ^(BacktraceResult * _Nonnull result) {
NSLog(@"%@", result);
Expand Down
4 changes: 2 additions & 2 deletions Examples/Example-iOS-ObjC/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@
<key>CFBundlePackageType</key>
<string>APPL</string>
<key>CFBundleShortVersionString</key>
<string>$(MARKETING_VERSION)</string>
<string>1.0</string>
<key>CFBundleVersion</key>
<string>$(CURRENT_PROJECT_VERSION)</string>
<string>1.0</string>
<key>LSRequiresIPhoneOS</key>
<true/>
<key>UILaunchStoryboardName</key>
Expand Down
5 changes: 5 additions & 0 deletions Examples/Example-iOS-ObjC/ViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@ @implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
wastedMemory = [[NSMutableData alloc] init];

NSString * text = [NSString stringWithFormat: @"BadEvents: %ld\nIs Safe to Launch: %s",
[BacktraceClient consecutiveCrashesCount],
[BacktraceClient isInSafeMode] ? "FALSE" : "TRUE" ];
[_textView setText: text];
}

- (IBAction) outOfMemoryReportAction: (id) sender {
Expand Down
14 changes: 14 additions & 0 deletions Examples/Example-iOS/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,20 @@ final class AppDelegate: UIResponder, UIApplicationDelegate {

func application(_ application: UIApplication,
didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {

/* Enable crash loop detector.
You can pass crashes count threshold (maximum amount of launching events to evaluate) here.
If threshold is not specified or you pass 0 - default value '5' will be used.
*/
BacktraceClient.enableCrashLoopDetection()

if BacktraceClient.isSafeModeRequired() {
// When crash loop is detected we need to reset crash loop counter to restart crash loop detection from scratch
BacktraceClient.resetCrashLoopDetection()
// TODO: Perform any custom checks if necessary and decide if Backtrace should be launched
return true
}

let backtraceCredentials = BacktraceCredentials(endpoint: URL(string: Keys.backtraceUrl as String)!,
token: Keys.backtraceToken as String)

Expand Down
2 changes: 2 additions & 0 deletions Examples/Example-iOS/ViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ class ViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()

textView.text = "BadEvents: " + BacktraceClient.consecutiveCrashesCount().description
+ "\nIs Safe to Launch: " + (BacktraceClient.isInSafeMode() ? "FALSE" : "TRUE")
}

@IBAction func outOfMemoryReportAction(_ sender: Any) {
Expand Down
10 changes: 10 additions & 0 deletions Examples/Example-macOS-ObjC/AppDelegate.m
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,16 @@ @implementation AppDelegate

- (void)applicationDidFinishLaunching:(NSNotification *)aNotification {

// Enable crash loop detector, pass 0 to use default threshold value '5'
[BacktraceClient enableCrashLoopDetection: 0];

if([BacktraceClient isSafeModeRequired]) {
// When crash loop is detected we need to reset crash loop counter to restart crash loop detection from scratch
[BacktraceClient resetCrashLoopDetection];
// TODO: Perform any custom checks if necessary and decide if Backtrace should be launched
return;
}

BacktraceCredentials *credentials = [[BacktraceCredentials alloc]
initWithSubmissionUrl: [NSURL URLWithString: Keys.backtraceSubmissionUrl]];
BacktraceDatabaseSettings *backtraceDatabaseSettings = [[BacktraceDatabaseSettings alloc] init];
Expand Down
17 changes: 11 additions & 6 deletions Examples/Example-macOS-ObjC/Base.lproj/Main.storyboard
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<document type="com.apple.InterfaceBuilder3.Cocoa.Storyboard.XIB" version="3.0" toolsVersion="14460.31" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES" initialViewController="B8D-0N-5wS">
<document type="com.apple.InterfaceBuilder3.Cocoa.Storyboard.XIB" version="3.0" toolsVersion="20037" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES" initialViewController="B8D-0N-5wS">
<dependencies>
<plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="14460.31"/>
<deployment identifier="macosx"/>
<plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="20037"/>
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
</dependencies>
<scenes>
Expand Down Expand Up @@ -619,7 +620,7 @@
<menuItem title="Show Sidebar" keyEquivalent="s" id="kIP-vf-haE">
<modifierMask key="keyEquivalentModifierMask" control="YES" command="YES"/>
<connections>
<action selector="toggleSourceList:" target="Ady-hI-5gd" id="iwa-gc-5KM"/>
<action selector="toggleSidebar:" target="Ady-hI-5gd" id="iwa-gc-5KM"/>
</connections>
</menuItem>
<menuItem title="Enter Full Screen" keyEquivalent="f" id="4J7-dP-txa">
Expand Down Expand Up @@ -710,16 +711,16 @@
<autoresizingMask key="autoresizingMask"/>
<subviews>
<button verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="Snf-7p-7db">
<rect key="frame" x="4" y="3" width="472" height="61"/>
<rect key="frame" x="3" y="3" width="474" height="62"/>
<constraints>
<constraint firstAttribute="height" constant="50" id="wS4-BS-4BZ"/>
</constraints>
<buttonCell key="cell" type="push" title="Button" bezelStyle="rounded" alignment="center" borderStyle="border" imageScaling="proportionallyDown" inset="2" id="vpD-Xg-4cH">
<buttonCell key="cell" type="push" title="Crash Me" bezelStyle="rounded" alignment="center" borderStyle="border" imageScaling="proportionallyDown" inset="2" id="vpD-Xg-4cH">
<behavior key="behavior" pushIn="YES" lightByBackground="YES" lightByGray="YES"/>
<font key="font" metaFont="system"/>
</buttonCell>
<connections>
<action selector="liveReportButtonAction:" target="XfG-lQ-9wD" id="r4X-yE-pnP"/>
<action selector="crashAction:" target="XfG-lQ-9wD" id="OfJ-Ce-bpL"/>
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

shouldn't liveReportButton stay here?

</connections>
</button>
<scrollView borderType="none" horizontalLineScroll="10" horizontalPageScroll="10" verticalLineScroll="10" verticalPageScroll="10" hasHorizontalScroller="NO" translatesAutoresizingMaskIntoConstraints="NO" id="FmX-dS-tKd">
Expand All @@ -739,6 +740,10 @@
</textView>
</subviews>
</clipView>
<scroller key="horizontalScroller" hidden="YES" wantsLayer="YES" verticalHuggingPriority="750" horizontal="YES" id="KrE-Pr-E3e">
<rect key="frame" x="-100" y="-100" width="460" height="16"/>
<autoresizingMask key="autoresizingMask"/>
</scroller>
<scroller key="verticalScroller" wantsLayer="YES" verticalHuggingPriority="750" horizontal="NO" id="7RO-Uj-aNq">
<rect key="frame" x="444" y="0.0" width="16" height="190"/>
<autoresizingMask key="autoresizingMask"/>
Expand Down
28 changes: 19 additions & 9 deletions Examples/Example-macOS-ObjC/ViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -9,30 +9,40 @@ @interface ViewController()

@implementation ViewController

- (void)viewDidLoad {
- (void) viewDidLoad {
[super viewDidLoad];

SEL selector = NSSelectorFromString(@"updateUI");
[self performSelector: selector withObject: nil afterDelay: 0.5];

// Do any additional setup after loading the view.
}
- (IBAction)crashAction:(id)sender {
NSArray *array = @[];
(void)array[1];

- (void) updateUI {
NSString * text = [NSString stringWithFormat: @"BadEvents: %ld\nIs Safe to Launch: %@",
[BacktraceClient consecutiveCrashesCount],
[BacktraceClient isInSafeMode] ? @"FALSE" : @"TRUE" ];
NSLog(@"updateUI: text = %@", text);
[_textView setString: text];
}

- (IBAction)liveReportAction:(id)sender {
- (IBAction) crashAction:(id)sender {
// NOTE: crashing with array out of bounds case doesn't terminate app on some OS versions, so using runtime crash to be sure signal is received.
NSString * string = [NSString stringWithFormat: @"%@", 12];
}

- (IBAction) liveReportAction:(id)sender {

}

- (IBAction)liveReportButtonAction:(id)sender {
- (IBAction) liveReportButtonAction:(id)sender {
NSArray *array = @[];
(void)array[1];
}

- (void)setRepresentedObject:(id)representedObject {
- (void) setRepresentedObject:(id)representedObject {
[super setRepresentedObject:representedObject];

// Update the view, if already loaded.
}


@end
14 changes: 14 additions & 0 deletions Examples/Example-tvOS/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,20 @@ class AppDelegate: UIResponder, UIApplicationDelegate {

func application(_ application: UIApplication,
didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {

/* Enable crash loop detector.
You can pass crashes count threshold (maximum amount of launching events to evaluate) here.
If threshold is not specified or you pass 0 - default value '5' will be used.
*/
BacktraceClient.enableCrashLoopDetection()

if BacktraceClient.isSafeModeRequired() {
// When crash loop is detected we need to reset crash loop counter to restart crash loop detection from scratch
BacktraceClient.resetCrashLoopDetection()
// TODO: Perform any custom checks if necessary and decide if Backtrace should be launched
return true
}

let backtraceCredentials = BacktraceCredentials(endpoint: URL(string: Keys.backtraceUrl as String)!,
token: Keys.backtraceToken as String)
let backtraceDatabaseSettings = BacktraceDatabaseSettings()
Expand Down
Loading