Skip to content

Commit

Permalink
feat(crashlytics): Test Crash Implemented
Browse files Browse the repository at this point in the history
  • Loading branch information
AhsanAyaz committed Nov 19, 2018
1 parent db3b661 commit 085788e
Show file tree
Hide file tree
Showing 5 changed files with 237 additions and 205 deletions.
22 changes: 19 additions & 3 deletions src/android/FirebasePlugin.java
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,9 @@ public boolean execute(String action, JSONArray args, CallbackContext callbackCo
}else if(action.equals("setCrashlyticsUserId")){
this.setCrashlyticsUserId(callbackContext, args.getString(0));
return true;
}else if(action.equals("testCrash")){
this.testCrash(callbackContext);
return true;
} else if (action.equals("setScreenName")) {
this.setScreenName(callbackContext, args.getString(0));
return true;
Expand Down Expand Up @@ -513,6 +516,19 @@ public void run() {
});
}

private void testCrash(final CallbackContext callbackContext) {
cordova.getThreadPool().execute(new Runnable() {
public void run() {
try {
Crashlytics.getInstance().crash(); // Force a crash
} catch (Exception e) {
Crashlytics.logException(e);
callbackContext.error(e.getMessage());
}
}
});
}

private void setScreenName(final CallbackContext callbackContext, final String name) {
// This must be called on the main thread
cordova.getActivity().runOnUiThread(new Runnable() {
Expand Down Expand Up @@ -747,7 +763,7 @@ public void onVerificationCompleted(PhoneAuthCredential credential) {
try {
String verificationId = null;
String code = null;

Field[] fields = credential.getClass().getDeclaredFields();
for (Field field : fields) {
Class type = field.getType();
Expand Down Expand Up @@ -814,7 +830,7 @@ public void onCodeSent(String verificationId, PhoneAuthProvider.ForceResendingTo
callbackContext.sendPluginResult(pluginresult);
}
};

PhoneAuthProvider.getInstance().verifyPhoneNumber(number, // Phone number to verify
timeOutDuration, // Timeout duration
TimeUnit.SECONDS, // Unit of timeout
Expand All @@ -827,7 +843,7 @@ public void onCodeSent(String verificationId, PhoneAuthProvider.ForceResendingTo
}
});
}

private static String getPrivateField(PhoneAuthCredential credential, Field field) {
try {
field.setAccessible(true);
Expand Down
85 changes: 43 additions & 42 deletions src/ios/FirebasePlugin.h
Original file line number Diff line number Diff line change
@@ -1,42 +1,43 @@
#import <Cordova/CDV.h>
#import "AppDelegate.h"

@interface FirebasePlugin : CDVPlugin
+ (FirebasePlugin *) firebasePlugin;
- (void)getVerificationID:(CDVInvokedUrlCommand*)command;
- (void)verifyPhoneNumber:(CDVInvokedUrlCommand*)command;
- (void)getInstanceId:(CDVInvokedUrlCommand*)command;
- (void)getId:(CDVInvokedUrlCommand*)command;
- (void)getToken:(CDVInvokedUrlCommand*)command;
- (void)grantPermission:(CDVInvokedUrlCommand*)command;
- (void)hasPermission:(CDVInvokedUrlCommand*)command;
- (void)setBadgeNumber:(CDVInvokedUrlCommand*)command;
- (void)getBadgeNumber:(CDVInvokedUrlCommand*)command;
- (void)subscribe:(CDVInvokedUrlCommand*)command;
- (void)unsubscribe:(CDVInvokedUrlCommand*)command;
- (void)unregister:(CDVInvokedUrlCommand*)command;
- (void)onNotificationOpen:(CDVInvokedUrlCommand*)command;
- (void)onTokenRefresh:(CDVInvokedUrlCommand*)command;
- (void)sendNotification:(NSDictionary*)userInfo;
- (void)sendToken:(NSString*)token;
- (void)logEvent:(CDVInvokedUrlCommand*)command;
- (void)logError:(CDVInvokedUrlCommand*)command;
- (void)setCrashlyticsUserId:(CDVInvokedUrlCommand*)command;
- (void)setScreenName:(CDVInvokedUrlCommand*)command;
- (void)setUserId:(CDVInvokedUrlCommand*)command;
- (void)setUserProperty:(CDVInvokedUrlCommand*)command;
- (void)fetch:(CDVInvokedUrlCommand*)command;
- (void)activateFetched:(CDVInvokedUrlCommand*)command;
- (void)getValue:(CDVInvokedUrlCommand*)command;
- (void)startTrace:(CDVInvokedUrlCommand*)command;
- (void)incrementCounter:(CDVInvokedUrlCommand*)command;
- (void)stopTrace:(CDVInvokedUrlCommand*)command;
- (void)setAnalyticsCollectionEnabled:(CDVInvokedUrlCommand*)command;
- (void)setPerformanceCollectionEnabled:(CDVInvokedUrlCommand*)command;
- (void)clearAllNotifications:(CDVInvokedUrlCommand *)command;
@property (nonatomic, copy) NSString *notificationCallbackId;
@property (nonatomic, copy) NSString *tokenRefreshCallbackId;
@property (nonatomic, retain) NSMutableArray *notificationStack;
@property (nonatomic, readwrite) NSMutableDictionary* traces;

@end
#import <Cordova/CDV.h>
#import "AppDelegate.h"

@interface FirebasePlugin : CDVPlugin
+ (FirebasePlugin *) firebasePlugin;
- (void)getVerificationID:(CDVInvokedUrlCommand*)command;
- (void)verifyPhoneNumber:(CDVInvokedUrlCommand*)command;
- (void)getInstanceId:(CDVInvokedUrlCommand*)command;
- (void)getId:(CDVInvokedUrlCommand*)command;
- (void)getToken:(CDVInvokedUrlCommand*)command;
- (void)grantPermission:(CDVInvokedUrlCommand*)command;
- (void)hasPermission:(CDVInvokedUrlCommand*)command;
- (void)setBadgeNumber:(CDVInvokedUrlCommand*)command;
- (void)getBadgeNumber:(CDVInvokedUrlCommand*)command;
- (void)subscribe:(CDVInvokedUrlCommand*)command;
- (void)unsubscribe:(CDVInvokedUrlCommand*)command;
- (void)unregister:(CDVInvokedUrlCommand*)command;
- (void)onNotificationOpen:(CDVInvokedUrlCommand*)command;
- (void)onTokenRefresh:(CDVInvokedUrlCommand*)command;
- (void)sendNotification:(NSDictionary*)userInfo;
- (void)sendToken:(NSString*)token;
- (void)logEvent:(CDVInvokedUrlCommand*)command;
- (void)logError:(CDVInvokedUrlCommand*)command;
- (void)setCrashlyticsUserId:(CDVInvokedUrlCommand*)command;
- (void)testCrash:(CDVInvokedUrlCommand*)command;
- (void)setScreenName:(CDVInvokedUrlCommand*)command;
- (void)setUserId:(CDVInvokedUrlCommand*)command;
- (void)setUserProperty:(CDVInvokedUrlCommand*)command;
- (void)fetch:(CDVInvokedUrlCommand*)command;
- (void)activateFetched:(CDVInvokedUrlCommand*)command;
- (void)getValue:(CDVInvokedUrlCommand*)command;
- (void)startTrace:(CDVInvokedUrlCommand*)command;
- (void)incrementCounter:(CDVInvokedUrlCommand*)command;
- (void)stopTrace:(CDVInvokedUrlCommand*)command;
- (void)setAnalyticsCollectionEnabled:(CDVInvokedUrlCommand*)command;
- (void)setPerformanceCollectionEnabled:(CDVInvokedUrlCommand*)command;
- (void)clearAllNotifications:(CDVInvokedUrlCommand *)command;
@property (nonatomic, copy) NSString *notificationCallbackId;
@property (nonatomic, copy) NSString *tokenRefreshCallbackId;
@property (nonatomic, retain) NSMutableArray *notificationStack;
@property (nonatomic, readwrite) NSMutableDictionary* traces;

@end
5 changes: 5 additions & 0 deletions src/ios/FirebasePlugin.m
Original file line number Diff line number Diff line change
Expand Up @@ -301,6 +301,11 @@ - (void)setCrashlyticsUserId:(CDVInvokedUrlCommand *)command {
[self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
}

- (void)crashTest: (CDVInvokedUrlCommand *)command {
[[Crashlytics sharedInstance] crash];
[self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
}

- (void)setScreenName:(CDVInvokedUrlCommand *)command {
NSString* name = [command.arguments objectAtIndex:0];

Expand Down
Loading

0 comments on commit 085788e

Please sign in to comment.