Skip to content

Commit 2f2dea0

Browse files
committed
feat(crashlytics): Test Crash Implemented
1 parent db3b661 commit 2f2dea0

File tree

5 files changed

+237
-205
lines changed

5 files changed

+237
-205
lines changed

src/android/FirebasePlugin.java

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,9 @@ public boolean execute(String action, JSONArray args, CallbackContext callbackCo
134134
}else if(action.equals("setCrashlyticsUserId")){
135135
this.setCrashlyticsUserId(callbackContext, args.getString(0));
136136
return true;
137+
}else if(action.equals("testCrash")){
138+
this.testCrash(callbackContext);
139+
return true;
137140
} else if (action.equals("setScreenName")) {
138141
this.setScreenName(callbackContext, args.getString(0));
139142
return true;
@@ -513,6 +516,19 @@ public void run() {
513516
});
514517
}
515518

519+
private void crashTest(final CallbackContext callbackContext) {
520+
cordova.getThreadPool().execute(new Runnable() {
521+
public void run() {
522+
try {
523+
Crashlytics.getInstance().crash(); // Force a crash
524+
} catch (Exception e) {
525+
Crashlytics.logException(e);
526+
callbackContext.error(e.getMessage());
527+
}
528+
}
529+
});
530+
}
531+
516532
private void setScreenName(final CallbackContext callbackContext, final String name) {
517533
// This must be called on the main thread
518534
cordova.getActivity().runOnUiThread(new Runnable() {
@@ -747,7 +763,7 @@ public void onVerificationCompleted(PhoneAuthCredential credential) {
747763
try {
748764
String verificationId = null;
749765
String code = null;
750-
766+
751767
Field[] fields = credential.getClass().getDeclaredFields();
752768
for (Field field : fields) {
753769
Class type = field.getType();
@@ -814,7 +830,7 @@ public void onCodeSent(String verificationId, PhoneAuthProvider.ForceResendingTo
814830
callbackContext.sendPluginResult(pluginresult);
815831
}
816832
};
817-
833+
818834
PhoneAuthProvider.getInstance().verifyPhoneNumber(number, // Phone number to verify
819835
timeOutDuration, // Timeout duration
820836
TimeUnit.SECONDS, // Unit of timeout
@@ -827,7 +843,7 @@ public void onCodeSent(String verificationId, PhoneAuthProvider.ForceResendingTo
827843
}
828844
});
829845
}
830-
846+
831847
private static String getPrivateField(PhoneAuthCredential credential, Field field) {
832848
try {
833849
field.setAccessible(true);

src/ios/FirebasePlugin.h

Lines changed: 43 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,43 @@
1-
#import <Cordova/CDV.h>
2-
#import "AppDelegate.h"
3-
4-
@interface FirebasePlugin : CDVPlugin
5-
+ (FirebasePlugin *) firebasePlugin;
6-
- (void)getVerificationID:(CDVInvokedUrlCommand*)command;
7-
- (void)verifyPhoneNumber:(CDVInvokedUrlCommand*)command;
8-
- (void)getInstanceId:(CDVInvokedUrlCommand*)command;
9-
- (void)getId:(CDVInvokedUrlCommand*)command;
10-
- (void)getToken:(CDVInvokedUrlCommand*)command;
11-
- (void)grantPermission:(CDVInvokedUrlCommand*)command;
12-
- (void)hasPermission:(CDVInvokedUrlCommand*)command;
13-
- (void)setBadgeNumber:(CDVInvokedUrlCommand*)command;
14-
- (void)getBadgeNumber:(CDVInvokedUrlCommand*)command;
15-
- (void)subscribe:(CDVInvokedUrlCommand*)command;
16-
- (void)unsubscribe:(CDVInvokedUrlCommand*)command;
17-
- (void)unregister:(CDVInvokedUrlCommand*)command;
18-
- (void)onNotificationOpen:(CDVInvokedUrlCommand*)command;
19-
- (void)onTokenRefresh:(CDVInvokedUrlCommand*)command;
20-
- (void)sendNotification:(NSDictionary*)userInfo;
21-
- (void)sendToken:(NSString*)token;
22-
- (void)logEvent:(CDVInvokedUrlCommand*)command;
23-
- (void)logError:(CDVInvokedUrlCommand*)command;
24-
- (void)setCrashlyticsUserId:(CDVInvokedUrlCommand*)command;
25-
- (void)setScreenName:(CDVInvokedUrlCommand*)command;
26-
- (void)setUserId:(CDVInvokedUrlCommand*)command;
27-
- (void)setUserProperty:(CDVInvokedUrlCommand*)command;
28-
- (void)fetch:(CDVInvokedUrlCommand*)command;
29-
- (void)activateFetched:(CDVInvokedUrlCommand*)command;
30-
- (void)getValue:(CDVInvokedUrlCommand*)command;
31-
- (void)startTrace:(CDVInvokedUrlCommand*)command;
32-
- (void)incrementCounter:(CDVInvokedUrlCommand*)command;
33-
- (void)stopTrace:(CDVInvokedUrlCommand*)command;
34-
- (void)setAnalyticsCollectionEnabled:(CDVInvokedUrlCommand*)command;
35-
- (void)setPerformanceCollectionEnabled:(CDVInvokedUrlCommand*)command;
36-
- (void)clearAllNotifications:(CDVInvokedUrlCommand *)command;
37-
@property (nonatomic, copy) NSString *notificationCallbackId;
38-
@property (nonatomic, copy) NSString *tokenRefreshCallbackId;
39-
@property (nonatomic, retain) NSMutableArray *notificationStack;
40-
@property (nonatomic, readwrite) NSMutableDictionary* traces;
41-
42-
@end
1+
#import <Cordova/CDV.h>
2+
#import "AppDelegate.h"
3+
4+
@interface FirebasePlugin : CDVPlugin
5+
+ (FirebasePlugin *) firebasePlugin;
6+
- (void)getVerificationID:(CDVInvokedUrlCommand*)command;
7+
- (void)verifyPhoneNumber:(CDVInvokedUrlCommand*)command;
8+
- (void)getInstanceId:(CDVInvokedUrlCommand*)command;
9+
- (void)getId:(CDVInvokedUrlCommand*)command;
10+
- (void)getToken:(CDVInvokedUrlCommand*)command;
11+
- (void)grantPermission:(CDVInvokedUrlCommand*)command;
12+
- (void)hasPermission:(CDVInvokedUrlCommand*)command;
13+
- (void)setBadgeNumber:(CDVInvokedUrlCommand*)command;
14+
- (void)getBadgeNumber:(CDVInvokedUrlCommand*)command;
15+
- (void)subscribe:(CDVInvokedUrlCommand*)command;
16+
- (void)unsubscribe:(CDVInvokedUrlCommand*)command;
17+
- (void)unregister:(CDVInvokedUrlCommand*)command;
18+
- (void)onNotificationOpen:(CDVInvokedUrlCommand*)command;
19+
- (void)onTokenRefresh:(CDVInvokedUrlCommand*)command;
20+
- (void)sendNotification:(NSDictionary*)userInfo;
21+
- (void)sendToken:(NSString*)token;
22+
- (void)logEvent:(CDVInvokedUrlCommand*)command;
23+
- (void)logError:(CDVInvokedUrlCommand*)command;
24+
- (void)setCrashlyticsUserId:(CDVInvokedUrlCommand*)command;
25+
- (void)testCrash:(CDVInvokedUrlCommand*)command;
26+
- (void)setScreenName:(CDVInvokedUrlCommand*)command;
27+
- (void)setUserId:(CDVInvokedUrlCommand*)command;
28+
- (void)setUserProperty:(CDVInvokedUrlCommand*)command;
29+
- (void)fetch:(CDVInvokedUrlCommand*)command;
30+
- (void)activateFetched:(CDVInvokedUrlCommand*)command;
31+
- (void)getValue:(CDVInvokedUrlCommand*)command;
32+
- (void)startTrace:(CDVInvokedUrlCommand*)command;
33+
- (void)incrementCounter:(CDVInvokedUrlCommand*)command;
34+
- (void)stopTrace:(CDVInvokedUrlCommand*)command;
35+
- (void)setAnalyticsCollectionEnabled:(CDVInvokedUrlCommand*)command;
36+
- (void)setPerformanceCollectionEnabled:(CDVInvokedUrlCommand*)command;
37+
- (void)clearAllNotifications:(CDVInvokedUrlCommand *)command;
38+
@property (nonatomic, copy) NSString *notificationCallbackId;
39+
@property (nonatomic, copy) NSString *tokenRefreshCallbackId;
40+
@property (nonatomic, retain) NSMutableArray *notificationStack;
41+
@property (nonatomic, readwrite) NSMutableDictionary* traces;
42+
43+
@end

src/ios/FirebasePlugin.m

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -301,6 +301,11 @@ - (void)setCrashlyticsUserId:(CDVInvokedUrlCommand *)command {
301301
[self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
302302
}
303303

304+
- (void)crashTest: (CDVInvokedUrlCommand *)command {
305+
[[Crashlytics sharedInstance] crash];
306+
[self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
307+
}
308+
304309
- (void)setScreenName:(CDVInvokedUrlCommand *)command {
305310
NSString* name = [command.arguments objectAtIndex:0];
306311

0 commit comments

Comments
 (0)