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

Commit

Permalink
Add delegate to FeedbackManagerDelegate
Browse files Browse the repository at this point in the history
Added `allowAutomaticFetchingForNewFeedbackForManager:` which allows the developer to influence if the SDK should fetch for new messages on app startup and when the app is coming into foreground.

By default the SDK always checks in those cases if there are already messages existing.
  • Loading branch information
Andreas Linde committed May 19, 2015
1 parent 1e30c35 commit bea1b36
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 2 deletions.
16 changes: 14 additions & 2 deletions Classes/BITFeedbackManager.m
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,6 @@ - (void)dealloc {
[self unregisterObservers];
}


- (void)didBecomeActiveActions {
if ([self isFeedbackManagerDisabled]) return;
if (!_didEnterBackgroundState) return;
Expand All @@ -126,7 +125,10 @@ - (void)didBecomeActiveActions {
} else {
[self updateAppDefinedUserData];
}
[self updateMessagesList];

if ([self allowFetchingNewMessages]) {
[self updateMessagesList];
}
}

- (void)didEnterBackgroundActions {
Expand Down Expand Up @@ -275,6 +277,16 @@ - (void)startManager {
}
}

- (BOOL)allowFetchingNewMessages {
BOOL fetchNewMessages = YES;
if ([BITHockeyManager sharedHockeyManager].delegate &&
[[BITHockeyManager sharedHockeyManager].delegate respondsToSelector:@selector(allowAutomaticFetchingForNewFeedbackForManager:)]) {
fetchNewMessages = [[BITHockeyManager sharedHockeyManager].delegate
allowAutomaticFetchingForNewFeedbackForManager:self];
}
return fetchNewMessages;
}

- (void)updateMessagesList {
if (_networkRequestInProgress) return;

Expand Down
13 changes: 13 additions & 0 deletions Classes/BITFeedbackManagerDelegate.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,4 +47,17 @@
*/
- (void) feedbackManagerDidReceiveNewFeedback:(BITFeedbackManager*) feedbackManager;


/**
* Can be implemented to control wether the feedback manager should automatically
* fetch for new messages on app startup or when becoming active.
*
* By default the SDK fetches on app startup or when the app is becoming active again
* if there are already messages existing or pending on the device.
*
* You could disable it e.g. depending on available mobile network/WLAN connection
* or let it fetch less frequently.
*/
- (BOOL) allowAutomaticFetchingForNewFeedbackForManager:(BITFeedbackManager *)feedbackManager;

@end
3 changes: 3 additions & 0 deletions Classes/BITFeedbackManagerPrivate.h
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,9 @@ extern NSString *const kBITFeedbackUpdateAttachmentThumbnail;
- (BOOL)updateUserNameUsingKeychainAndDelegate;
- (BOOL)updateUserEmailUsingKeychainAndDelegate;

// check if the user wants to influence when fetching of new messages may be done
- (BOOL)allowFetchingNewMessages;

// load new messages from the server
- (void)updateMessagesList;

Expand Down
21 changes: 21 additions & 0 deletions Support/HockeySDKTests/BITFeedbackManagerTests.m
Original file line number Diff line number Diff line change
Expand Up @@ -207,5 +207,26 @@ - (void)testUpdateUserEmailWithGlobalSetter {
assertThat(_sut.userEmail, equalTo(@"test"));
}

- (void)testAllowFetchingNewMessages {
BOOL fetchMessages = NO;

// check the default
fetchMessages = [_sut allowFetchingNewMessages];

assertThatBool(fetchMessages, equalToBool(YES));

// check the delegate is implemented and returns NO
BITHockeyManager *hm = [BITHockeyManager sharedHockeyManager];
NSObject <BITHockeyManagerDelegate> *classMock = mockObjectAndProtocol([NSObject class], @protocol(BITHockeyManagerDelegate));
[given([classMock allowAutomaticFetchingForNewFeedbackForManager:_sut]) willReturn:NO];
hm.delegate = classMock;
_sut.delegate = classMock;

fetchMessages = [_sut allowFetchingNewMessages];

assertThatBool(fetchMessages, equalToBool(NO));

[verifyCount(classMock, times(1)) allowAutomaticFetchingForNewFeedbackForManager:_sut];
}

@end

0 comments on commit bea1b36

Please sign in to comment.