SyncControlPanelViewController.m 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203
  1. //
  2. // SyncControlPanelViewController.m
  3. // iSales-NPD
  4. //
  5. // Created by Ray on 7/8/16.
  6. // Copyright © 2016 United Software Applications, Inc. All rights reserved.
  7. //
  8. #import "SyncControlPanelViewController.h"
  9. #import "AppDelegate.h"
  10. #import "RAUtils.h"
  11. #import "DBUtil.h"
  12. @interface SyncControlPanelViewController ()
  13. @end
  14. @implementation SyncControlPanelViewController
  15. - (void)viewDidLoad {
  16. [super viewDidLoad];
  17. self.edgesForExtendedLayout = UIRectEdgeNone ;
  18. self.closeButton = [[UIBarButtonItem alloc] initWithImage:[[UIImage imageNamed:@"close"] imageWithRenderingMode:UIImageRenderingModeAutomatic]
  19. style:UIBarButtonItemStylePlain
  20. target:self
  21. action:@selector( onCloseClick:)];
  22. self.closeButton.enabled=false;
  23. self.navigationItem.rightBarButtonItem = self.closeButton;
  24. self.tv_log.layer.borderWidth=1 ; //边框粗细
  25. self.tv_log.layer.borderColor=[UIColor darkGrayColor].CGColor; //边框颜色
  26. UIApplication * app = [UIApplication sharedApplication];
  27. AppDelegate *appDelegate = (AppDelegate *)[app delegate];
  28. appDelegate.settingUI=self;
  29. // Do any additional setup after loading the view.
  30. }
  31. - (void)onCloseClick:(UIButton *)sender {
  32. // if(self.onDismissVC)
  33. // self.onDismissVC();
  34. [self dismissViewControllerAnimated:true completion:nil];
  35. }
  36. - (void)didReceiveMemoryWarning {
  37. [super didReceiveMemoryWarning];
  38. // Dispose of any resources that can be recreated.
  39. }
  40. -(void) onProgressUpdate
  41. {
  42. UIApplication * app = [UIApplication sharedApplication];
  43. AppDelegate *appDelegate = (AppDelegate *)[app delegate];
  44. self.progress_overall.progress= appDelegate.overall_progress;
  45. self.progress_current.progress= appDelegate.file_progress;
  46. }
  47. - (IBAction)onSendlogClick:(id)sender {
  48. UIApplication * app = [UIApplication sharedApplication];
  49. AppDelegate *appDelegate = (AppDelegate *)[app delegate];
  50. if(appDelegate.downloadlog.length==0)
  51. {
  52. [RAUtils message_alert:@"Log is empty sending canceled." title:@"Sending log" controller:self] ;
  53. return;
  54. }
  55. // NSString *path = NSTemporaryDirectory();
  56. // CFUUIDRef uuidObject = CFUUIDCreate(kCFAllocatorDefault);
  57. // Get the string representation of CFUUID object.
  58. // NSString* filename =[[NSUUID UUID] UUIDString];
  59. // NSString *filePath = [path stringByAppendingPathComponent:filename];
  60. MFMailComposeViewController *mc = [[MFMailComposeViewController alloc] init];
  61. if(mc==nil)
  62. return;
  63. mc.mailComposeDelegate = self;
  64. [mc setSubject:@"offline sync log"];
  65. [mc setToRecipients:@[@"ray.zhang@united-cn.net",@"RedAntSupport@united-us.net"]];
  66. NSDictionary *infoDictionary = [[NSBundle mainBundle] infoDictionary];
  67. // CFShow(infoDictionary);
  68. // app名称
  69. NSString *app_Name = [infoDictionary objectForKey:@"CFBundleName"];
  70. // app版本
  71. NSString *app_Version = [infoDictionary objectForKey:@"CFBundleShortVersionString"];
  72. // app build版本
  73. NSString *app_build = [infoDictionary objectForKey:@"CFBundleVersion"];
  74. NSString* appinfo =[NSString stringWithFormat:@"App info: %@ %@ build%@</br>",app_Name,app_Version,app_build];
  75. NSString* userinfo =[NSString stringWithFormat:@"login info: %@ </br>",appDelegate.user];
  76. // if(self.mail_content==nil)
  77. // self.mail_content=@"";
  78. NSString* htmlbody = [NSString stringWithFormat:@"<p>%@</p></br>%@%@</br></br>%@",@"Process description:",appinfo,userinfo,[appDelegate.downloadlog stringByReplacingOccurrencesOfString:@"\n" withString:@"</br>"]];
  79. [mc setMessageBody:htmlbody
  80. isHTML:YES];
  81. // NSData *data = [appDelegate.downloadlog dataUsingEncoding:NSUTF8StringEncoding];//[NSData dataWithContentsOfFile:filePath];
  82. // if(self.attachment_name.length>0)
  83. // filename = self.attachment_name;
  84. NSString* dbzippath= [DBUtil getdbzip:DBNAME];
  85. NSData *data1 = [NSData dataWithContentsOfFile:dbzippath];
  86. // filename=@"database.db";
  87. // [mc addAttachmentData:data mimeType:@"text/plain" fileName:filename];
  88. [mc addAttachmentData:data1 mimeType:@"application/zip" fileName:@"db.zip"];
  89. // [self presentModalViewController:mc animated:YES];
  90. [self presentViewController:mc animated:YES completion:nil];
  91. return;
  92. }
  93. -(void) onLogUpdate
  94. {
  95. UIApplication * app = [UIApplication sharedApplication];
  96. AppDelegate *appDelegate = (AppDelegate *)[app delegate];
  97. dispatch_async(dispatch_get_main_queue(), ^{
  98. self.tv_log.text = appDelegate.downloadlog;
  99. [self.tv_log scrollRangeToVisible:NSMakeRange(appDelegate.downloadlog.length-1,0)];
  100. });
  101. }
  102. -(void) onSyncFinish
  103. {
  104. self.closeButton.enabled=true;
  105. // UIApplication * app = [UIApplication sharedApplication];
  106. // AppDelegate *appDelegate = (AppDelegate *)[app delegate];
  107. // appDelegate.downloadlog=nil;
  108. // appDelegate.downloading=false;
  109. //// self.downloadlog=nil;
  110. //// self.downloading=false;
  111. // appDelegate.download_task=nil;
  112. // appDelegate.vid=nil;
  113. }
  114. /*
  115. #pragma mark - Navigation
  116. // In a storyboard-based application, you will often want to do a little preparation before navigation
  117. - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
  118. // Get the new view controller using [segue destinationViewController].
  119. // Pass the selected object to the new view controller.
  120. }
  121. */
  122. - (void)mailComposeController:(MFMailComposeViewController*)controller
  123. didFinishWithResult:(MFMailComposeResult)result
  124. error:(NSError*)error {
  125. switch (result)
  126. {
  127. case MFMailComposeResultCancelled:
  128. DebugLog(@"Mail send canceled...");
  129. break;
  130. case MFMailComposeResultSaved:
  131. DebugLog(@"Mail saved...");
  132. break;
  133. case MFMailComposeResultSent:
  134. DebugLog(@"Mail sent...");
  135. break;
  136. case MFMailComposeResultFailed:
  137. DebugLog(@"Mail send errored: %@...", [error localizedDescription]);
  138. break;
  139. default:
  140. break;
  141. }
  142. // [self dismissModalViewControllerAnimated:YES];
  143. [self dismissViewControllerAnimated:YES completion:nil];
  144. }
  145. @end