+ Finalized preliminary feedback support. Now comes the polish.

This commit is contained in:
moritz haarmann
2014-02-13 11:04:32 +01:00
parent 9b57875a47
commit 36371dcd30
7 changed files with 38 additions and 8 deletions

View File

@@ -351,7 +351,7 @@
NSString *text = self.textView.text;
[self.manager submitMessageWithText:text];
[self.manager submitMessageWithText:text andPhotos:self.photos];
[self dismissWithResult:BITFeedbackComposeResultSubmitted];
}

View File

@@ -837,6 +837,15 @@
[postBody appendData:[[NSString stringWithFormat:@"--%@--\r\n", boundary] dataUsingEncoding:NSUTF8StringEncoding]];
NSInteger photoIndex = 0;
for (UIImage *image in message.photos){
NSString *contentType = @"image/png";
NSData* imageData = UIImagePNGRepresentation(image);
[postBody appendData:[BITHockeyAppClient dataWithPostValue:imageData forKey:[NSString stringWithFormat:@"attachment%ld", (long)photoIndex] contentType:contentType boundary:boundary]];
photoIndex++;
}
[request setHTTPBody:postBody];
}
@@ -971,11 +980,12 @@
}
}
- (void)submitMessageWithText:(NSString *)text {
- (void)submitMessageWithText:(NSString *)text andPhotos:(NSArray *)photos {
BITFeedbackMessage *message = [[BITFeedbackMessage alloc] init];
message.text = text;
[message setStatus:BITFeedbackMessageStatusSendPending];
[message setToken:[self uuidAsLowerCaseAndShortened]];
[message setToken:[self uuidAsLowerCaseAndShortened]];
[message setPhotos:photos];
[message setUserMessage:YES];
[_feedbackList addObject:message];

View File

@@ -65,7 +65,7 @@
- (NSUInteger)numberOfMessages;
- (BITFeedbackMessage *)messageAtIndex:(NSUInteger)index;
- (void)submitMessageWithText:(NSString *)text;
- (void)submitMessageWithText:(NSString *)text andPhotos:(NSArray *)photos;
- (void)submitPendingMessages;
// Returns YES if manual user data can be entered, required or optional

View File

@@ -69,6 +69,7 @@ typedef NS_ENUM(NSInteger, BITFeedbackMessageStatus) {
@property (nonatomic, copy) NSDate *date;
@property (nonatomic, copy) NSNumber *id;
@property (nonatomic, copy) NSString *token;
@property (nonatomic, strong) NSArray *photos;
@property (nonatomic) BITFeedbackMessageStatus status;
@property (nonatomic) BOOL userMessage;

View File

@@ -42,6 +42,7 @@
_email = nil;
_date = [[NSDate alloc] init];
_token = nil;
_photos = nil;
_id = [[NSNumber alloc] initWithInteger:0];
_status = BITFeedbackMessageStatusSendPending;
_userMessage = NO;
@@ -59,6 +60,7 @@
[encoder encodeObject:self.email forKey:@"email"];
[encoder encodeObject:self.date forKey:@"date"];
[encoder encodeObject:self.id forKey:@"id"];
[encoder encodeObject:self.photos forKey:@"photos"];
[encoder encodeInteger:self.status forKey:@"status"];
[encoder encodeBool:self.userMessage forKey:@"userMessage"];
[encoder encodeObject:self.token forKey:@"token"];
@@ -72,6 +74,7 @@
self.email = [decoder decodeObjectForKey:@"email"];
self.date = [decoder decodeObjectForKey:@"date"];
self.id = [decoder decodeObjectForKey:@"id"];
self.photos = [decoder decodeObjectForKey:@"photos"];
self.status = (BITFeedbackMessageStatus)[decoder decodeIntegerForKey:@"status"];
self.userMessage = [decoder decodeBoolForKey:@"userMessage"];
self.token = [decoder decodeObjectForKey:@"token"];

View File

@@ -118,8 +118,8 @@
#pragma mark - Helpers
/**
* create a post body from the given value, key and boundary
* c/p from HockeyBaseManager
* create a post body from the given value, key and boundary. This is a convenience call to
* dataWithPostValue:forKey:contentType:boundary and aimed at NSString-content.
*
* @param value -
* @param key -
@@ -128,4 +128,16 @@
* @return NSData instance configured to be attached on a (post) URLRequest
*/
+ (NSData *)dataWithPostValue:(NSString *)value forKey:(NSString *)key boundary:(NSString *) boundary;
/**
* create a post body from the given value, key and boundary and content type.
*
* @param value -
* @param key -
* @param boundary -
*
* @return NSData instance configured to be attached on a (post) URLRequest
*/
+ (NSData *)dataWithPostValue:(NSData *)value forKey:(NSString *)key contentType:(NSString *)contentType boundary:(NSString *) boundary;
@end

View File

@@ -85,12 +85,16 @@
}
+ (NSData *)dataWithPostValue:(NSString *)value forKey:(NSString *)key boundary:(NSString *) boundary {
return [self dataWithPostValue:[value dataUsingEncoding:NSUTF8StringEncoding] forKey:key contentType:@"text" boundary:boundary];
}
+ (NSData *)dataWithPostValue:(NSData *)value forKey:(NSString *)key contentType:(NSString *)contentType boundary:(NSString *) boundary {
NSMutableData *postBody = [NSMutableData data];
[postBody appendData:[[NSString stringWithFormat:@"--%@\r\n", boundary] dataUsingEncoding:NSUTF8StringEncoding]];
[postBody appendData:[[NSString stringWithFormat:@"Content-Disposition: form-data; name=\"%@\";\r\n", key] dataUsingEncoding:NSUTF8StringEncoding]];
[postBody appendData:[[NSString stringWithFormat:@"Content-Type: text\r\n\r\n"] dataUsingEncoding:NSUTF8StringEncoding]];
[postBody appendData:[value dataUsingEncoding:NSUTF8StringEncoding]];
[postBody appendData:[[NSString stringWithFormat:@"Content-Type: %@\r\n\r\n", contentType] dataUsingEncoding:NSUTF8StringEncoding]];
[postBody appendData:value];
[postBody appendData:[@"\r\n" dataUsingEncoding:NSUTF8StringEncoding]];
return postBody;