Skip to content
This repository has been archived by the owner on Feb 19, 2020. It is now read-only.

Fix/fix disabling feedback #390

Merged
merged 5 commits into from
Jan 12, 2017
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion Classes/BITFeedbackManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,11 @@ typedef NS_ENUM(NSInteger, BITFeedbackObservationMode) {
/**
* Triggers when the user taps with three fingers on the screen. Captures a screenshot and attaches it to the composer.
*/
BITFeedbackObservationModeThreeFingerTap = 2
BITFeedbackObservationModeThreeFingerTap = 2,
/**
* Allows both BITFeedbackObservationModeOnScreenshot and BITFeedbackObservationModeThreeFingerTap at the same time.
*/
BITFeedbackObservationModeAll = 3
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is not a problem in this specific case but generally I would advise for this to be some other, very high number, 99 or so for example. But since it's unlikely we'll add any more options here, this should be fine 🙂

};


Expand Down
54 changes: 29 additions & 25 deletions Classes/BITFeedbackManager.m
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ - (void)unregisterObservers {

- (NSString *)uuidString {
CFUUIDRef theToken = CFUUIDCreate(NULL);
NSString * stringUUID = (__bridge_transfer NSString *) CFUUIDCreateString(NULL, theToken);
NSString *stringUUID = (__bridge_transfer NSString *) CFUUIDCreateString(NULL, theToken);
CFRelease(theToken);

return stringUUID;
Expand Down Expand Up @@ -318,7 +318,7 @@ - (void)updateMessagesListIfRequired {
- (BOOL)updateUserIDUsingKeychainAndDelegate {
BOOL availableViaDelegate = NO;

NSString * userID = [self stringValueFromKeychainForKey:kBITHockeyMetaUserID];
NSString *userID = [self stringValueFromKeychainForKey:kBITHockeyMetaUserID];

if ([[BITHockeyManager sharedHockeyManager].delegate respondsToSelector:@selector(userIDForHockeyManager:componentManager:)]) {
userID = [[BITHockeyManager sharedHockeyManager].delegate
Expand All @@ -337,7 +337,7 @@ - (BOOL)updateUserIDUsingKeychainAndDelegate {
- (BOOL)updateUserNameUsingKeychainAndDelegate {
BOOL availableViaDelegate = NO;

NSString * userName = [self stringValueFromKeychainForKey:kBITHockeyMetaUserName];
NSString *userName = [self stringValueFromKeychainForKey:kBITHockeyMetaUserName];

if ([[BITHockeyManager sharedHockeyManager].delegate respondsToSelector:@selector(userNameForHockeyManager:componentManager:)]) {
userName = [[BITHockeyManager sharedHockeyManager].delegate
Expand All @@ -357,7 +357,7 @@ - (BOOL)updateUserNameUsingKeychainAndDelegate {
- (BOOL)updateUserEmailUsingKeychainAndDelegate {
BOOL availableViaDelegate = NO;

NSString * userEmail = [self stringValueFromKeychainForKey:kBITHockeyMetaUserEmail];
NSString *userEmail = [self stringValueFromKeychainForKey:kBITHockeyMetaUserEmail];

if ([[BITHockeyManager sharedHockeyManager].delegate respondsToSelector:@selector(userEmailForHockeyManager:componentManager:)]) {
userEmail = [[BITHockeyManager sharedHockeyManager].delegate
Expand Down Expand Up @@ -453,7 +453,7 @@ - (void)loadMessages {
self.token = [self stringValueFromKeychainForKey:kBITFeedbackToken];

if ([unarchiver containsValueForKey:kBITFeedbackAppID]) {
NSString * appID = [unarchiver decodeObjectForKey:kBITFeedbackAppID];
NSString *appID = [unarchiver decodeObjectForKey:kBITFeedbackAppID];

// the stored thread is from another application identifier, so clear the token
// which will cause the new posts to create a new thread on the server for the
Expand Down Expand Up @@ -732,9 +732,9 @@ - (void)updateMessageListFromResponse:(NSDictionary *)jsonDictionary {
return;
}

NSDictionary * feedback = [jsonDictionary objectForKey:@"feedback"];
NSString * token = [jsonDictionary objectForKey:@"token"];
NSDictionary * feedbackObject = [jsonDictionary objectForKey:@"feedback"];
NSDictionary *feedback = [jsonDictionary objectForKey:@"feedback"];
NSString *token = [jsonDictionary objectForKey:@"token"];
NSDictionary *feedbackObject = [jsonDictionary objectForKey:@"feedback"];
if (feedback && token && feedbackObject) {
if ([self shouldForceNewThread]) {
self.token = nil;
Expand Down Expand Up @@ -898,19 +898,19 @@ - (void)updateMessageListFromResponse:(NSDictionary *)jsonDictionary {


- (void)sendNetworkRequestWithHTTPMethod:(NSString *)httpMethod withMessage:(BITFeedbackMessage *)message completionHandler:(void (^)(NSError *error))completionHandler {
NSString * boundary = @"----FOO";
NSString *boundary = @"----FOO";

_networkRequestInProgress = YES;
// inform the UI to update its data in case the list is already showing
[[NSNotificationCenter defaultCenter] postNotificationName:BITHockeyFeedbackMessagesLoadingStarted object:nil];

NSString * tokenParameter = @"";
NSString *tokenParameter = @"";
if ([self token]) {
tokenParameter = [NSString stringWithFormat:@"/%@", [self token]];
}
NSMutableString *parameter = [NSMutableString stringWithFormat:@"api/2/apps/%@/feedback%@", [self encodedAppIdentifier], tokenParameter];

NSString * lastMessageID = @"";
NSString *lastMessageID = @"";
if (!self.lastMessageID) {
[self updateLastMessageID];
}
Expand All @@ -926,7 +926,7 @@ - (void)sendNetworkRequestWithHTTPMethod:(NSString *)httpMethod withMessage:(BIT
];

// build request & send
NSString * url = [NSString stringWithFormat:@"%@%@", self.serverURL, parameter];
NSString *url = [NSString stringWithFormat:@"%@%@", self.serverURL, parameter];
BITHockeyLogDebug(@"INFO: sending api request to %@", url);

NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:url] cachePolicy:1 timeoutInterval:10.0];
Expand All @@ -935,7 +935,7 @@ - (void)sendNetworkRequestWithHTTPMethod:(NSString *)httpMethod withMessage:(BIT
[request setValue:@"gzip" forHTTPHeaderField:@"Accept-Encoding"];

if (message) {
NSString * contentType = [NSString stringWithFormat:@"multipart/form-data; boundary=%@", boundary];
NSString *contentType = [NSString stringWithFormat:@"multipart/form-data; boundary=%@", boundary];
[request setValue:contentType forHTTPHeaderField:@"Content-type"];

NSMutableData *postBody = [NSMutableData data];
Expand All @@ -948,7 +948,7 @@ - (void)sendNetworkRequestWithHTTPMethod:(NSString *)httpMethod withMessage:(BIT
[postBody appendData:[BITHockeyAppClient dataWithPostValue:[message text] forKey:@"text" boundary:boundary]];
[postBody appendData:[BITHockeyAppClient dataWithPostValue:[message token] forKey:@"message_token" boundary:boundary]];

NSString * installString = bit_appAnonID(NO);
NSString *installString = bit_appAnonID(NO);
if (installString) {
[postBody appendData:[BITHockeyAppClient dataWithPostValue:installString forKey:@"install_string" boundary:boundary]];
}
Expand All @@ -967,9 +967,9 @@ - (void)sendNetworkRequestWithHTTPMethod:(NSString *)httpMethod withMessage:(BIT
NSInteger photoIndex = 0;

for (BITFeedbackMessageAttachment *attachment in message.attachments) {
NSString * key = [NSString stringWithFormat:@"attachment%ld", (long) photoIndex];
NSString *key = [NSString stringWithFormat:@"attachment%ld", (long) photoIndex];

NSString * filename = attachment.originalFilename;
NSString *filename = attachment.originalFilename;

if (!filename) {
filename = [NSString stringWithFormat:@"Attachment %ld", (long) photoIndex];
Expand Down Expand Up @@ -1049,13 +1049,13 @@ - (void)handleFeedbackMessageResponse:(NSURLResponse *)response data:(NSData *)r
[self saveMessages];
[self performSelector:@selector(fetchMessageUpdates) withObject:nil afterDelay:0.2];
} else if ([responseData length]) {
NSString * responseString = [[NSString alloc] initWithBytes:[responseData bytes] length:[responseData length] encoding:NSUTF8StringEncoding];
NSString *responseString = [[NSString alloc] initWithBytes:[responseData bytes] length:[responseData length] encoding:NSUTF8StringEncoding];
BITHockeyLogDebug(@"INFO: Received API response: %@", responseString);

if (responseString && [responseString dataUsingEncoding:NSUTF8StringEncoding]) {
NSError *error = NULL;

NSDictionary * feedDict = (NSDictionary *) [NSJSONSerialization JSONObjectWithData:[responseString dataUsingEncoding:NSUTF8StringEncoding] options:0 error:&error];
NSDictionary *feedDict = (NSDictionary *) [NSJSONSerialization JSONObjectWithData:[responseString dataUsingEncoding:NSUTF8StringEncoding] options:0 error:&error];

// server returned empty response?
if (error) {
Expand All @@ -1066,7 +1066,7 @@ - (void)handleFeedbackMessageResponse:(NSURLResponse *)response data:(NSData *)r
userInfo:[NSDictionary dictionaryWithObjectsAndKeys:@"Server returned empty response.", NSLocalizedDescriptionKey, nil]]];
} else {
BITHockeyLogDebug(@"INFO: Received API response: %@", responseString);
NSString * status = [feedDict objectForKey:@"status"];
NSString *status = [feedDict objectForKey:@"status"];
if ([status compare:@"success"] != NSOrderedSame) {
[self reportError:[NSError errorWithDomain:kBITFeedbackErrorDomain
code:BITFeedbackAPIServerReturnedInvalidStatus
Expand Down Expand Up @@ -1126,7 +1126,7 @@ - (void)submitPendingMessages {
if (self.userEmail)
[messageToSend setEmail:self.userEmail];

NSString * httpMethod = @"POST";
NSString *httpMethod = @"POST";
if ([self token]) {
httpMethod = @"PUT";
}
Expand Down Expand Up @@ -1198,7 +1198,7 @@ - (void)setFeedbackObservationMode:(BITFeedbackObservationMode)feedbackObservati

if (feedbackObservationMode == BITFeedbackObservationModeOnScreenshot) {
[self setObservationModeOnScreenshotEnabled:YES];
if(self.observationModeThreeFingerTapEnabled) {
if (self.observationModeThreeFingerTapEnabled) {
[self setObservationModeThreeFingerTapEnabled:NO];
}
}
Expand All @@ -1209,6 +1209,11 @@ - (void)setFeedbackObservationMode:(BITFeedbackObservationMode)feedbackObservati
[self setObservationModeOnScreenshotEnabled:NO];
}
}

if (feedbackObservationMode == BITFeedbackObservationModeAll) {
[self setObservationModeOnScreenshotEnabled:YES];
[self setObservationModeThreeFingerTapEnabled:YES];
}
}
}

Expand All @@ -1224,7 +1229,7 @@ - (void)setObservationModeOnScreenshotEnabled:(BOOL)observationModeOnScreenshotE
}
} else {
if (observationModeOnScreenshotEnabled) {
BITHockeyLogWarning(@"WARNING: BITFeedbackObservationModeOnScreenshot requires iOS 7 or later.");
BITHockeyLogWarning(@"BITFeedbackObservationModeOnScreenshot requires iOS 7 or later.");
}
}

Expand All @@ -1236,7 +1241,7 @@ - (void)setObservationModeOnScreenshotEnabled:(BOOL)observationModeOnScreenshotE
- (void)setObservationModeThreeFingerTapEnabled:(BOOL)observationModeThreeFingerTapEnabled {
_observationModeThreeFingerTapEnabled = observationModeThreeFingerTapEnabled;

if(observationModeThreeFingerTapEnabled) {
if (observationModeThreeFingerTapEnabled) {
if (!self.tapRecognizer) {
self.tapRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(screenshotTripleTap:)];
self.tapRecognizer.numberOfTouchesRequired = 3;
Expand All @@ -1250,8 +1255,7 @@ - (void)setObservationModeThreeFingerTapEnabled:(BOOL)observationModeThreeFinger
}

BITHockeyLogVerbose(@"Enabled BITFeedbackObservationModeThreeFingerTap.");
}
else {
} else {
[[[UIApplication sharedApplication] keyWindow] removeGestureRecognizer:self.tapRecognizer];
self.tapRecognizer = nil;
BITHockeyLogVerbose(@"Disabled BITFeedbackObservationModeThreeFingerTap.");
Expand Down
52 changes: 52 additions & 0 deletions Support/HockeySDKTests/BITFeedbackManagerTests.m
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,20 @@ - (void)startManager {

#pragma mark - Setup Tests

- (void)testSetup {
XCTAssertNotNil(self.sut);
XCTAssertTrue([self.sut feedbackObservationMode] == BITFeedbackObservationNone);
XCTAssertNil(self.sut.tapRecognizer);
XCTAssertFalse([self.sut isFeedbackManagerDisabled]);
XCTAssertFalse([self.sut observationModeOnScreenshotEnabled]);
XCTAssertFalse([self.sut observationModeThreeFingerTapEnabled]);
XCTAssertNil([self.sut userEmail]);
XCTAssertNil([self.sut userID]);
XCTAssertNil([self.sut userName]);
XCTAssertNil([self.sut lastMessageID]);
XCTAssertNil([self.sut lastCheck]);
XCTAssertFalse([self.sut didAskUserData]);
}

#pragma mark - User Metadata

Expand Down Expand Up @@ -278,6 +292,44 @@ - (void)testSetFeedbackObservationMode {
XCTAssertTrue(self.sut.observationModeThreeFingerTapEnabled);
XCTAssertNotNil(self.sut.tapRecognizer);
XCTAssertTrue(self.sut.feedbackObservationMode == BITFeedbackObservationModeThreeFingerTap);

[self.sut setFeedbackObservationMode:BITFeedbackObservationNone];
XCTAssertFalse(self.sut.observationModeOnScreenshotEnabled);
XCTAssertFalse(self.sut.observationModeThreeFingerTapEnabled);
XCTAssertNil(self.sut.tapRecognizer);
XCTAssertTrue(self.sut.feedbackObservationMode == BITFeedbackObservationNone);

[self.sut setFeedbackObservationMode:BITFeedbackObservationModeAll];
XCTAssertTrue(self.sut.observationModeOnScreenshotEnabled);
XCTAssertTrue(self.sut.observationModeThreeFingerTapEnabled);
XCTAssertNotNil(self.sut.tapRecognizer);
XCTAssertTrue(self.sut.feedbackObservationMode == BITFeedbackObservationModeAll);

[self.sut setFeedbackObservationMode:BITFeedbackObservationModeThreeFingerTap];
XCTAssertFalse(self.sut.observationModeOnScreenshotEnabled);
XCTAssertTrue(self.sut.observationModeThreeFingerTapEnabled);
XCTAssertNotNil(self.sut.tapRecognizer);
XCTAssertTrue(self.sut.feedbackObservationMode == BITFeedbackObservationModeThreeFingerTap);

[self.sut setFeedbackObservationMode:BITFeedbackObservationModeAll];
XCTAssertTrue(self.sut.observationModeOnScreenshotEnabled);
XCTAssertTrue(self.sut.observationModeThreeFingerTapEnabled);
XCTAssertNotNil(self.sut.tapRecognizer);
XCTAssertTrue(self.sut.feedbackObservationMode == BITFeedbackObservationModeAll);

[self.sut setFeedbackObservationMode:BITFeedbackObservationModeOnScreenshot];
XCTAssertTrue(self.sut.observationModeOnScreenshotEnabled);
XCTAssertFalse(self.sut.observationModeThreeFingerTapEnabled);
XCTAssertNil(self.sut.tapRecognizer);
XCTAssertTrue(self.sut.feedbackObservationMode == BITFeedbackObservationModeOnScreenshot);

[self.sut setFeedbackObservationMode:BITFeedbackObservationModeThreeFingerTap];
XCTAssertFalse(self.sut.observationModeOnScreenshotEnabled);
XCTAssertTrue(self.sut.observationModeThreeFingerTapEnabled);
XCTAssertNotNil(self.sut.tapRecognizer);
XCTAssertTrue(self.sut.feedbackObservationMode == BITFeedbackObservationModeThreeFingerTap);


}

#pragma mark - FeedbackManagerDelegate Tests
Expand Down