|
@@ -33,47 +33,47 @@
|
|
|
AppDelegate *appDelegate = (AppDelegate *)[app delegate];
|
|
AppDelegate *appDelegate = (AppDelegate *)[app delegate];
|
|
|
[appDelegate didRotated];
|
|
[appDelegate didRotated];
|
|
|
|
|
|
|
|
-// [CATransaction begin];
|
|
|
|
|
-// [CATransaction setAnimationDuration:0.5];
|
|
|
|
|
-// [CATransaction setAnimationTimingFunction:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut]];
|
|
|
|
|
-// // [self updatePreviewLayerForOrientation:toInterfaceOrientation];
|
|
|
|
|
-// _previewLayer.position = CGPointMake(CGRectGetMidX(rect), CGRectGetMidY(rect));
|
|
|
|
|
-//
|
|
|
|
|
-// // self.backgroundView.highLightRect = CGRectInset(self.focusZone.frame,6,6);
|
|
|
|
|
-// _previewLayer.bounds = rect;
|
|
|
|
|
-//
|
|
|
|
|
-// UIInterfaceOrientation orientation = [[UIApplication sharedApplication]statusBarOrientation];
|
|
|
|
|
-// switch (orientation) {
|
|
|
|
|
-//
|
|
|
|
|
-//
|
|
|
|
|
-//
|
|
|
|
|
-// case UIInterfaceOrientationPortrait:
|
|
|
|
|
-// // [_previewLayer setAffineTransform:CGAffineTransformMakeRotation(0)];
|
|
|
|
|
-//
|
|
|
|
|
-// _previewLayer.connection.videoOrientation=AVCaptureVideoOrientationPortrait;
|
|
|
|
|
-// break;
|
|
|
|
|
-// case UIInterfaceOrientationPortraitUpsideDown:
|
|
|
|
|
-// //[_previewLayer setAffineTransform:CGAffineTransformMakeRotation(M_PI)];
|
|
|
|
|
-// _previewLayer.connection.videoOrientation=AVCaptureVideoOrientationPortraitUpsideDown;
|
|
|
|
|
-// break;
|
|
|
|
|
-// case UIInterfaceOrientationLandscapeLeft:
|
|
|
|
|
-// // [_previewLayer setAffineTransform:CGAffineTransformMakeRotation(M_PI/2)];
|
|
|
|
|
-// _previewLayer.connection.videoOrientation=AVCaptureVideoOrientationLandscapeLeft;
|
|
|
|
|
-// break;
|
|
|
|
|
-// case UIInterfaceOrientationLandscapeRight:
|
|
|
|
|
-// // [_previewLayer setAffineTransform:CGAffineTransformMakeRotation(-M_PI/2)];
|
|
|
|
|
-// _previewLayer.connection.videoOrientation=AVCaptureVideoOrientationLandscapeRight;
|
|
|
|
|
-// break;
|
|
|
|
|
-// default:
|
|
|
|
|
-// break;
|
|
|
|
|
-// }
|
|
|
|
|
-// [CATransaction commit];
|
|
|
|
|
-
|
|
|
|
|
-
|
|
|
|
|
- NSTimeInterval animationDuration = 0.30f;
|
|
|
|
|
- [UIView beginAnimations:nil context:nil];
|
|
|
|
|
- [UIView setAnimationDuration:animationDuration];
|
|
|
|
|
-
|
|
|
|
|
|
|
+ // [CATransaction begin];
|
|
|
|
|
+ // [CATransaction setAnimationDuration:0.5];
|
|
|
|
|
+ // [CATransaction setAnimationTimingFunction:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut]];
|
|
|
|
|
+ // // [self updatePreviewLayerForOrientation:toInterfaceOrientation];
|
|
|
|
|
+ // _previewLayer.position = CGPointMake(CGRectGetMidX(rect), CGRectGetMidY(rect));
|
|
|
|
|
+ //
|
|
|
|
|
+ // // self.backgroundView.highLightRect = CGRectInset(self.focusZone.frame,6,6);
|
|
|
|
|
+ // _previewLayer.bounds = rect;
|
|
|
|
|
+ //
|
|
|
|
|
+ // UIInterfaceOrientation orientation = [[UIApplication sharedApplication]statusBarOrientation];
|
|
|
|
|
+ // switch (orientation) {
|
|
|
|
|
+ //
|
|
|
|
|
+ //
|
|
|
|
|
+ //
|
|
|
|
|
+ // case UIInterfaceOrientationPortrait:
|
|
|
|
|
+ // // [_previewLayer setAffineTransform:CGAffineTransformMakeRotation(0)];
|
|
|
|
|
+ //
|
|
|
|
|
+ // _previewLayer.connection.videoOrientation=AVCaptureVideoOrientationPortrait;
|
|
|
|
|
+ // break;
|
|
|
|
|
+ // case UIInterfaceOrientationPortraitUpsideDown:
|
|
|
|
|
+ // //[_previewLayer setAffineTransform:CGAffineTransformMakeRotation(M_PI)];
|
|
|
|
|
+ // _previewLayer.connection.videoOrientation=AVCaptureVideoOrientationPortraitUpsideDown;
|
|
|
|
|
+ // break;
|
|
|
|
|
+ // case UIInterfaceOrientationLandscapeLeft:
|
|
|
|
|
+ // // [_previewLayer setAffineTransform:CGAffineTransformMakeRotation(M_PI/2)];
|
|
|
|
|
+ // _previewLayer.connection.videoOrientation=AVCaptureVideoOrientationLandscapeLeft;
|
|
|
|
|
+ // break;
|
|
|
|
|
+ // case UIInterfaceOrientationLandscapeRight:
|
|
|
|
|
+ // // [_previewLayer setAffineTransform:CGAffineTransformMakeRotation(-M_PI/2)];
|
|
|
|
|
+ // _previewLayer.connection.videoOrientation=AVCaptureVideoOrientationLandscapeRight;
|
|
|
|
|
+ // break;
|
|
|
|
|
+ // default:
|
|
|
|
|
+ // break;
|
|
|
|
|
+ // }
|
|
|
|
|
+ // [CATransaction commit];
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+ NSTimeInterval animationDuration = 0.30f;
|
|
|
|
|
+ [UIView beginAnimations:nil context:nil];
|
|
|
|
|
+ [UIView setAnimationDuration:animationDuration];
|
|
|
|
|
+
|
|
|
UIInterfaceOrientation orientation = [[UIApplication sharedApplication]statusBarOrientation];
|
|
UIInterfaceOrientation orientation = [[UIApplication sharedApplication]statusBarOrientation];
|
|
|
if (UIInterfaceOrientationIsLandscape(orientation))
|
|
if (UIInterfaceOrientationIsLandscape(orientation))
|
|
|
{
|
|
{
|
|
@@ -94,9 +94,9 @@
|
|
|
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- [UIView commitAnimations];
|
|
|
|
|
|
|
+ [UIView commitAnimations];
|
|
|
|
|
+
|
|
|
|
|
|
|
|
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@@ -120,9 +120,9 @@
|
|
|
|
|
|
|
|
UIApplication * app = [UIApplication sharedApplication];
|
|
UIApplication * app = [UIApplication sharedApplication];
|
|
|
AppDelegate *appDelegate = (AppDelegate *)[app delegate];
|
|
AppDelegate *appDelegate = (AppDelegate *)[app delegate];
|
|
|
-// [appDelegate didRotated];
|
|
|
|
|
|
|
+ // [appDelegate didRotated];
|
|
|
|
|
+
|
|
|
|
|
|
|
|
-
|
|
|
|
|
|
|
|
|
|
NSTimeInterval animationDuration = 0.30f;
|
|
NSTimeInterval animationDuration = 0.30f;
|
|
|
[UIView beginAnimations:nil context:nil];
|
|
[UIView beginAnimations:nil context:nil];
|
|
@@ -210,115 +210,123 @@
|
|
|
}
|
|
}
|
|
|
self.uploadProgress.progress = 0;
|
|
self.uploadProgress.progress = 0;
|
|
|
|
|
|
|
|
-
|
|
|
|
|
- // UIAlertView * waitalert = [[UIAlertView alloc] initWithTitle:@"wait" message:@"uploading" delegate:nil cancelButtonTitle:nil otherButtonTitles:nil, nil];
|
|
|
|
|
- // [waitalert show];
|
|
|
|
|
-
|
|
|
|
|
- NSData *imageData = UIImagePNGRepresentation(self.imgview.image);
|
|
|
|
|
-
|
|
|
|
|
- AFHTTPRequestSerializer* serializer=[AFHTTPRequestSerializer serializer] ;
|
|
|
|
|
-
|
|
|
|
|
-
|
|
|
|
|
-
|
|
|
|
|
- NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
|
|
|
|
|
AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
|
|
AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
|
|
|
- if(appDelegate.user!=nil)
|
|
|
|
|
- [params setValue:appDelegate.user forKey:@"user"];
|
|
|
|
|
-// if(appDelegate.contact_id!=nil)
|
|
|
|
|
-// [params setValue:appDelegate.contact_id forKey:@"contactId"];
|
|
|
|
|
- if(appDelegate.password!=nil)
|
|
|
|
|
- [params setValue:appDelegate.password forKey:@"password"];
|
|
|
|
|
-
|
|
|
|
|
-
|
|
|
|
|
- NSMutableURLRequest *request = [serializer multipartFormRequestWithMethod:@"POST" URLString:URL_UPLOAD_IMG parameters:params constructingBodyWithBlock:^(id<AFMultipartFormData> formData) {
|
|
|
|
|
- [formData appendPartWithFileData:imageData name:@"upfile" fileName:@"test.jpg" mimeType:@"image/png"];
|
|
|
|
|
- } error:nil];
|
|
|
|
|
-
|
|
|
|
|
-
|
|
|
|
|
- // NSMutableURLRequest *request = [[AFHTTPRequestSerializer serializer] multipartFormRequestWithMethod:@"POST" URLString:WEBSERVICE_URL parameters:nil constructingBodyWithBlock:^(id<AFMultipartFormData> formData) {
|
|
|
|
|
- // [formData appendPartWithFileData:imageData name:@"upfile" fileName:@"test" mimeType:@"image/png"];
|
|
|
|
|
- // } error:nil];
|
|
|
|
|
- //
|
|
|
|
|
- AFURLSessionManager *manager = [[AFURLSessionManager alloc] initWithSessionConfiguration:[NSURLSessionConfiguration defaultSessionConfiguration]];
|
|
|
|
|
-
|
|
|
|
|
-
|
|
|
|
|
-
|
|
|
|
|
- //manager.responseSerializer.acceptableContentTypes = [self.operationManager.responseSerializer.acceptableContentTypes setByAddingObject:@"text/html"];
|
|
|
|
|
-
|
|
|
|
|
-
|
|
|
|
|
-
|
|
|
|
|
- //
|
|
|
|
|
- NSProgress *progress = nil;
|
|
|
|
|
|
|
|
|
|
- NSURLSessionUploadTask *uploadTask = [manager uploadTaskWithStreamedRequest:request progress:&progress completionHandler:^(NSURLResponse *response, id responseObject, NSError *error) {
|
|
|
|
|
|
|
+ if(appDelegate.offline_mode)
|
|
|
|
|
+ {
|
|
|
|
|
|
|
|
- // [progress removeObserver:self forKeyPath:@"fractionCompleted"];
|
|
|
|
|
|
|
+ }
|
|
|
|
|
+ else
|
|
|
|
|
+ {
|
|
|
|
|
|
|
|
|
|
+ // UIAlertView * waitalert = [[UIAlertView alloc] initWithTitle:@"wait" message:@"uploading" delegate:nil cancelButtonTitle:nil otherButtonTitles:nil, nil];
|
|
|
|
|
+ // [waitalert show];
|
|
|
|
|
|
|
|
|
|
+ NSData *imageData = UIImagePNGRepresentation(self.imgview.image);
|
|
|
|
|
|
|
|
|
|
+ AFHTTPRequestSerializer* serializer=[AFHTTPRequestSerializer serializer] ;
|
|
|
|
|
|
|
|
- if (error) {
|
|
|
|
|
-
|
|
|
|
|
- NSString* err_msg = [error localizedDescription];
|
|
|
|
|
- NSLog(@"%@",err_msg);// [self.view updateWithMessage:[NSString stringWithFormat:@"Error : %@!", error.debugDescription]];
|
|
|
|
|
-
|
|
|
|
|
-
|
|
|
|
|
- NSMutableString *str = [[NSMutableString alloc] initWithData:responseObject encoding:NSUTF8StringEncoding];
|
|
|
|
|
-
|
|
|
|
|
- NSLog(@"data string: %@",str);
|
|
|
|
|
- [RAUtils message_alert:@"Can not connect to server please try again." title:@"Upload Image" controller:self] ;
|
|
|
|
|
-
|
|
|
|
|
- } else {
|
|
|
|
|
- NSLog(@"response ");
|
|
|
|
|
-
|
|
|
|
|
-
|
|
|
|
|
-
|
|
|
|
|
- NSData *data = [NSJSONSerialization dataWithJSONObject:(NSDictionary*)responseObject options:kNilOptions error:nil];
|
|
|
|
|
-
|
|
|
|
|
- // 再将NSData转为字符串
|
|
|
|
|
- NSString *jsonStr = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
|
|
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+ NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
|
|
|
|
|
+
|
|
|
|
|
+ if(appDelegate.user!=nil)
|
|
|
|
|
+ [params setValue:appDelegate.user forKey:@"user"];
|
|
|
|
|
+ // if(appDelegate.contact_id!=nil)
|
|
|
|
|
+ // [params setValue:appDelegate.contact_id forKey:@"contactId"];
|
|
|
|
|
+ if(appDelegate.password!=nil)
|
|
|
|
|
+ [params setValue:appDelegate.password forKey:@"password"];
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+ NSMutableURLRequest *request = [serializer multipartFormRequestWithMethod:@"POST" URLString:URL_UPLOAD_IMG parameters:params constructingBodyWithBlock:^(id<AFMultipartFormData> formData) {
|
|
|
|
|
+ [formData appendPartWithFileData:imageData name:@"upfile" fileName:@"test.jpg" mimeType:@"image/png"];
|
|
|
|
|
+ } error:nil];
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+ // NSMutableURLRequest *request = [[AFHTTPRequestSerializer serializer] multipartFormRequestWithMethod:@"POST" URLString:WEBSERVICE_URL parameters:nil constructingBodyWithBlock:^(id<AFMultipartFormData> formData) {
|
|
|
|
|
+ // [formData appendPartWithFileData:imageData name:@"upfile" fileName:@"test" mimeType:@"image/png"];
|
|
|
|
|
+ // } error:nil];
|
|
|
|
|
+ //
|
|
|
|
|
+ AFURLSessionManager *manager = [[AFURLSessionManager alloc] initWithSessionConfiguration:[NSURLSessionConfiguration defaultSessionConfiguration]];
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+ //manager.responseSerializer.acceptableContentTypes = [self.operationManager.responseSerializer.acceptableContentTypes setByAddingObject:@"text/html"];
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+ //
|
|
|
|
|
+ NSProgress *progress = nil;
|
|
|
|
|
+
|
|
|
|
|
+ NSURLSessionUploadTask *uploadTask = [manager uploadTaskWithStreamedRequest:request progress:&progress completionHandler:^(NSURLResponse *response, id responseObject, NSError *error) {
|
|
|
|
|
|
|
|
- // NSMutableString *str = [[NSMutableString alloc] initWithData:responseObject encoding:NSUTF8StringEncoding];
|
|
|
|
|
|
|
+ // [progress removeObserver:self forKeyPath:@"fractionCompleted"];
|
|
|
|
|
|
|
|
- NSLog(@"data string: %@",jsonStr);
|
|
|
|
|
|
|
|
|
|
- NSDictionary* json = responseObject;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
- if([[json valueForKey:@"result"] intValue]==2)
|
|
|
|
|
- {
|
|
|
|
|
- NSString* img_url_down = json[@"img_url_aname"];
|
|
|
|
|
- NSString* img_url_up = json[@"img_url"];
|
|
|
|
|
-
|
|
|
|
|
- if(self.returnValue)
|
|
|
|
|
- self.returnValue(img_url_down,img_url_up,self.imgview.image);
|
|
|
|
|
-
|
|
|
|
|
- [self.navigationController popViewControllerAnimated:false];
|
|
|
|
|
- }
|
|
|
|
|
- else
|
|
|
|
|
- {
|
|
|
|
|
- [RAUtils message_alert:[json valueForKey:@"err_msg"] title:@"Upload Image" controller:self] ;
|
|
|
|
|
|
|
+ if (error) {
|
|
|
|
|
+
|
|
|
|
|
+ NSString* err_msg = [error localizedDescription];
|
|
|
|
|
+ NSLog(@"%@",err_msg);// [self.view updateWithMessage:[NSString stringWithFormat:@"Error : %@!", error.debugDescription]];
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+ NSMutableString *str = [[NSMutableString alloc] initWithData:responseObject encoding:NSUTF8StringEncoding];
|
|
|
|
|
+
|
|
|
|
|
+ NSLog(@"data string: %@",str);
|
|
|
|
|
+ [RAUtils message_alert:@"Can not connect to server please try again." title:@"Upload Image" controller:self] ;
|
|
|
|
|
+
|
|
|
|
|
+ } else {
|
|
|
|
|
+ NSLog(@"response ");
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+ NSData *data = [NSJSONSerialization dataWithJSONObject:(NSDictionary*)responseObject options:kNilOptions error:nil];
|
|
|
|
|
+
|
|
|
|
|
+ // 再将NSData转为字符串
|
|
|
|
|
+ NSString *jsonStr = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
|
|
|
|
|
+
|
|
|
|
|
+ // NSMutableString *str = [[NSMutableString alloc] initWithData:responseObject encoding:NSUTF8StringEncoding];
|
|
|
|
|
+
|
|
|
|
|
+ NSLog(@"data string: %@",jsonStr);
|
|
|
|
|
+
|
|
|
|
|
+ NSDictionary* json = responseObject;
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+ if([[json valueForKey:@"result"] intValue]==2)
|
|
|
|
|
+ {
|
|
|
|
|
+ NSString* img_url_down = json[@"img_url_aname"];
|
|
|
|
|
+ NSString* img_url_up = json[@"img_url"];
|
|
|
|
|
+
|
|
|
|
|
+ if(self.returnValue)
|
|
|
|
|
+ self.returnValue(img_url_down,img_url_up,self.imgview.image);
|
|
|
|
|
+
|
|
|
|
|
+ [self.navigationController popViewControllerAnimated:false];
|
|
|
|
|
+ }
|
|
|
|
|
+ else
|
|
|
|
|
+ {
|
|
|
|
|
+ [RAUtils message_alert:[json valueForKey:@"err_msg"] title:@"Upload Image" controller:self] ;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
-
|
|
|
|
|
- }
|
|
|
|
|
- // [waitalert dismissWithClickedButtonIndex:0 animated:FALSE];
|
|
|
|
|
- }];
|
|
|
|
|
-
|
|
|
|
|
-
|
|
|
|
|
-
|
|
|
|
|
-
|
|
|
|
|
- [self.uploadProgress setProgressWithUploadProgressOfTask:uploadTask animated:true];
|
|
|
|
|
- //
|
|
|
|
|
-
|
|
|
|
|
-
|
|
|
|
|
-
|
|
|
|
|
-
|
|
|
|
|
-
|
|
|
|
|
-
|
|
|
|
|
- [uploadTask resume];
|
|
|
|
|
-
|
|
|
|
|
-
|
|
|
|
|
|
|
+ // [waitalert dismissWithClickedButtonIndex:0 animated:FALSE];
|
|
|
|
|
+ }];
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+ [self.uploadProgress setProgressWithUploadProgressOfTask:uploadTask animated:true];
|
|
|
|
|
+ //
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+ [uploadTask resume];
|
|
|
|
|
+
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@@ -361,13 +369,13 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
/*
|
|
|
-#pragma mark - Navigation
|
|
|
|
|
-
|
|
|
|
|
-// In a storyboard-based application, you will often want to do a little preparation before navigation
|
|
|
|
|
-- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
|
|
|
|
|
- // Get the new view controller using [segue destinationViewController].
|
|
|
|
|
- // Pass the selected object to the new view controller.
|
|
|
|
|
-}
|
|
|
|
|
-*/
|
|
|
|
|
|
|
+ #pragma mark - Navigation
|
|
|
|
|
+
|
|
|
|
|
+ // In a storyboard-based application, you will often want to do a little preparation before navigation
|
|
|
|
|
+ - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
|
|
|
|
|
+ // Get the new view controller using [segue destinationViewController].
|
|
|
|
|
+ // Pass the selected object to the new view controller.
|
|
|
|
|
+ }
|
|
|
|
|
+ */
|
|
|
|
|
|
|
|
@end
|
|
@end
|