Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[iOS]Crash reporting plugin #322

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
9 changes: 9 additions & 0 deletions iOS/FlipperKit.podspec
Expand Up @@ -155,4 +155,13 @@ Pod::Spec.new do |spec|
ss.source_files = "iOS/Plugins/FlipperKitExamplePlugin/**/*.{h,mm}"
ss.pod_target_xcconfig = { "HEADER_SEARCH_PATHS" => "\"$(PODS_ROOT)\"/Headers/Private/FlipperKit/**" }
end

spec.subspec "FlipperKitCrashReporterPlugin" do |ss|
ss.header_dir = "FlipperKitCrashReporterPlugin"
ss.dependency 'FlipperKit/Core'
ss.compiler_flags = folly_compiler_flags
ss.public_header_files = 'iOS/Plugins/FlipperKitCrashReporterPlugin/FlipperKitCrashReporterPlugin.h'
ss.source_files = "iOS/Plugins/FlipperKitCrashReporterPlugin/**/*.{h,mm}"
ss.pod_target_xcconfig = { "HEADER_SEARCH_PATHS" => "\"$(PODS_ROOT)\"/Headers/Private/FlipperKit/**" }
end
end
@@ -0,0 +1,19 @@
/*
* Copyright (c) 2018-present, Facebook, Inc.
*
* This source code is licensed under the MIT license found in the LICENSE
* file in the root directory of this source tree.
*
*/
#if FB_SONARKIT_ENABLED

#import <Foundation/Foundation.h>
#import <FlipperKit/FlipperPlugin.h>

@interface FlipperKitCrashReporterPlugin : NSObject<FlipperPlugin>
- (instancetype)init NS_UNAVAILABLE;
+ (instancetype) sharedInstance;
@end


#endif
@@ -0,0 +1,71 @@
/*
* Copyright (c) 2018-present, Facebook, Inc.
*
* This source code is licensed under the MIT license found in the LICENSE
* file in the root directory of this source tree.
*
*/
#if FB_SONARKIT_ENABLED
#import "FlipperKitCrashReporterPlugin.h"
#import <FlipperKit/FlipperConnection.h>

@interface FlipperKitCrashReporterPlugin()
@property (strong, nonatomic) id<FlipperConnection> connection;
@property (assign, nonatomic) NSUInteger notificationID;
- (void) handleException:(NSException *)exception;

@end

void flipperkitUncaughtExceptionHandler(NSException *exception) {
NSLog(@"CRASH: %@", exception);
NSLog(@"Stack Trace: %@", [exception callStackSymbols]);
[[FlipperKitCrashReporterPlugin sharedInstance] handleException:exception];
}

@implementation FlipperKitCrashReporterPlugin

- (instancetype)init {
if (self = [super init]) {
_connection = nil;
_notificationID = 0;
}
return self;
}

+ (instancetype)sharedInstance {
static FlipperKitCrashReporterPlugin *sInstance = nil;

static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
sInstance = [FlipperKitCrashReporterPlugin new];
});

return sInstance;
}

- (NSString *)identifier {
return @"CrashReporter";
}

- (void) handleException:(NSException *)exception {
// TODO: Rather than having indirection from c function, somehow pass objective c selectors as a c function pointer to NSSetUncaughtExceptionHandler
self.notificationID += 1;
[self.connection send:@"crash-report" withParams:@{@"id": [NSUUID UUID].UUIDString, @"reason": [exception reason], @"name": [exception name], @"callstack": [exception callStackSymbols]}];

}
- (void)didConnect:(id<FlipperConnection>)connection {
self.connection = connection;
NSSetUncaughtExceptionHandler(&flipperkitUncaughtExceptionHandler);
}

- (void)didDisconnect {
self.connection = nil;
NSSetUncaughtExceptionHandler(nullptr);
}

- (BOOL)runInBackground {
return YES;
}

@end
#endif
Expand Up @@ -27,6 +27,7 @@ - (void)setAdapter:(id<SKNetworkAdapterDelegate>)adapter {
}

