Skip to content

Commit

Permalink
Merge pull request #16 from testfairy/feat-enable-disable-logs
Browse files Browse the repository at this point in the history
Added enableLogs() and disableLogs()
  • Loading branch information
diegoperini authored Jan 19, 2022
2 parents 49e37a1 + 763b0b2 commit 231da01
Show file tree
Hide file tree
Showing 5 changed files with 224 additions and 8 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ jobs:
npm install
- name: Update native SDK versions
run: |
ANDROID_SDK_VERSION=1.12.18
IOS_VERSION=1.29.5
ANDROID_SDK_VERSION=1.12.19
IOS_VERSION=1.29.6
mkdir -p Files/Android/
mkdir -p Files/iOS/
curl -s -L https://maven.testfairy.com/com/testfairy/testfairy-android-sdk/${ANDROID_SDK_VERSION}/testfairy-android-sdk-${ANDROID_SDK_VERSION}.aar -o Files/Android/testfairy-android-sdk.aar
Expand Down
Binary file modified Plugins/Android/testfairy-android-sdk.aar
Binary file not shown.
26 changes: 26 additions & 0 deletions Plugins/TestFairy.cs
Original file line number Diff line number Diff line change
Expand Up @@ -398,6 +398,26 @@ public static void disableMetric(string metric)
#endif
}

public static void enableLogs()
{
#if UNITY_EDITOR || (!UNITY_ANDROID && !UNITY_IPHONE)
#elif UNITY_IPHONE && !UNITY_EDITOR
TestFairy_enableLogs();
#elif UNITY_ANDROID && !UNITY_EDITOR
TestFairy.callMethod("enableLogs");
#endif
}

public static void disableLogs()
{
#if UNITY_EDITOR || (!UNITY_ANDROID && !UNITY_IPHONE)
#elif UNITY_IPHONE && !UNITY_EDITOR
TestFairy_disableLogs();
#elif UNITY_ANDROID && !UNITY_EDITOR
TestFairy.callMethod("disableLogs");
#endif
}

