SyncControlPanelViewController.m 6.5 KB

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