Skip to content

Commit

Permalink
Remove dependency on crashlytics (#11)
Browse files Browse the repository at this point in the history
  • Loading branch information
Jesse Crocker authored Oct 22, 2020
1 parent 928f361 commit 1475d00
Show file tree
Hide file tree
Showing 18 changed files with 94 additions and 138 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,4 @@ DerivedData
Podfile.lock
Pods/*
demo/pods/*
TBOOMDetector.xcodeproj/project.xcworkspace
13 changes: 13 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v3.3.0
hooks:
- id: end-of-file-fixer
- id: check-yaml
- id: check-merge-conflict
- id: no-commit-to-branch
args: [--branch, master]
- repo: https://github.com/doublify/pre-commit-clang-format
sha: 62302476d0da01515660132d76902359bed0f782
hooks:
- id: clang-format
12 changes: 12 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# Changelog
All notable changes to this project will be documented in this file.

The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [1.0.0] - 2020-10-22
### Changed
- Dependency on crashlytics has been removed, and TBOOMDetector must now be passed a block that will be called to determine if the last session crashed.
- Minimum iOS version has changed to 10.0.
- Code is now formatted with Clang Format using pre-commit hooks.
- Removed cocoapods from demo app.
1 change: 0 additions & 1 deletion LICENSE
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,3 @@ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

13 changes: 7 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,21 +1,22 @@
# TBOOMDetector

Detect Out Of Memory events in an iOS app by process of elimination. If we can't figure out why the app is relaunching, it must have been the OOM Killer. For a complete explanation read [this excellent blog post from Facebook](https://code.facebook.com/posts/1146930688654547/reducing-fooms-in-the-facebook-ios-app/).

Requires crashlytics for detecting crashes.

Example:

```objc
TBOOMDetector *oomDetector = [[TBOOMDetector alloc] initWithCrashlyticsApiKey:@"..."
directory:directory
TBOOMDetector *oomDetector = [[TBOOMDetector alloc] initWithDirectory:directory
crashCheck:^BOOL{
// return [[Crashlytics crashlytics] didCrashDuringPreviousExecution]
return NO;
}
callback:^(TBTerminationType terminationType) {
if(terminationType == TBTerminationTypeBackgroundOom) {
DDLogError(@"Detected Background OOM");
[Answers logCustomEventWithName:@"OOM Background Crash"
customAttributes:nil];
} else if(terminationType == TBTerminationTypeForegroundOom) {
DDLogError(@"Detected Foreground OOM");
[Answers logCustomEventWithName:@"OOM foreground Crash"
customAttributes:nil];
}
}];
```
8 changes: 3 additions & 5 deletions TBOOMDetector.podspec
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Pod::Spec.new do |s|

s.name = "TBOOMDetector"
s.version = "0.6"
s.version = "1.0"
s.summary = "Detect Out Of Memory events in an iOS app"

s.description = <<-DESC
Expand All @@ -14,12 +14,10 @@ Pod::Spec.new do |s|
s.author = { "TrailBehind, Inc." => "Jesse@Gaiagps.com" }
s.social_media_url = "http://twitter.com/gaiagps"

s.platform = :ios, "6.0"
s.platform = :ios, "10.0"

s.source = { :git => "https://github.com/trailbehind/TBOOMDetector.git", :tag => "0.6" }
s.source = { :git => "https://github.com/trailbehind/TBOOMDetector.git", :tag => "1.0" }

s.source_files = "TBOOMDetector/*.{h,m,c}"
s.dependency 'Crashlytics', '~> 3'
s.static_framework = true

end
2 changes: 1 addition & 1 deletion TBOOMDetector/TBDebuggerUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,6 @@
/** Determine if debugger is attached to application
@return true if debugger is attached
*/
bool isApplicationAttachedToDebugger();
bool isApplicationAttachedToDebugger(void);

#endif
7 changes: 3 additions & 4 deletions TBOOMDetector/TBOOMDetector.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
//

#import <Foundation/Foundation.h>
#import <Crashlytics/Crashlytics.h>

typedef NS_ENUM(NSInteger, TBTerminationType) {
TBTerminationTypeUnknown = -1,
Expand All @@ -27,9 +26,9 @@ typedef NS_ENUM(NSInteger, TBTerminationType) {
@property (nonatomic, readonly) TBTerminationType lastTerminationType;
@property (nonatomic, readonly) BOOL appWasBackgroundedOnExit;

- (instancetype)initWithCrashlyticsApiKey:(NSString*)apiKey
directory:(NSString*)directory
callback:(void (^)(TBTerminationType terminationType))callback;
- (instancetype)initWithDirectory:(NSString*)directory
crashCheck:(BOOL (^)(void))crashCheck
callback:(void (^)(TBTerminationType terminationType))callback;
- (void)logAbort;
- (void)logExit;

Expand Down
20 changes: 6 additions & 14 deletions TBOOMDetector/TBOOMDetector.m
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#import "TBDebuggerUtils.h"
#import <UIKit/UIKit.h>

@interface TBOOMDetector () <CrashlyticsDelegate> {
@interface TBOOMDetector () {
NSString *terminationEventFile;
NSString *backgroundStateFile;
NSString *terminationEventFileContents;
Expand All @@ -25,13 +25,12 @@ @implementation TBOOMDetector
static NSString *AppVersionKey = @"AppVersion";
static NSString *OSVersionKey = @"OSVersion";

- (instancetype)initWithCrashlyticsApiKey:(NSString*)apiKey
directory:(NSString*)directory
callback:(void (^)(TBTerminationType terminationType))callback {
- (instancetype)initWithDirectory:(NSString*)directory
crashCheck:(BOOL (^)(void))crashCheck
callback:(void (^)(TBTerminationType terminationType))callback {
self = [super init];
if(self) {
stateDirectory = directory;
[Crashlytics startWithAPIKey:apiKey delegate:self];

[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(handleBackgroundNotification)
Expand Down Expand Up @@ -68,8 +67,8 @@ - (instancetype)initWithCrashlyticsApiKey:(NSString*)apiKey
_appWasBackgroundedOnExit = YES;
}

//Wait for crashlytics to run, so we know if there was a crash
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
dispatch_async(dispatch_get_main_queue(), ^{
self->crashWasDetected = crashCheck();
[self runChecks:callback];
});
}
Expand Down Expand Up @@ -200,13 +199,6 @@ - (void)logTerminationEvent:(NSString*)event {
}


#pragma mark - CrashlyticsDelegate
- (void)crashlyticsDidDetectReportForLastExecution:(CLSReport *)report completionHandler:(void (^)(BOOL submit))completionHandler {
crashWasDetected = YES;
completionHandler(YES);
}


#pragma mark - notifications
- (void)handleBackgroundNotification {
[@"" writeToFile:backgroundStateFile atomically:NO encoding:NSUTF8StringEncoding error:nil];
Expand Down
6 changes: 0 additions & 6 deletions demo/Podfile

This file was deleted.

Loading

0 comments on commit 1475d00

Please sign in to comment.