public static void enableFeedbackForm(string method)
{
#if UNITY_EDITOR || (!UNITY_ANDROID && !UNITY_IPHONE)
Expand Down Expand Up @@ -736,6 +756,12 @@ public override AndroidJavaObject Invoke(string methodName, AndroidJavaObject[]
[DllImport("__Internal")]
private static extern void TestFairy_disableMetric(string metric);

[DllImport("__Internal")]
private static extern void TestFairy_enableLogs();

[DllImport("__Internal")]
private static extern void TestFairy_disableLogs();

[DllImport("__Internal")]
private static extern void TestFairy_disableAutoUpdate();

Expand Down
194 changes: 188 additions & 6 deletions Plugins/iOS/TestFairy.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,173 @@
- (void)noAutoUpdateAvailable;
@end

@interface TestFairyFeedbackContent: NSObject
- (instancetype)initWith:(NSString *)text email:(NSString *)email timestamp:(long)timestamp;
- (instancetype)initWith:(NSString *)text email:(NSString *)email timestamp:(long)timestamp bitmap:(UIImage *)bitmap;
- (instancetype)initWith:(NSString *)text email:(NSString *)email timestamp:(long)timestamp bitmap:(UIImage *)bitmap attributes:(NSDictionary *)attributes;

@property(nonatomic, strong, readonly) NSString* text;
@property(nonatomic, strong, readonly) NSString* email;
@property(nonatomic, strong, readonly) UIImage* bitmap;
@property(nonatomic, strong, readonly) NSDictionary* attributes;
@property(nonatomic, readonly) long timestamp;
@end

/**
* Common interface for all custom feedback form fields
*/
@protocol TestFairyFeedbackFormField <NSObject>
/**
* Implement this to return a custom view for the form element
*/
- (UIView *)onCreateView;

/**
* Return the key name for the attribute represented by this form field
*/
- (NSString *)getAttribute;

/**
* Return the value for the attribute respressented by this form field
*/
- (NSString *)getValue;
@end

/**
* A simple form element for editable string inputs
*/
@interface TestFairyStringFeedbackFormField : NSObject<TestFairyFeedbackFormField>
- (instancetype)initWithAttribute:(NSString *)attribute
label:(NSString *)label
placeholder:(NSString *)placeholder
defaultValue:(NSString *)value;
@end

/**
* A simple form element for editable text area.
*/
@interface TestFairyTextAreaFeedbackFormField : NSObject<TestFairyFeedbackFormField>
- (instancetype)initWithAttribute:(NSString *)attribute
placeholder:(NSString *)placeholder
defaultValue:(NSString *)value;
@end

/**
* A dropdown element to represent single choice options, like an HTML select node.
*/
@interface TestFairySelectFeedbackFormField : NSObject<TestFairyFeedbackFormField>
- (instancetype)initWithAttribute:(NSString *)attribute
label:(NSString *)label
values:(NSDictionary *)values
defaultValue:(NSString *)value;
@end

@class TestFairyFeedbackOptionsBuilder;

/**
* Block for reviewing and modify feedback content before it is sent to the server
*/
typedef TestFairyFeedbackContent * (^TestFairyFeedbackInterceptor)(TestFairyFeedbackContent *);

@protocol TestFairyFeedbackVerifier <NSObject>
/**
* A callback from the feedback form to verify the contents that the user
* has inputed. Use this to verify the email address, specific address of the
* content, or any other information available in FeedbackContent.
*
* @param content TestFairyFeedbackContent
* @return YES if verification passed
*/
- (BOOL)verifyFeedback:(TestFairyFeedbackContent *)content;

/**
* A callback to get the error message after a failure from verifyFeedback
* method. This will only be called after verifyFeedback returned NO.
*
* @return Error message to be displayed on screen
*/
- (NSString *)getVerificationFailedMessage;
@end

@interface TestFairyFeedbackOptions: NSObject

/**
* Convenience method for creating TestFairyFeedbackOptions.
*
* TestFairyFeedbackOptions *options = [TestFairyFeedbackOptions createWithBlock:^(TestFairyFeedbackOptionsBuilder * builder) {
* builder.defaultText = @"Some default text";
* builder.isEmailMandatory = NO;
* }];
*
* Note: Developers do not need to call "build" on the TestFairyFeedbackOptionsBuilder. This will be called internally
*/
+ (instancetype)createWithBlock:(void (^)(TestFairyFeedbackOptionsBuilder *))block;

/**
* By setting a default text, you will override the initial content of the text area
* inside the feedback form. This way, you can standardize the way you receive feedbacks
* by specifying guidelines to your users.
*/
@property(readonly, nonatomic, strong) NSString* defaultText;

/**
* Determines whether the user has to add his email address to the feedback. Default is true
*/
@property(readonly, nonatomic) BOOL isEmailMandatory;

/**
* Determines whether the email field is displayed in the feedback form. Default is true
* Note: If set to false, isEmailMandatory will also be set to false.
*/
@property(readonly, nonatomic) BOOL isEmailVisible;

/**
* An optional callback before a feedback is sent. This allows the developer to review
* and modify the contents of the feedback (email, feedback body, attributes, and so on.)
*/
@property(readonly, nonatomic, copy) TestFairyFeedbackInterceptor interceptor;

/**
* By setting this list, feedback forms can be customized with extra input fields.
* Calling with a nil or empty list will enable the default fields, namely email and feedback message.
*/
@property(readonly, nonatomic) NSArray *feedbackFormFields;

/**
* Provide a custom title for the feedback form
*/
@property(readonly, nonatomic) NSString *title;

/**
* Provide a custom verification class for feedbacks. This allows you
* to control the checks that are done against the feedback's content
* and email address. If not provided, TestFairy will check for valid
* email (if mandatory) and feedback text. By providing your own class,
* you can, for example, add checks for email addresses ending with
* your own company domain.
*/
@property(readonly, nonatomic) id<TestFairyFeedbackVerifier> verifier;

@end

@interface TestFairyFeedbackOptionsBuilder: NSObject

/**
* Create TestFairyFeedbackOptions.
*
* Alternatively, See TestFairyFeedbackOptions#createWithBlock
*/
- (TestFairyFeedbackOptions *)build;

@property(nonatomic, strong) NSString* defaultText;
@property(nonatomic) BOOL isEmailMandatory;
@property(nonatomic) BOOL isEmailVisible;
@property(nonatomic, strong) NSString *title;
@property(nonatomic, copy) TestFairyFeedbackInterceptor interceptor;
@property(nonatomic, strong) NSArray *feedbackFormFields;
@property(nonatomic, strong) id<TestFairyFeedbackVerifier> verifier;
@end

@interface TestFairy: NSObject

/**
Expand All @@ -70,10 +237,6 @@
*
* @param appToken Your key as given to you in your TestFairy account
* @param options A dictionary of options controlling the current session
* Options include
* - metrics: comma separated string of default metric options such as
* "cpu,memory,network-requests,shake,video,logs"
* - enableCrashReporter: @YES / @NO to enable crash handling. Default is @YES
*/
+ (void)begin:(NSString *)appToken withOptions:(NSDictionary *)options;

Expand All @@ -95,6 +258,10 @@
*/
+ (void)installFeedbackHandler:(NSString *)appToken method:(NSString *)method;

/**
* Disables a previously installed feedback handler. Stops listening user shakes to prompt feedback alerts.
*/
+ (void)uninstallFeedbackHandler;
/**
* Change the server endpoint for use with on-premise hosting. Please
* contact support or sales for more information. Must be called before begin
Expand Down Expand Up @@ -399,6 +566,16 @@
*/
+ (void)disableMetric:(NSString *)metric;

/**
* Enables recording of logs regardless of build settings. Must be called before begin.
*/
+ (void)enableLogs;

/**
* Disables recording of logs regardless of build settings. Must be called before begin.
*/
+ (void)disableLogs;

/**
* Enables the ability to capture video recording regardless of build settings.
* Valid values for policy include "always" and "wifi"
Expand Down Expand Up @@ -460,7 +637,7 @@
*
* @param visible BOOL
*/
+ (void)setFeedbackEmailVisible:(BOOL)visible;
+ (void)setFeedbackEmailVisible:(BOOL)visible TF_DEPRECATED("Please refer setTestFairyFeedbackOptions");

/**
* Customize the feedback form
Expand All @@ -479,7 +656,12 @@
*
* isEmailVisible: Determines whether the email field is displayed in the feedback form. Default is true
*/
+ (void)setFeedbackOptions:(NSDictionary *)options;
+ (void)setFeedbackOptions:(NSDictionary *)options TF_DEPRECATED("Please refer to setTestFairyFeedbackOptions");

/**
* You can customize the feedback form by creating FeedbackOptions, See TestFairyFeedbackOptions
*/
+ (void)setTestFairyFeedbackOptions:(TestFairyFeedbackOptions *)options;

/**
* Query the distribution status of this build. Distribution is not required
Expand Down
8 changes: 8 additions & 0 deletions Plugins/iOS/TestFairyUnityWrapper.m
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,14 @@ void TestFairy_disableMetric(char *metric) {
[TestFairy disableMetric: value];
}

void TestFairy_enableLogs() {
[TestFairy enableLogs];
}

void TestFairy_disableLogs() {
[TestFairy disableLogs];
}

void TestFairy_enableVideo(char *policy, char *quality, float framesPerSecond) {
NSString *policy_ = policy == NULL ? @"" : [NSString stringWithUTF8String: policy];
NSString *quality_ = quality == NULL ? @"" : [NSString stringWithUTF8String: quality];
Expand Down

0 comments on commit 231da01

Please sign in to comment.