- (instancetype)init {

if (self = [super initWithQueue:dispatch_queue_create("com.sonarkit.network.buffer", DISPATCH_QUEUE_SERIAL)]) {
}
return self;
Expand Down
11 changes: 10 additions & 1 deletion iOS/Sample/AppDelegate.mm
Expand Up @@ -6,7 +6,7 @@
*
*/
#import "AppDelegate.h"

#import <FlipperKitCrashReporterPlugin/FlipperKitCrashReporterPlugin.h>
#import <FlipperKit/FlipperClient.h>
#import <FlipperKitLayoutPlugin/FlipperKitLayoutPlugin.h>
#import <FlipperKitNetworkPlugin/FlipperKitNetworkPlugin.h>
Expand All @@ -27,6 +27,12 @@ @implementation AppDelegate {
UIWindow *_window;
}

//void uncaughtExceptionHandler(NSException *exception) {
// NSLog(@"CRASH: %@", exception);
// NSLog(@"Stack Trace: %@", [exception callStackSymbols]);
// // Internal error reporting
//}

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
_window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
Expand All @@ -38,6 +44,7 @@ - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(
withDescriptorMapper: layoutDescriptorMapper]];

[client addPlugin:[[FKUserDefaultsPlugin alloc] initWithSuiteName:nil]];
[client addPlugin:[FlipperKitCrashReporterPlugin sharedInstance]];

[[FlipperClient sharedClient] addPlugin: [[FlipperKitNetworkPlugin alloc] initWithNetworkAdapter:[SKIOSNetworkAdapter new]]];
[client addPlugin:[FlipperKitExamplePlugin sharedInstance]];
Expand All @@ -54,6 +61,8 @@ - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(
[_window makeKeyAndVisible];

NSLog(@"Hello from Flipper in an Objc app!");
// NSSetUncaughtExceptionHandler(&uncaughtExceptionHandler); // Normal launch stuff

return YES;
}

Expand Down
10 changes: 5 additions & 5 deletions iOS/Sample/MainStoryBoard.storyboard
@@ -1,11 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="14313.18" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" useSafeAreas="YES" colorMatched="YES">
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="14460.31" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" useSafeAreas="YES" colorMatched="YES">
<device id="retina4_7" orientation="portrait">
<adaptation id="fullscreen"/>
</device>
<dependencies>
<deployment identifier="iOS"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="14283.14"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="14460.20"/>
<capability name="Safe area layout guides" minToolsVersion="9.0"/>
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
</dependencies>
Expand Down Expand Up @@ -259,6 +259,9 @@
<rect key="frame" x="0.0" y="0.0" width="375" height="667"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<subviews>
<imageView userInteractionEnabled="NO" contentMode="scaleAspectFill" horizontalHuggingPriority="251" verticalHuggingPriority="251" image="sonarpattern" translatesAutoresizingMaskIntoConstraints="NO" id="ytS-7A-bty">
<rect key="frame" x="0.0" y="20" width="375" height="647"/>
</imageView>
<view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="WSh-CB-RQ8">
<rect key="frame" x="40" y="257.5" width="295" height="152"/>
<subviews>
Expand Down Expand Up @@ -319,9 +322,6 @@
<constraint firstItem="Fel-3h-2Ts" firstAttribute="top" secondItem="cp1-5I-XfA" secondAttribute="bottom" constant="8" id="sAQ-IL-GiU"/>
</constraints>
</view>
<imageView userInteractionEnabled="NO" contentMode="scaleAspectFill" horizontalHuggingPriority="251" verticalHuggingPriority="251" image="sonarpattern" translatesAutoresizingMaskIntoConstraints="NO" id="ytS-7A-bty">
<rect key="frame" x="0.0" y="20" width="375" height="647"/>
</imageView>
</subviews>
<color key="backgroundColor" white="0.0" alpha="0.0" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
<constraints>
Expand Down
1 change: 1 addition & 0 deletions iOS/Sample/Podfile
Expand Up @@ -10,6 +10,7 @@ target 'Sample' do
pod 'FlipperKit/SKIOSNetworkPlugin', :path => '../../FlipperKit.podspec'
pod 'FlipperKit/FlipperKitUserDefaultsPlugin', :path => '../../FlipperKit.podspec'
pod 'FlipperKit/FlipperKitExamplePlugin', :path => '../../FlipperKit.podspec'
pod 'FlipperKit/FlipperKitCrashReporterPlugin', :path => '../../FlipperKit.podspec'
pod 'Flipper', :path => '../../Flipper.podspec'
post_install do |installer|

Expand Down