|
|
@@ -13,6 +13,7 @@
|
|
|
#import "ZipArchive.h"
|
|
|
#import "DefaultAppearance.h"
|
|
|
#import "OLDataProvider.h"
|
|
|
+#import "AFHTTPSessionManager.h"
|
|
|
|
|
|
|
|
|
#define UNZIP_OPEN_FAILED 0
|
|
|
@@ -768,34 +769,136 @@
|
|
|
}
|
|
|
});
|
|
|
}
|
|
|
--(void) check_offline:(NSString*) ver useInternalAddress:(bool)buseinternaladdress
|
|
|
+-(void) upload_offline:(NSString*) ver useInternalAddress:(bool)buseinternaladdress
|
|
|
{
|
|
|
+ [self add_downloadlog:@"Begin sync, please wait."];
|
|
|
+ [self add_downloadlog:@"Prepare upload data."];
|
|
|
+ NSArray* arr_order=[OLDataProvider enumOfflineOrder];
|
|
|
+ NSDictionary* upjson=[OLDataProvider prepareUpload:arr_order];
|
|
|
+
|
|
|
+ NSString* upfile=upjson[@"file"];
|
|
|
|
|
|
+ {
|
|
|
+ NSData* data = [NSData dataWithContentsOfFile: upfile];
|
|
|
+ UIApplication * app = [UIApplication sharedApplication];
|
|
|
+ AppDelegate *appDelegate = (AppDelegate *)[app delegate];
|
|
|
+
|
|
|
+
|
|
|
+ AFHTTPRequestSerializer* serializer=[AFHTTPRequestSerializer serializer] ;
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ 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_OFFLINE parameters:params constructingBodyWithBlock:^(id<AFMultipartFormData> formData) {
|
|
|
+ [formData appendPartWithFileData:data name:@"upfile" fileName:[upfile lastPathComponent] mimeType:@"application/zip"];
|
|
|
+ } error:nil];
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ AFURLSessionManager *manager = [[AFURLSessionManager alloc] initWithSessionConfiguration:[NSURLSessionConfiguration defaultSessionConfiguration]];
|
|
|
+
|
|
|
+ NSProgress *progress = nil;
|
|
|
+
|
|
|
+ NSURLSessionUploadTask *uploadTask = [manager uploadTaskWithStreamedRequest:request progress:&progress completionHandler:^(NSURLResponse *response, id responseObject, NSError *error) {
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ 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);
|
|
|
+ [self add_downloadlog:err_msg];
|
|
|
+ [self add_downloadlog:@"Can not connect to server please try again."];
|
|
|
+ [self.settingUI onSyncFinish];
|
|
|
+
|
|
|
+ } 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* so_id=[RAUtils arr2string:arr_order separator:@"," trim:true brackets:@"'"];
|
|
|
+
|
|
|
+ [iSalesDB execSql:@"delete from offline_contact where not sync_data is null"];
|
|
|
+ [iSalesDB execSql:@"delete from wishlist"];
|
|
|
+ [iSalesDB execSql:[NSString stringWithFormat:@"delete from offline_order where so_id=in(%@)",so_id]];
|
|
|
+ [iSalesDB execSql:[NSString stringWithFormat:@"delete from offline_cart where so_no=in(%@)",so_id]];
|
|
|
+// NSDictionary* contactjson= upjson[@"contact"];
|
|
|
+// NSDictionary* wishlistjson= upjson[@"wishlist"];
|
|
|
+// NSDictionary* orderjson= upjson[@"order"];
|
|
|
+
|
|
|
+
|
|
|
+ [self download_offline:ver useInternalAddress:buseinternaladdress];
|
|
|
+
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ [self add_downloadlog:[json valueForKey:@"err_msg"]];
|
|
|
+ [self.settingUI onSyncFinish];
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ }
|
|
|
+ // [waitalert dismissWithClickedButtonIndex:0 animated:FALSE];
|
|
|
+ }];
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ [uploadTask resume];
|
|
|
+
|
|
|
+ }
|
|
|
|
|
|
|
|
|
+
|
|
|
+ return;
|
|
|
+}
|
|
|
+-(void) download_offline:(NSString*) ver useInternalAddress:(bool)buseinternaladdress
|
|
|
+{
|
|
|
if(self.downloading)
|
|
|
return;
|
|
|
|
|
|
-
|
|
|
- dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
|
|
|
-
|
|
|
-// [self add_downloadlog:@"Begin sync, please wait."];
|
|
|
-// [self add_downloadlog:@"Prepare upload data."];
|
|
|
-// NSArray* arr_order=[OLDataProvider enumOfflineOrder];
|
|
|
-// NSString* upfile=[OLDataProvider prepareUpload:arr_order];
|
|
|
-//
|
|
|
-// [OLDataProvider uploadFile:upfile];
|
|
|
-//
|
|
|
-//
|
|
|
-// [self.settingUI onSyncFinish];
|
|
|
-// return;
|
|
|
- self.downloading=true;
|
|
|
- NSUserDefaults *defaults =[NSUserDefaults standardUserDefaults];
|
|
|
-
|
|
|
- NSString* pvid = [defaults stringForKey:@"vid"] ;
|
|
|
-
|
|
|
+ self.downloading=true;
|
|
|
+ dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
|
|
|
+
|
|
|
+
|
|
|
|
|
|
+ NSUserDefaults *defaults =[NSUserDefaults standardUserDefaults];
|
|
|
+
|
|
|
+ NSString* pvid = [defaults stringForKey:@"vid"] ;
|
|
|
+
|
|
|
+
|
|
|
|
|
|
[self add_downloadlog:@"Checking offline data, this will take a few minute, please wait."];
|
|
|
|
|
|
@@ -807,7 +910,7 @@
|
|
|
[self add_downloadlog:@"Can not get offline data version, please try again later."];
|
|
|
[self.settingUI onSyncFinish];
|
|
|
dispatch_async(dispatch_get_main_queue(), ^{
|
|
|
- // self.downloadlog=nil;
|
|
|
+ // self.downloadlog=nil;
|
|
|
self.downloading=false;
|
|
|
});
|
|
|
return;
|
|
|
@@ -816,7 +919,7 @@
|
|
|
[ [ UIApplication sharedApplication] setIdleTimerDisabled:YES ] ;
|
|
|
NSMutableDictionary* download_json=nil;
|
|
|
|
|
|
-// NSString* vid=@"31f4d59d-c229-47e3-9270-e15425777186";
|
|
|
+ // NSString* vid=@"31f4d59d-c229-47e3-9270-e15425777186";
|
|
|
NSString* downSerial=[json valueForKey:@"downSerial"];
|
|
|
// sleep(3);
|
|
|
//UIAlertView * waitalert1 = [RAUtils waiting_alert:@"Please wait..." title:@"Server is preparing data for you"];
|
|
|
@@ -833,34 +936,7 @@
|
|
|
count++;
|
|
|
download_json=[[iSalesNetwork download_Offline:downSerial] mutableCopy];
|
|
|
|
|
|
- // int aaa=0;
|
|
|
-
|
|
|
- // dispatch_sync(dispatch_get_main_queue(), ^{
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
- // if([[download_json valueForKey:@"result"] intValue]==2)
|
|
|
- // {
|
|
|
- // preparing = false;
|
|
|
- // // [waitalert1 dismissWithClickedButtonIndex:0 animated:FALSE];
|
|
|
- // }
|
|
|
- // else if([[download_json valueForKey:@"result"] intValue]==1)
|
|
|
- // {
|
|
|
- // // preparing.
|
|
|
- // }
|
|
|
- // else
|
|
|
- // {
|
|
|
- // //wrong.
|
|
|
- // preparing = false;
|
|
|
- // // [waitalert1 dismissWithClickedButtonIndex:0 animated:FALSE];
|
|
|
- // // [RAUtils message_alert:@"Download data wrong, canceled." title:@"Offline" controller:self] ;
|
|
|
- //
|
|
|
- // }
|
|
|
-
|
|
|
-
|
|
|
- // });
|
|
|
-
|
|
|
+
|
|
|
|
|
|
|
|
|
}
|
|
|
@@ -870,7 +946,7 @@
|
|
|
{
|
|
|
[self add_downloadlog:@"Can not get offline data version, please try again later."];
|
|
|
dispatch_async(dispatch_get_main_queue(), ^{
|
|
|
-// self.downloadlog=nil;
|
|
|
+ // self.downloadlog=nil;
|
|
|
self.downloading=false;
|
|
|
});
|
|
|
[ [ UIApplication sharedApplication] setIdleTimerDisabled:NO ] ;
|
|
|
@@ -885,7 +961,7 @@
|
|
|
//没有找到更新包,当前是最新版本
|
|
|
[self add_downloadlog:@"You are up-to-date!"];
|
|
|
dispatch_async(dispatch_get_main_queue(), ^{
|
|
|
-// self.downloadlog=nil;
|
|
|
+ // self.downloadlog=nil;
|
|
|
self.downloading=false;
|
|
|
});
|
|
|
[ [ UIApplication sharedApplication] setIdleTimerDisabled:NO ] ;
|
|
|
@@ -904,17 +980,16 @@
|
|
|
}
|
|
|
|
|
|
}
|
|
|
- // int aaa=123;
|
|
|
-
|
|
|
- // });
|
|
|
-
|
|
|
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
- // });
|
|
|
});
|
|
|
+}
|
|
|
+-(void) check_offline:(NSString*) ver useInternalAddress:(bool)buseinternaladdress
|
|
|
+{
|
|
|
+
|
|
|
+
|
|
|
+ [self upload_offline:ver useInternalAddress:buseinternaladdress];
|
|
|
+
|
|
|
+
|
|
|
|
|
|
|
|
|
|