diff --git a/Classes/BITFeedbackManager.h b/Classes/BITFeedbackManager.h index 1f1543df26..e4059d1d2c 100644 --- a/Classes/BITFeedbackManager.h +++ b/Classes/BITFeedbackManager.h @@ -59,6 +59,25 @@ typedef NS_ENUM(NSInteger, BITFeedbackUserDataElement) { BITFeedbackUserDataElementRequired = 2 }; +/** + * Available modes for collecting automated feedback. + */ +typedef NS_ENUM(NSInteger, BITFeedbackObservationMode) { + /** + * No automatic feedback gathering. + */ + BITFeedbackObservationNone = 0, + /** + * Feedback compose form will open once a screenshot is taken. + */ + BITFeedbackObservationModeOnScreenshot = 1, + /** + * Feedback compose will open with a generated screenshot if the screen is tapped + * three fingers for three seconds. + */ + BITFeedbackObservationModeThreeFingersThreeSeconds = 2 +}; + @class BITFeedbackMessage; @protocol BITFeedbackManagerDelegate; @@ -241,6 +260,19 @@ typedef NS_ENUM(NSInteger, BITFeedbackUserDataElement) { */ - (void)showFeedbackComposeView; +/** + Present the modal feedback compose message user interface with the items given. + All NSString-Content in the array will be concatenated and result in the message, + while all UIImage and NSData-instances will be turned into attachments. + */ +- (void)showFeedbackComposeViewWithPreparedItems:(NSArray *)items; + +/** + Present the modal feedback compose message user interface with a screenshot that is taken + at the time of calling this method. + */ +- (void)showFeedbackComposeViewWithGeneratedScreenshot; + /** Create an feedback compose view @@ -262,5 +294,7 @@ typedef NS_ENUM(NSInteger, BITFeedbackUserDataElement) { */ - (BITFeedbackComposeViewController *)feedbackComposeViewController; +- (void)setFeedbackObservationMode:(BITFeedbackObservationMode)mode; + @end diff --git a/Classes/BITFeedbackManager.m b/Classes/BITFeedbackManager.m index 8eac1761af..c79dc986a3 100644 --- a/Classes/BITFeedbackManager.m +++ b/Classes/BITFeedbackManager.m @@ -29,6 +29,8 @@ #import "HockeySDK.h" +#import + #if HOCKEYSDK_FEATURE_FEEDBACK #import "HockeySDKPrivate.h" @@ -63,6 +65,8 @@ BOOL _incomingMessagesAlertShowing; BOOL _didEnterBackgroundState; BOOL _networkRequestInProgress; + + BITFeedbackObservationMode _observationMode; } #pragma mark - Initialization @@ -214,14 +218,23 @@ } - (void)showFeedbackComposeView { + [self showFeedbackComposeViewWithPreparedItems:nil]; +} + +- (void)showFeedbackComposeViewWithPreparedItems:(NSArray *)items{ if (_currentFeedbackComposeViewController) { BITHockeyLog(@"INFO: update view already visible, aborting"); return; } - - [self showView:[self feedbackComposeViewController]]; + BITFeedbackComposeViewController *composeView = [self feedbackComposeViewController]; + [composeView prepareWithItems:items]; + [self showView:composeView]; } +- (void)showFeedbackComposeViewWithGeneratedScreenshot { + UIImage *screenshot = bit_screenshot(); + [self showFeedbackComposeViewWithPreparedItems:@[screenshot]]; +} #pragma mark - Manager Control @@ -1018,6 +1031,38 @@ } } +#pragma mark - Observation Handling + +-(void)setFeedbackObservationMode:(BITFeedbackObservationMode)mode { + if (mode == BITFeedbackObservationModeOnScreenshot){ + [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(screenshotNotificationReceived:) name:UIApplicationUserDidTakeScreenshotNotification object:nil]; + } +} + +-(void)screenshotNotificationReceived:(NSNotification *)notification { + +} + +-(void)extractLastPictureFromLibraryAndLaunchFeedback { + ALAssetsLibrary *library = [[ALAssetsLibrary alloc] init]; + + [library enumerateGroupsWithTypes:ALAssetsGroupSavedPhotos usingBlock:^(ALAssetsGroup *group, BOOL *stop) { + + [group setAssetsFilter:[ALAssetsFilter allPhotos]]; + + [group enumerateAssetsWithOptions:NSEnumerationReverse usingBlock:^(ALAsset *alAsset, NSUInteger index, BOOL *innerStop) { + + if (alAsset) { + ALAssetRepresentation *representation = [alAsset defaultRepresentation]; + UIImage *latestPhoto = [UIImage imageWithCGImage:[representation fullScreenImage]]; + + *stop = YES; *innerStop = YES; + + // [self sendTweet:latestPhoto]; + } + }]; + } failureBlock: nil]; +} @end