KMVerificationWindowController.m 49 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070
  1. //
  2. // KMVerificationWindowController.m
  3. // EaseUS PDF Editor
  4. //
  5. // Created by 王帅 on 2018/5/8.
  6. //
  7. #import "KMVerificationWindowController.h"
  8. #import "KMVerificationViewController.h"
  9. #import "KMVerificationActivateViewController.h"
  10. #import "KMVerificationExpiredViewController.h"
  11. #import "KMVerificationTrialViewController.h"
  12. #import "KMVerificationAlertViewController.h"
  13. #import "KMActivityALertViewController.h"
  14. #import "KMVerificationInfoViewController.h"
  15. #import "VerificationManager.h"
  16. //#import "KMMailHelper.h"
  17. #import "GBDeviceInfo.h"
  18. #import "Reachability.h"
  19. //#import "SKInspectPublicTool.h"
  20. #import "KMRepeatTrialAlertController.h"
  21. #import "KMRepeatVerifyExpireController.h"
  22. #import <PDF_Reader_Pro-Swift.h>
  23. @interface KMVerificationWindowController ()
  24. @property (nonatomic, assign) KMVerificationType type;
  25. @property (nonatomic, assign) IBOutlet NSBox *box;
  26. @property (nonatomic, assign) IBOutlet NSProgressIndicator *progressIndicator;
  27. @property (nonatomic, retain) KMVerificationViewController *normalViewController;
  28. @property (nonatomic, retain) KMVerificationActivateViewController *activateViewController;
  29. @property (nonatomic, retain) KMVerificationExpiredViewController *expiredViewController;
  30. @property (nonatomic, retain) KMVerificationTrialViewController *trialViewController;
  31. @property (nonatomic, retain) KMVerificationAlertViewController *alertViewController;
  32. @property (nonatomic, retain) KMActivityALertViewController *activityAlertViewController;
  33. @property (nonatomic, retain) KMVerificationInfoViewController *infoViewController;
  34. @property (nonatomic, retain) KMRepeatTrialAlertController *repeatTrialAlertController;//二次试用提示弹窗
  35. @property (nonatomic, retain) KMRepeatVerifyExpireController *repeatTrialExpireController;//二次试用过期弹窗
  36. @property (nonatomic, retain) KMTrialSuccessController *trialSuccessController;
  37. @property (nonatomic, retain) KMUnbindAlertViewController *unbindAlertController;
  38. @end
  39. @implementation KMVerificationWindowController
  40. + (void)launching {
  41. [VerificationManager manager];
  42. }
  43. + (BOOL)allowsShowExpired {
  44. #if VERSION_DMG
  45. if ([VerificationManager manager].status == ActivityStatusTrialExpire &&
  46. [VerificationManager manager].secondTrialEnabled == NO) {
  47. if (![[NSUserDefaults standardUserDefaults] objectForKey:@"allowTrialExpireShowKeyDMG"]) {
  48. [[NSUserDefaults standardUserDefaults] setObject:@"YES" forKey:@"allowTrialExpireShowKeyDMG"];
  49. return YES;
  50. }
  51. }
  52. return NO;
  53. #else
  54. NSDate *lastTimeDate = [[NSUserDefaults standardUserDefaults] objectForKey:@"kVerificationExpiredShowLastTimeDateKay"];
  55. if (lastTimeDate) {
  56. NSDate *date = [NSDate date];
  57. NSTimeInterval time = [date timeIntervalSinceDate:lastTimeDate];
  58. int days = ((int)time)/(3600*24);
  59. if (days < 15) {
  60. return NO;
  61. }
  62. }
  63. #endif
  64. return YES;
  65. }
  66. + (void)showExpiredInfo {
  67. if (ActivityStatusTrialExpire == [VerificationManager manager].status) {
  68. if ([KMVerificationWindowController allowsShowExpired]) {
  69. KMVerificationWindowController *vc = [KMVerificationWindowController verificationWithType:KMVerificationTypeTrialExpired];
  70. [vc showWindow:nil];
  71. [[NSUserDefaults standardUserDefaults] setObject:[NSDate date] forKey:@"kVerificationExpiredShowLastTimeDateKay"];
  72. [[NSUserDefaults standardUserDefaults] synchronize];
  73. }
  74. } else if (ActivityStatusVerifExpire == [VerificationManager manager].status) {
  75. if ([KMVerificationWindowController allowsShowExpired]) {
  76. KMVerificationWindowController *vc = [KMVerificationWindowController verificationWithType:KMVerificationTypeActivateExpired];
  77. [vc showWindow:nil];
  78. [[NSUserDefaults standardUserDefaults] setObject:[NSDate date] forKey:@"kVerificationExpiredShowLastTimeDateKay"];
  79. [[NSUserDefaults standardUserDefaults] synchronize];
  80. }
  81. }
  82. }
  83. + (BOOL)allowRepeatTrialAlertShow {
  84. //是否在开启APP时弹出二次试用弹窗提示框
  85. if ([VerificationManager manager].secondTrialEnabled) {
  86. if (![[NSUserDefaults standardUserDefaults] objectForKey:@"allowRepeatTrialAlertShowKey"]) {
  87. return YES;
  88. }
  89. }
  90. return NO;
  91. }
  92. + (BOOL)allowRepeatTrialExpireShow {
  93. if ([VerificationManager manager].status == ActivityStatusTrialExpire &&
  94. [VerificationManager manager].trialTimes == 2) {
  95. if (![[NSUserDefaults standardUserDefaults] objectForKey:@"allowRepeatTrialExpireShowKey"]) {
  96. return YES;
  97. }
  98. }
  99. return NO;
  100. }
  101. static KMVerificationWindowController *_currentWindowController = nil;
  102. + (KMVerificationWindowController *)verificationWithType:(KMVerificationType)type {
  103. if (_currentWindowController) {
  104. if (type != _currentWindowController.type) {
  105. [_currentWindowController close];
  106. } else {
  107. return _currentWindowController;
  108. }
  109. }
  110. KMVerificationWindowController *vc = [[KMVerificationWindowController alloc] initWithType:type];
  111. return vc;
  112. }
  113. #pragma mark Init Methods
  114. - (instancetype)initWithType:(KMVerificationType)type {
  115. if (self = [super initWithWindowNibName:@"KMVerificationWindowController"]) {
  116. _type = type;
  117. }
  118. return self;
  119. }
  120. - (void)dealloc {
  121. [NSDistributedNotificationCenter.defaultCenter removeObserver:self];
  122. }
  123. #pragma mark - Getter Methods
  124. - (KMVerificationViewController *)normalViewController {
  125. if (!_normalViewController) {
  126. __block __typeof(self) blockSelf = self;
  127. _normalViewController = [[KMVerificationViewController alloc] init];
  128. _normalViewController.callback = ^(NSInteger index) {
  129. if (index == 0) {
  130. [blockSelf setContentView:blockSelf.activateViewController.view];
  131. } else if (index == 1) {
  132. if (KMVerificationTypeActivateExpired == self.type) {
  133. [blockSelf verificationFeedback];
  134. } else {
  135. [blockSelf close];
  136. }
  137. } else {
  138. [blockSelf verificationBuy];
  139. }
  140. };
  141. if (KMVerificationTypeTrialExpired == self.type) {
  142. _normalViewController.titleText = NSLocalizedString(@"Thank you for trying EaseUS PDF Editor", nil);
  143. _normalViewController.messageText = NSLocalizedString(@"Your trial has expired. Buy Full version to annotate and edit PDF files.", nil);
  144. } else {
  145. _normalViewController.titleText = NSLocalizedString(@"EaseUS PDF Editor Activation", nil);
  146. _normalViewController.messageText = NSLocalizedString(@"Buy Full Version to annotate and edit your PDF documents.", nil);
  147. }
  148. }
  149. return _normalViewController;
  150. }
  151. - (KMVerificationActivateViewController *)activateViewController {
  152. if (!_activateViewController) {
  153. __block __typeof(self) blockSelf = self;
  154. _activateViewController = [[KMVerificationActivateViewController alloc] init];
  155. _activateViewController.callback = ^(NSInteger index, NSString *string) {
  156. if (index == 0) {
  157. if (blockSelf.callback) {
  158. blockSelf.callback();
  159. blockSelf.callback = nil;
  160. [blockSelf close];
  161. } else {
  162. if (KMVerificationTypeTrial == blockSelf.type) {
  163. [blockSelf setContentView:blockSelf.trialViewController.view];
  164. } else if (KMVerificationTypeActivateExpired == blockSelf.type) {
  165. [blockSelf setContentView:blockSelf.expiredViewController.view];
  166. } else {
  167. [blockSelf setContentView:blockSelf.normalViewController.view];
  168. }
  169. }
  170. } else {
  171. if (blockSelf.type == KMVerificationTypeActivateAIInfo) {
  172. [blockSelf verificationActivateAIInfo:string];
  173. } else {
  174. [blockSelf verificationActivate:string];
  175. }
  176. }
  177. };
  178. if (self.type == KMVerificationTypeActivateAIInfo) {
  179. _activateViewController.type = self.type;
  180. }
  181. }
  182. return _activateViewController;
  183. }
  184. - (KMVerificationExpiredViewController *)expiredViewController {
  185. if (!_expiredViewController) {
  186. __block __typeof(self) blockSelf = self;
  187. _expiredViewController = [[KMVerificationExpiredViewController alloc] init];
  188. _expiredViewController.callback = ^(NSInteger index) {
  189. if (index == 0) {
  190. [blockSelf setContentView:blockSelf.activateViewController.view];
  191. } else {
  192. [blockSelf verificationFeedback];
  193. }
  194. };
  195. }
  196. return _expiredViewController;
  197. }
  198. - (KMVerificationTrialViewController *)trialViewController {
  199. if (!_trialViewController) {
  200. __block __typeof(self) blockSelf = self;
  201. _trialViewController = [[KMVerificationTrialViewController alloc] init];
  202. _trialViewController.callback = ^(NSInteger index, NSString *email, NSString *name) {
  203. if (index == 0) {
  204. [blockSelf setContentView:blockSelf.activateViewController.view];
  205. } else {
  206. [blockSelf verificationTrialForEmail:email name:name];
  207. }
  208. };
  209. }
  210. return _trialViewController;
  211. }
  212. - (KMVerificationAlertViewController *)alertViewController {
  213. if (!_alertViewController) {
  214. __block __typeof(self) blockSelf = self;
  215. _alertViewController = [[KMVerificationAlertViewController alloc] init];
  216. _alertViewController.callback = ^{
  217. [blockSelf close];
  218. };
  219. _alertViewController.buyActionHandle = ^{
  220. #if VERSION_DMG
  221. NSURL *url = [NSURL URLWithString:Swift_oc_Tool.Store_Link_OC];
  222. [[NSWorkspace sharedWorkspace] openURL:url];
  223. #endif
  224. [blockSelf close];
  225. };
  226. }
  227. return _alertViewController;
  228. }
  229. - (KMActivityALertViewController *)activityAlertViewController {
  230. if (!_activityAlertViewController) {
  231. __block __typeof(self) blockSelf = self;
  232. _activityAlertViewController = [[KMActivityALertViewController alloc] init];
  233. _activityAlertViewController.callback = ^{
  234. [blockSelf close];
  235. };
  236. }
  237. return _activityAlertViewController;
  238. }
  239. - (KMVerificationInfoViewController *)infoViewController {
  240. if (!_infoViewController) {
  241. __weak __typeof(self) blockSelf = self;
  242. _infoViewController = [[KMVerificationInfoViewController alloc] init];
  243. _infoViewController.callback = ^{
  244. [blockSelf close];
  245. };
  246. _infoViewController.unbindAction = ^{
  247. dispatch_async(dispatch_get_main_queue(), ^{
  248. //输入序列码
  249. KMVerificationWindowController *vc = [KMVerificationWindowController verificationWithType:KMVerificationTypeUnbindAlert];
  250. vc.callback = ^{
  251. };
  252. [vc showWindow:nil];
  253. });
  254. };
  255. }
  256. return _infoViewController;
  257. }
  258. - (KMRepeatTrialAlertController *)repeatTrialAlertController {
  259. if (!_repeatTrialAlertController) {
  260. __block __typeof(self) blockSelf = self;
  261. _repeatTrialAlertController = [[KMRepeatTrialAlertController alloc] init];
  262. _repeatTrialAlertController.callback = ^(NSInteger clickIndex, KMRepeatTrialAlertController * _Nonnull tRController) {
  263. if (clickIndex == 0) {
  264. //免费试用
  265. [blockSelf verificationTrialForEmail:[VerificationManager manager].email
  266. name:[VerificationManager manager].accountName] ;
  267. } else if (clickIndex == 1) {
  268. //了解更多
  269. // NSURL *url = [NSURL URLWithString:[NSString stringWithFormat:@"%@?utm_source=app_dmg&utm_medium=dmg_puw_sec_free_trial", Swift_oc_Tool.Store_Link_OC]];
  270. // [[NSWorkspace sharedWorkspace] openURL:url];
  271. // [blockSelf close];
  272. KMPurchaseCompareDMGWindowController *singleTon = [[KMPurchaseCompareDMGWindowController alloc] init];
  273. [singleTon showWindow:nil];
  274. } else if (clickIndex == 2) {
  275. //输入序列码
  276. KMVerificationWindowController *vc = [KMVerificationWindowController verificationWithType:KMVerificationTypeActivate];
  277. vc.callback = ^{
  278. };
  279. [vc showWindow:nil];
  280. }
  281. };
  282. }
  283. return _repeatTrialAlertController;
  284. }
  285. - (KMRepeatVerifyExpireController *)repeatTrialExpireController {
  286. if (!_repeatTrialExpireController) {
  287. __block __typeof(self) blockSelf = self;
  288. _repeatTrialExpireController = [[KMRepeatVerifyExpireController alloc] init];
  289. _repeatTrialExpireController.callback = ^(NSInteger clickIndex, KMRepeatVerifyExpireController * _Nonnull tRController) {
  290. if (clickIndex == 0) {
  291. [blockSelf setContentView:blockSelf.activateViewController.view];
  292. } else if (clickIndex == 1) {
  293. [blockSelf close];
  294. } else if (clickIndex == 2) {
  295. [blockSelf verificationBuy];
  296. }
  297. };
  298. }
  299. return _repeatTrialExpireController;
  300. }
  301. - (KMTrialSuccessController *)trialSuccessController {
  302. if (!_trialSuccessController) {
  303. __block __typeof(self) blockSelf = self;
  304. _trialSuccessController = [[KMTrialSuccessController alloc] init];
  305. _trialSuccessController.clickHandle = ^(KMTrialSuccessController * _Nonnull controller) {
  306. [blockSelf close];
  307. };
  308. }
  309. return _trialSuccessController;
  310. }
  311. - (KMUnbindAlertViewController *)unbindAlertController {
  312. if (!_unbindAlertController) {
  313. __weak typeof(self) weakSelf = self;
  314. _unbindAlertController = [[KMUnbindAlertViewController alloc] init];
  315. _unbindAlertController.unbundHandle = ^(KMUnbindAlertViewController * _Nonnull controller) {
  316. [weakSelf unbindAction];
  317. [weakSelf close];
  318. };
  319. }
  320. return _unbindAlertController;
  321. }
  322. #pragma mark - Window Methods
  323. - (void)windowDidLoad {
  324. [super windowDidLoad];
  325. // Implement this method to handle any initialization after your window controller's window has been loaded from its nib file.
  326. self.window.title = @"";
  327. [[self.window standardWindowButton:NSWindowZoomButton] setHidden:YES];
  328. [[self.window standardWindowButton:NSWindowMiniaturizeButton] setHidden:YES];
  329. [self updateViewInfo];
  330. [self updateViewColor];
  331. [NSDistributedNotificationCenter.defaultCenter addObserver:self selector:@selector(themeChanged:) name:@"AppleInterfaceThemeChangedNotification" object: nil];
  332. }
  333. - (void)updateViewInfo {
  334. if (KMVerificationTypeNormal == self.type) {
  335. [self setContentView:self.normalViewController.view];
  336. } else if (KMVerificationTypeActivate == self.type) {
  337. [self setContentView:self.activateViewController.view];
  338. } else if (KMVerificationTypeTrial == self.type) {
  339. [self setContentView:self.trialViewController.view];
  340. } else if (KMVerificationTypeActivateExpired == self.type) {
  341. [self setContentView:self.expiredViewController.view];
  342. } else if (KMVerificationTypeTrialExpired == self.type) {
  343. [self setContentView:self.normalViewController.view];
  344. } else if (KMVerificationTypeInfo == self.type) {
  345. [self setContentView:self.infoViewController.view];
  346. } else if (KMVerificationTypeRepeatTrialGuide == self.type) {
  347. self.window.title = @"";
  348. [self setContentView:self.repeatTrialAlertController.view];
  349. [[NSUserDefaults standardUserDefaults] setObject:@"YES" forKey:@"allowRepeatTrialAlertShowKey"];
  350. [[NSUserDefaults standardUserDefaults] synchronize];
  351. } else if (KMVerificationTypeRepeatTrialExpire == self.type) {
  352. [self setContentView:self.repeatTrialExpireController.view];
  353. [[NSUserDefaults standardUserDefaults] setObject:@"YES" forKey:@"allowRepeatTrialExpireShowKey"];
  354. [[NSUserDefaults standardUserDefaults] synchronize];
  355. } else if (self.type == KMVerificationTypeTrialSuccess ||
  356. self.type == KMVerificationTypeRepeatTrialSuccess) {
  357. [self setContentView:self.trialSuccessController.view];
  358. } else if (KMVerificationTypeActivateAIInfo == self.type) {
  359. [self setContentView:self.activateViewController.view];
  360. self.activateViewController.type = self.type;
  361. } else if (KMVerificationTypeUnbindAlert == self.type) {
  362. [self setContentView:self.unbindAlertController.view];
  363. }
  364. }
  365. - (void)updateViewColor {
  366. if (KMVerificationTypeNormal == self.type) {
  367. } else if (KMVerificationTypeActivate == self.type) {
  368. } else if (KMVerificationTypeTrial == self.type) {
  369. } else if (KMVerificationTypeActivateExpired == self.type) {
  370. } else if (KMVerificationTypeTrialExpired == self.type) {
  371. } else if (KMVerificationTypeInfo == self.type) {
  372. } else if (KMVerificationTypeRepeatTrialGuide == self.type) {
  373. [self.repeatTrialAlertController updateViewColor];
  374. } else if (KMVerificationTypeRepeatTrialExpire == self.type) {
  375. [self.repeatTrialExpireController updateViewColor];
  376. } else if (KMVerificationTypeTrialSuccess == self.type ||
  377. KMVerificationTypeRepeatTrialSuccess == self.type) {
  378. [self.trialSuccessController updateViewColor];
  379. } else if (KMVerificationTypeUnbindAlert == self.type) {
  380. [self.unbindAlertController updateViewColor];
  381. }
  382. }
  383. - (void)showWindow:(id)sender {
  384. if (!_currentWindowController) {
  385. _currentWindowController = self;
  386. }
  387. [super showWindow:sender];
  388. }
  389. - (void)windowWillClose:(NSNotification *)notification {
  390. if (_currentWindowController) {
  391. _currentWindowController = nil;
  392. }
  393. }
  394. #pragma mark - Setter
  395. - (void)setContentView:(NSView *)view {
  396. NSRect frame = self.window.frame;
  397. frame.origin.y -= view.frame.size.height-frame.size.height;
  398. frame.origin.x -= (view.frame.size.width-frame.size.width)/2.0;
  399. frame.size.width = view.frame.size.width;
  400. frame.size.height = view.frame.size.height;
  401. [self.box setContentView:view];
  402. [self.window setFrame:frame display:YES animate:YES];
  403. }
  404. #pragma mark - Private Methods
  405. - (void)verificationTrialForEmail:(NSString *)email name:(NSString *)name {
  406. if (email.length <= 0) {
  407. return;
  408. }
  409. if (![self isConnectionAvailable]) {
  410. NSAlert *alert = [NSAlert alertWithMessageText:NSLocalizedString(@"Connection Error", nil)
  411. defaultButton:NSLocalizedString(@"OK", nil)
  412. alternateButton:nil
  413. otherButton:nil
  414. informativeTextWithFormat:NSLocalizedString(@"Please make sure your internet connection is available.", nil), nil];
  415. [alert runModal];
  416. return;
  417. }
  418. __block __typeof(self) blockSelf = self;
  419. self.progressIndicator.hidden = NO;
  420. [self.progressIndicator startAnimation:nil];
  421. [self.trialViewController setEnabled:NO];
  422. [[VerificationManager manager] trialForDays:7 email:email name:name complention:^(ActivityStatus status, NSDictionary *info, NSError *error) {
  423. blockSelf.progressIndicator.hidden = YES;
  424. [blockSelf.progressIndicator stopAnimation:nil];
  425. [blockSelf.trialViewController setEnabled:YES];
  426. if (error ||
  427. status != ActivityStatusTrial) {
  428. NSAlert *alert = [NSAlert alertWithMessageText:NSLocalizedString(@"Activation Error", nil)
  429. defaultButton:NSLocalizedString(@"Try Again", nil)
  430. alternateButton:nil
  431. otherButton:nil
  432. informativeTextWithFormat:NSLocalizedString(@"Failed to sign up for the free trial. Please make sure your internet connection is available and try again later.", nil), nil];
  433. [alert runModal];
  434. } else {
  435. blockSelf.type = KMVerificationTypeTrialSuccess;
  436. [blockSelf updateViewInfo];
  437. }
  438. }];
  439. }
  440. - (void)verificationActivateAIInfo:(NSString *)license {
  441. if (license.length <= 0) {
  442. return;
  443. }
  444. if (![self isConnectionAvailable]) {
  445. NSAlert *alert = [NSAlert alertWithMessageText:NSLocalizedString(@"Connection Error", nil)
  446. defaultButton:NSLocalizedString(@"OK", nil)
  447. alternateButton:nil
  448. otherButton:nil
  449. informativeTextWithFormat:@"", nil];
  450. NSButton *accessryBtn = [[NSButton alloc] initWithFrame:CGRectMake(0, 0, 180, 44)];
  451. accessryBtn.autoresizingMask = NSViewMaxXMargin | NSViewMinYMargin | NSViewMaxYMargin;
  452. accessryBtn.bezelStyle = NSBezelStyleRegularSquare;
  453. accessryBtn.bordered = NO;
  454. accessryBtn.target = self;
  455. accessryBtn.action = @selector(accessryBtnClicked:);
  456. NSMutableAttributedString *mutAttrString = [[NSMutableAttributedString alloc] initWithString:NSLocalizedString(@"Please make sure your internet connection is available.", nil)];
  457. [mutAttrString addAttribute:NSUnderlineStyleAttributeName value:[NSNumber numberWithInteger:NSUnderlineStyleSingle] range:NSMakeRange(0, [mutAttrString length])];
  458. [mutAttrString addAttribute:NSFontAttributeName value:[NSFont systemFontOfSize:12] range:NSMakeRange(0, [mutAttrString length])];
  459. [mutAttrString addAttribute:NSForegroundColorAttributeName value:[KMAppearance KMColor_Interactive_M0] range:NSMakeRange(0, [mutAttrString length])];
  460. accessryBtn.attributedTitle = mutAttrString;
  461. NSRect rect = [mutAttrString boundingRectWithSize:CGSizeMake(180, MAXFLOAT) options:NSStringDrawingUsesLineFragmentOrigin | NSStringDrawingUsesFontLeading];
  462. CGRect frame = accessryBtn.frame;
  463. frame.size.height = rect.size.height;
  464. accessryBtn.frame = frame;
  465. alert.accessoryView = accessryBtn;
  466. [alert runModal];
  467. return;
  468. }
  469. __block __typeof(self) blockSelf = self;
  470. self.progressIndicator.hidden = NO;
  471. [self.progressIndicator startAnimation:nil];
  472. [self.activateViewController setEnabled:NO];
  473. NSDictionary *infoDic = @{@"cdkey":license};
  474. [[AIInfoManager defaultManager] activateAIWithInfo:infoDic complention:^(NSDictionary *info, NSError *error) {
  475. blockSelf.progressIndicator.hidden = YES;
  476. [blockSelf.progressIndicator stopAnimation:nil];
  477. [blockSelf.activateViewController setEnabled:YES];
  478. if (error) {
  479. NSString *tTitle0 = NSLocalizedString(@"The license you have entered is not correct. Please enter valid license.", nil);
  480. NSString *tTitle1 = NSLocalizedString(@"Please confirm your EaseUS PDF Editor AI license code through the email you provided when purchasing.", nil);
  481. NSString *message = [NSString stringWithFormat:@"%@\n\n%@", tTitle0, tTitle1];
  482. if (ActivityErrorTypeCDKeyEmpty == error.code) {
  483. message = [NSString stringWithFormat:@"%@\n\n%@", NSLocalizedString(@"License number can not be empty.", nil), @""];
  484. } else if (ActivityErrorTypeCDKeyNotExist == error.code) {
  485. message = [NSString stringWithFormat:@"%@\n\n%@", NSLocalizedString(@"License number does not exist.", nil), @""];
  486. } else if (ActivityErrorTypeOutNumber == error.code) {
  487. NSString *tMsg0 = NSLocalizedString(@"The devices connected to the license number has outnumbered.", nil);
  488. NSString *tMsg1 = NSLocalizedString(@"Please deactivate license on one of them, to use EaseUS PDF Editor on this computer", nil);
  489. message = [NSString stringWithFormat:@"%@\n\n%@", tMsg0, tMsg1];
  490. } else if (ActivityErrorTypeNetworkDisable == error.code) {
  491. message = NSLocalizedString(@"The network is unavailable.", nil);
  492. } else if (ActivityErrorTypeCDKeyExpire == error.code) {
  493. message = NSLocalizedString(@"The license number expired.", nil);
  494. } else if (ActivityErrorTypeInvalidInfo == error.code) {
  495. message = NSLocalizedString(@"Activation error. Please try to input correct license, or contact us.", nil);
  496. } else if (ActivityErrorTypeNotMatchProduct == error.code) {
  497. message = NSLocalizedString(@"The license number is wrong, please input right license which is for this app.", nil);
  498. } else if (ActivityErrorTypeFormatError == error.code) {
  499. message = NSLocalizedString(@"Error license. Please enter an AI license.", nil);
  500. }
  501. if ((ActivityErrorTypeUnknow == error.code) || (ActivityErrorTypeOutNumber == error.code) || (ActivityErrorTypeInvalidInfo == error.code)) {
  502. NSAlert *alert = [NSAlert alertWithMessageText:NSLocalizedString(@"Activation Error", nil)
  503. defaultButton:NSLocalizedString(@"Contact Us", nil)
  504. alternateButton:NSLocalizedString(@"Try Again", nil)
  505. otherButton:nil
  506. informativeTextWithFormat:message, nil];
  507. if ([alert runModal]) {
  508. [blockSelf verificationFeedback];
  509. }
  510. } else {
  511. if (ActivityErrorTypeNetworkDisable == error.code) {
  512. NSAlert *alert = [NSAlert alertWithMessageText:NSLocalizedString(@"Connection Error", nil)
  513. defaultButton:NSLocalizedString(@"OK", nil)
  514. alternateButton:nil
  515. otherButton:nil
  516. informativeTextWithFormat:@"", nil];
  517. NSButton *accessryBtn = [[NSButton alloc] initWithFrame:CGRectMake(0, 0, 180, 44)];
  518. accessryBtn.autoresizingMask = NSViewMaxXMargin | NSViewMinYMargin | NSViewMaxYMargin;
  519. accessryBtn.bezelStyle = NSBezelStyleRegularSquare;
  520. accessryBtn.bordered = NO;
  521. accessryBtn.target = self;
  522. accessryBtn.action = @selector(accessryBtnClicked:);
  523. NSMutableAttributedString *mutAttrString = [[NSMutableAttributedString alloc] initWithString:NSLocalizedString(@"Please make sure your internet connection is available.", nil)];
  524. [mutAttrString addAttribute:NSFontAttributeName value:[NSFont systemFontOfSize:12] range:NSMakeRange(0, [mutAttrString length])];
  525. [mutAttrString addAttribute:NSUnderlineStyleAttributeName value:[NSNumber numberWithInteger:NSUnderlineStyleSingle] range:NSMakeRange(0, [mutAttrString length])];
  526. [mutAttrString addAttribute:NSForegroundColorAttributeName value:[KMAppearance KMColor_Interactive_M0] range:NSMakeRange(0, [mutAttrString length])];
  527. accessryBtn.attributedTitle = mutAttrString;
  528. NSRect rect = [mutAttrString boundingRectWithSize:CGSizeMake(180, MAXFLOAT) options:NSStringDrawingUsesLineFragmentOrigin | NSStringDrawingUsesFontLeading];
  529. CGRect frame = accessryBtn.frame;
  530. frame.size.height = rect.size.height;
  531. accessryBtn.frame = frame;
  532. alert.accessoryView = accessryBtn;
  533. [alert runModal];
  534. } else {
  535. NSAlert *alert = [NSAlert alertWithMessageText:NSLocalizedString(@"Activation Error", nil)
  536. defaultButton:NSLocalizedString(@"Try Again", nil)
  537. alternateButton:nil
  538. otherButton:nil
  539. informativeTextWithFormat:message, nil];
  540. [alert runModal];
  541. }
  542. }
  543. } else {
  544. blockSelf.activityAlertViewController.alertTitle = NSLocalizedString(@"Successful Activation!", nil);
  545. blockSelf.activityAlertViewController.alertMessage = NSLocalizedString(@"Congratulations! You can start using EaseUS PDF Editor AI features.", nil);
  546. [blockSelf setContentView:blockSelf.activityAlertViewController.view];
  547. }
  548. }];
  549. }
  550. - (void)verificationActivate:(NSString *)license {
  551. if (license.length <= 0) {
  552. return;
  553. }
  554. if ([license hasPrefix:@"AI-"]) {
  555. NSAlert *alert = [NSAlert alertWithMessageText:NSLocalizedString(@"Activation Error", nil)
  556. defaultButton:NSLocalizedString(@"Try Again", nil)
  557. alternateButton:nil
  558. otherButton:nil
  559. informativeTextWithFormat:NSLocalizedString(@"To activate the AI license code, click “AI Tools” on the toolbar, then tap “My AI Credit” from the right panel.", nil), nil];
  560. [alert runModal];
  561. return;
  562. }
  563. if (![self isConnectionAvailable]) {
  564. NSAlert *alert = [NSAlert alertWithMessageText:NSLocalizedString(@"Connection Error", nil)
  565. defaultButton:NSLocalizedString(@"OK", nil)
  566. alternateButton:nil
  567. otherButton:nil
  568. informativeTextWithFormat:@"", nil];
  569. NSButton *accessryBtn = [[NSButton alloc] initWithFrame:CGRectMake(0, 0, 180, 44)];
  570. accessryBtn.autoresizingMask = NSViewMaxXMargin | NSViewMinYMargin | NSViewMaxYMargin;
  571. accessryBtn.bezelStyle = NSBezelStyleRegularSquare;
  572. accessryBtn.bordered = NO;
  573. accessryBtn.target = self;
  574. accessryBtn.action = @selector(accessryBtnClicked:);
  575. NSMutableAttributedString *mutAttrString = [[NSMutableAttributedString alloc] initWithString:NSLocalizedString(@"Please make sure your internet connection is available.", nil)];
  576. [mutAttrString addAttribute:NSUnderlineStyleAttributeName value:[NSNumber numberWithInteger:NSUnderlineStyleSingle] range:NSMakeRange(0, [mutAttrString length])];
  577. [mutAttrString addAttribute:NSFontAttributeName value:[NSFont systemFontOfSize:12] range:NSMakeRange(0, [mutAttrString length])];
  578. [mutAttrString addAttribute:NSForegroundColorAttributeName value:[KMAppearance KMColor_Interactive_M0] range:NSMakeRange(0, [mutAttrString length])];
  579. accessryBtn.attributedTitle = mutAttrString;
  580. NSRect rect = [mutAttrString boundingRectWithSize:CGSizeMake(180, MAXFLOAT) options:NSStringDrawingUsesLineFragmentOrigin | NSStringDrawingUsesFontLeading];
  581. CGRect frame = accessryBtn.frame;
  582. frame.size.height = rect.size.height;
  583. accessryBtn.frame = frame;
  584. alert.accessoryView = accessryBtn;
  585. [alert runModal];
  586. return;
  587. }
  588. __block __typeof(self) blockSelf = self;
  589. self.progressIndicator.hidden = NO;
  590. [self.progressIndicator startAnimation:nil];
  591. [self.activateViewController setEnabled:NO];
  592. NSDictionary *infoDic = @{@"cdkey":license};
  593. [[VerificationManager manager] activateDeviceWithInfo:infoDic complention:^(ActivityStatus status, NSDictionary *info, NSError *error) {
  594. blockSelf.progressIndicator.hidden = YES;
  595. [blockSelf.progressIndicator stopAnimation:nil];
  596. [blockSelf.activateViewController setEnabled:YES];
  597. if (error) {
  598. NSString *tTitle0 = NSLocalizedString(@"The license you have entered is not correct. Please enter valid license.", nil);
  599. NSString *tTitle1 = NSLocalizedString(@"If you have already purchased EaseUS PDF Editor for Mac, you should find your license in an email confirmation.", nil);
  600. NSString *message = [NSString stringWithFormat:@"%@\n\n%@", tTitle0, tTitle1];
  601. if (ActivityErrorTypeCDKeyEmpty == error.code) {
  602. message = [NSString stringWithFormat:@"%@\n\n%@", NSLocalizedString(@"License number can not be empty.", nil), @""];
  603. } else if (ActivityErrorTypeCDKeyNotExist == error.code) {
  604. message = [NSString stringWithFormat:@"%@\n\n%@", NSLocalizedString(@"License number does not exist.", nil), @""];
  605. } else if (ActivityErrorTypeOutNumber == error.code) {
  606. NSString *tMsg0 = NSLocalizedString(@"The devices connected to the license number has outnumbered.", nil);
  607. NSString *tMsg1 = NSLocalizedString(@"Please deactivate license on one of them, to use EaseUS PDF Editor on this computer", nil);
  608. message = [NSString stringWithFormat:@"%@\n\n%@", tMsg0, tMsg1];
  609. } else if (ActivityErrorTypeNetworkDisable == error.code) {
  610. message = NSLocalizedString(@"The network is unavailable.", nil);
  611. } else if (ActivityErrorTypeCDKeyExpire == error.code) {
  612. message = NSLocalizedString(@"The license number expired.", nil);
  613. } else if (ActivityErrorTypeInvalidInfo == error.code) {
  614. message = NSLocalizedString(@"Activation error. Please try to input correct license, or contact us.", nil);
  615. } else if (ActivityErrorTypeNotMatchProduct == error.code) {
  616. message = NSLocalizedString(@"The license number is wrong, please input right license which is for this app.", nil);
  617. } else if (ActivityErrorTypeFormatError == error.code) {
  618. message = NSLocalizedString(@"The license format is wrong. Please input correct license.", nil);
  619. }
  620. if ((ActivityErrorTypeUnknow == error.code) || (ActivityErrorTypeOutNumber == error.code) || (ActivityErrorTypeInvalidInfo == error.code)) {
  621. NSAlert *alert = [NSAlert alertWithMessageText:NSLocalizedString(@"Activation Error", nil)
  622. defaultButton:NSLocalizedString(@"Contact Us", nil)
  623. alternateButton:NSLocalizedString(@"Try Again", nil)
  624. otherButton:nil
  625. informativeTextWithFormat:message, nil];
  626. if ([alert runModal]) {
  627. [blockSelf verificationFeedback];
  628. }
  629. } else {
  630. if (ActivityErrorTypeNetworkDisable == error.code) {
  631. NSAlert *alert = [NSAlert alertWithMessageText:NSLocalizedString(@"Connection Error", nil)
  632. defaultButton:NSLocalizedString(@"OK", nil)
  633. alternateButton:nil
  634. otherButton:nil
  635. informativeTextWithFormat:@"", nil];
  636. NSButton *accessryBtn = [[NSButton alloc] initWithFrame:CGRectMake(0, 0, 180, 44)];
  637. accessryBtn.autoresizingMask = NSViewMaxXMargin | NSViewMinYMargin | NSViewMaxYMargin;
  638. accessryBtn.bezelStyle = NSBezelStyleRegularSquare;
  639. accessryBtn.bordered = NO;
  640. accessryBtn.target = self;
  641. accessryBtn.action = @selector(accessryBtnClicked:);
  642. NSMutableAttributedString *mutAttrString = [[NSMutableAttributedString alloc] initWithString:NSLocalizedString(@"Please make sure your internet connection is available.", nil)];
  643. [mutAttrString addAttribute:NSFontAttributeName value:[NSFont systemFontOfSize:12] range:NSMakeRange(0, [mutAttrString length])];
  644. [mutAttrString addAttribute:NSUnderlineStyleAttributeName value:[NSNumber numberWithInteger:NSUnderlineStyleSingle] range:NSMakeRange(0, [mutAttrString length])];
  645. [mutAttrString addAttribute:NSForegroundColorAttributeName value:[KMAppearance KMColor_Interactive_M0] range:NSMakeRange(0, [mutAttrString length])];
  646. accessryBtn.attributedTitle = mutAttrString;
  647. NSRect rect = [mutAttrString boundingRectWithSize:CGSizeMake(180, MAXFLOAT) options:NSStringDrawingUsesLineFragmentOrigin | NSStringDrawingUsesFontLeading];
  648. CGRect frame = accessryBtn.frame;
  649. frame.size.height = rect.size.height;
  650. accessryBtn.frame = frame;
  651. alert.accessoryView = accessryBtn;
  652. [alert runModal];
  653. } else {
  654. NSAlert *alert = [NSAlert alertWithMessageText:NSLocalizedString(@"Activation Error", nil)
  655. defaultButton:NSLocalizedString(@"Try Again", nil)
  656. alternateButton:nil
  657. otherButton:nil
  658. informativeTextWithFormat:message, nil];
  659. [alert runModal];
  660. }
  661. }
  662. } else {
  663. blockSelf.activityAlertViewController.alertTitle = NSLocalizedString(@"Successful Activation!", nil);
  664. blockSelf.activityAlertViewController.alertMessage = NSLocalizedString(@"Congrats! You are eligible to enjoy all advanced features in EaseUS PDF Editor.", nil);
  665. [blockSelf setContentView:blockSelf.activityAlertViewController.view];
  666. }
  667. }];
  668. }
  669. - (void)verificationBuy {
  670. #if VERSION_DMG
  671. // NSURL *url = [NSURL URLWithString:[NSString stringWithFormat:@"%@?utm_source=MacAppDmg&utm_campaign=StoreLink&utm_medium=PdfStore", Swift_oc_Tool.Store_Link_OC]];
  672. // [[NSWorkspace sharedWorkspace] openURL:url];
  673. KMPurchaseCompareDMGWindowController *singleTon = [[KMPurchaseCompareDMGWindowController alloc] init];
  674. [singleTon showWindow:nil];
  675. #endif
  676. }
  677. #pragma - 验证错误时反馈信息
  678. - (void)verificationFeedback {
  679. unsigned major, minor, bugFix;
  680. [self getSystemVersionMajor:&major minor:&minor bugFix:&bugFix];
  681. NSString *versionString = [NSString stringWithFormat:@"%@ - %u.%u.%u", [GBDeviceInfo deviceInfo].rawSystemInfoString, major, minor, bugFix];
  682. //application version (use short version preferentially)
  683. NSString *tAppVersion = [[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBundleShortVersionString"];
  684. if ([tAppVersion length] < 1) {
  685. tAppVersion = [[NSBundle mainBundle] objectForInfoDictionaryKey:(NSString *)kCFBundleVersionKey];
  686. }
  687. NSString* subjects = [[self getAppNameForSupportEmail] stringByAppendingFormat:NSLocalizedString(@" - %@;Verification Feedback;%@", nil) ,tAppVersion,versionString];
  688. [KMMailHelper newEmailWithContacts:@"support@easeus.com" andSubjects:subjects];
  689. }
  690. - (void)unbindAction {
  691. unsigned major, minor, bugFix;
  692. [self getSystemVersionMajor:&major minor:&minor bugFix:&bugFix];
  693. NSString *versionString = [NSString stringWithFormat:@"%@ - %u.%u.%u", [GBDeviceInfo deviceInfo].rawSystemInfoString, major, minor, bugFix];
  694. //application version (use short version preferentially)
  695. NSString *tAppVersion = [[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBundleShortVersionString"];
  696. if ([tAppVersion length] < 1) {
  697. tAppVersion = [[NSBundle mainBundle] objectForInfoDictionaryKey:(NSString *)kCFBundleVersionKey];
  698. }
  699. NSString *subjects = [[self getAppNameForEmail] stringByAppendingString:[NSString stringWithFormat:@" %@",@"Verification:"]];
  700. subjects = [subjects stringByAppendingString:[NSString stringWithFormat:@"%@;",tAppVersion]];
  701. subjects = [subjects stringByAppendingString:[NSString stringWithFormat:@" %@;",versionString]];
  702. subjects = [subjects stringByAppendingString:[NSString stringWithFormat:@" %@",NSLocalizedString(@"Unbind License Code:", nil)]];
  703. subjects = [subjects stringByAppendingString:[NSString stringWithFormat:@"%@",[VerificationManager manager].detailInfo[@"device"][@"unique_sn"]?:@""]];
  704. NSString *mailtoAddress = [NSString stringWithFormat:@"mailto:%@?Subject=%@&body=%@",@"support@easeus.com",[self URLEncodedString:subjects],[self URLEncodedString:NSLocalizedString(@"Hi EaseUS PDF Editor Team, I need to unbind my license code, thanks!\nNotice: Please do not modify the subtitle content", nil)]];
  705. [[NSWorkspace sharedWorkspace] openURL:[NSURL URLWithString:mailtoAddress]];
  706. }
  707. - (void)accessryBtnClicked:(NSButton *)btn {
  708. [[NSWorkspace sharedWorkspace] openURL:[NSURL URLWithString:@"https://www.pdfreaderpro.com/mac/help/activate-license-code-mac"]];
  709. }
  710. - (NSString *)URLEncodedString:(NSString *)string {
  711. CFStringRef stringRef = CFBridgingRetain(string);
  712. #pragma clang diagnostic push
  713. #pragma clang diagnostic ignored "-Wdeprecated-declarations"
  714. CFStringRef encoded = CFURLCreateStringByAddingPercentEscapes(kCFAllocatorDefault,
  715. stringRef,
  716. NULL,
  717. CFSTR("!*'\"();:@&=+$,/?%#[]% "),
  718. kCFStringEncodingUTF8);
  719. #pragma clang diagnostic pop
  720. CFRelease(stringRef);
  721. return CFBridgingRelease(encoded);
  722. }
  723. - (void)getSystemVersionMajor:(unsigned *)major
  724. minor:(unsigned *)minor
  725. bugFix:(unsigned *)bugFix {
  726. OSErr err;
  727. SInt32 systemVersion, versionMajor, versionMinor, versionBugFix;
  728. if ([[NSProcessInfo processInfo] respondsToSelector:@selector(operatingSystemVersion)]) {
  729. NSOperatingSystemVersion osSystemVersion = [[NSProcessInfo processInfo] operatingSystemVersion];
  730. *major = (unsigned)osSystemVersion.majorVersion;
  731. *minor = (unsigned)osSystemVersion.minorVersion;
  732. *bugFix = (unsigned)osSystemVersion.patchVersion;
  733. return;
  734. } else {
  735. #pragma clang diagnostic push
  736. #pragma clang diagnostic ignored "-Wdeprecated-declarations"
  737. if ((err = Gestalt(gestaltSystemVersion, &systemVersion)) != noErr) goto fail;
  738. if (systemVersion < 0x1040)
  739. {
  740. if (major) *major = ((systemVersion & 0xF000) >> 12) * 10 +
  741. ((systemVersion & 0x0F00) >> 8);
  742. if (minor) *minor = (systemVersion & 0x00F0) >> 4;
  743. if (bugFix) *bugFix = (systemVersion & 0x000F);
  744. }
  745. else
  746. {
  747. if ((err = Gestalt(gestaltSystemVersionMajor, &versionMajor)) != noErr) goto fail;
  748. if ((err = Gestalt(gestaltSystemVersionMinor, &versionMinor)) != noErr) goto fail;
  749. if ((err = Gestalt(gestaltSystemVersionBugFix, &versionBugFix)) != noErr) goto fail;
  750. if (major) *major = versionMajor;
  751. if (minor) *minor = versionMinor;
  752. if (bugFix) *bugFix = versionBugFix;
  753. }
  754. return;
  755. #pragma clang diagnostic pop
  756. }
  757. fail:
  758. NSLog(@"Unable to obtain system version: %ld", (long)err);
  759. if (major) *major = 10;
  760. if (minor) *minor = 0;
  761. if (bugFix) *bugFix = 0;
  762. }
  763. - (NSString *)getAppNameForEmail {
  764. NSString *tAppName = @"EaseUS PDF Editor Mac";
  765. #if VERSION_FREE
  766. #if VERSION_DMG
  767. #else
  768. // AppStore 免费版本
  769. tAppName = @"EaseUS PDF Editor";
  770. #endif
  771. #else
  772. // AppStore 付费版
  773. tAppName = @"EaseUS PDF Editor";
  774. #endif
  775. return tAppName;
  776. }
  777. - (NSString *)getAppNameForSupportEmail {
  778. NSString *tAppName = @"EaseUS PDF Editor";
  779. #if VERSION_FREE
  780. #if VERSION_DMG
  781. // 桌机版
  782. VerificationManager *tManager = [VerificationManager manager];
  783. switch ([tManager status]) {
  784. case ActivityStatusTrial:
  785. tAppName = @"EaseUS PDF Editor Trial";
  786. break;
  787. case ActivityStatusVerification:
  788. tAppName = @"EaseUS PDF Editor Verification";
  789. break;
  790. case ActivityStatusTrialExpire:
  791. tAppName = @"EaseUS PDF Editor TrialExpire";
  792. break;
  793. case ActivityStatusVerifExpire:
  794. tAppName = @"EaseUS PDF Editor VerifExpire";
  795. break;
  796. default:
  797. break;
  798. }
  799. #else
  800. // AppStore 免费版本
  801. tAppName = @"EaseUS PDF Editor";
  802. #endif
  803. #else
  804. // AppStore 付费版
  805. tAppName = @"EaseUS PDF Editor";
  806. #endif
  807. return tAppName;
  808. }
  809. - (BOOL)isConnectionAvailable {
  810. BOOL isExistenceNetwork = YES;
  811. Reachability *reach = [Reachability reachabilityWithHostname:@"www.apple.com"];
  812. switch ([reach currentReachabilityStatus]) {
  813. case NotReachable:
  814. isExistenceNetwork = NO;
  815. //NSLog(@"notReachable");
  816. break;
  817. case ReachableViaWiFi:
  818. isExistenceNetwork = YES;
  819. //NSLog(@"WIFI");
  820. break;
  821. case ReachableViaWWAN:
  822. isExistenceNetwork = YES;
  823. //NSLog(@"3G");
  824. break;
  825. }
  826. if (NotReachable == [[Reachability reachabilityForInternetConnection] currentReachabilityStatus]) {
  827. return NO;
  828. }
  829. return YES;
  830. }
  831. #pragma mark - NSNotification
  832. - (void)themeChanged:(NSNotification *)notification {
  833. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.3 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
  834. [self updateViewColor];
  835. });
  836. }
  837. + (void)verificationFeedback {
  838. unsigned major, minor, bugFix;
  839. [self getSystemVersionMajor:&major minor:&minor bugFix:&bugFix];
  840. NSString *versionString = [NSString stringWithFormat:@"%@ - %u.%u.%u", [GBDeviceInfo deviceInfo].rawSystemInfoString, major, minor, bugFix];
  841. NSString *tAppVersion = [[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBundleShortVersionString"];
  842. if ([tAppVersion length] < 1)
  843. {
  844. tAppVersion = [[NSBundle mainBundle] objectForInfoDictionaryKey:(NSString *)kCFBundleVersionKey];
  845. }
  846. NSString* subjects = [[self getAppNameForSupportEmail] stringByAppendingFormat:NSLocalizedString(@" - %@;Verification Feedback;%@", nil) ,tAppVersion,versionString];
  847. [KMMailHelper newEmailWithContacts:@"support@easeus.com" andSubjects:subjects];
  848. }
  849. + (void)getSystemVersionMajor:(unsigned *)major
  850. minor:(unsigned *)minor
  851. bugFix:(unsigned *)bugFix;
  852. {
  853. OSErr err;
  854. SInt32 systemVersion, versionMajor, versionMinor, versionBugFix;
  855. if ([[NSProcessInfo processInfo] respondsToSelector:@selector(operatingSystemVersion)]) {
  856. NSOperatingSystemVersion osSystemVersion = [[NSProcessInfo processInfo] operatingSystemVersion];
  857. *major = (unsigned)osSystemVersion.majorVersion;
  858. *minor = (unsigned)osSystemVersion.minorVersion;
  859. *bugFix = (unsigned)osSystemVersion.patchVersion;
  860. return;
  861. } else {
  862. #pragma clang diagnostic push
  863. #pragma clang diagnostic ignored "-Wdeprecated-declarations"
  864. if ((err = Gestalt(gestaltSystemVersion, &systemVersion)) != noErr) goto fail;
  865. if (systemVersion < 0x1040)
  866. {
  867. if (major) *major = ((systemVersion & 0xF000) >> 12) * 10 +
  868. ((systemVersion & 0x0F00) >> 8);
  869. if (minor) *minor = (systemVersion & 0x00F0) >> 4;
  870. if (bugFix) *bugFix = (systemVersion & 0x000F);
  871. }
  872. else
  873. {
  874. if ((err = Gestalt(gestaltSystemVersionMajor, &versionMajor)) != noErr) goto fail;
  875. if ((err = Gestalt(gestaltSystemVersionMinor, &versionMinor)) != noErr) goto fail;
  876. if ((err = Gestalt(gestaltSystemVersionBugFix, &versionBugFix)) != noErr) goto fail;
  877. if (major) *major = versionMajor;
  878. if (minor) *minor = versionMinor;
  879. if (bugFix) *bugFix = versionBugFix;
  880. }
  881. return;
  882. #pragma clang diagnostic pop
  883. }
  884. fail:
  885. NSLog(@"Unable to obtain system version: %ld", (long)err);
  886. if (major) *major = 10;
  887. if (minor) *minor = 0;
  888. if (bugFix) *bugFix = 0;
  889. }
  890. + (NSString *)getAppNameForSupportEmail
  891. {
  892. NSString *tAppName = @"EaseUS PDF Editor";
  893. #if VERSION_FREE
  894. #if VERSION_DMG
  895. // 桌机版
  896. VerificationManager *tManager = [VerificationManager manager];
  897. switch ([tManager status]) {
  898. case ActivityStatusTrial:
  899. tAppName = @"EaseUS PDF Editor Trial";
  900. break;
  901. case ActivityStatusVerification:
  902. tAppName = @"EaseUS PDF Editor Verification";
  903. break;
  904. case ActivityStatusTrialExpire:
  905. tAppName = @"EaseUS PDF Editor TrialExpire";
  906. break;
  907. case ActivityStatusVerifExpire:
  908. tAppName = @"EaseUS PDF Editor VerifExpire";
  909. break;
  910. default:
  911. break;
  912. }
  913. #else
  914. // AppStore 免费版本
  915. tAppName = @"EaseUS PDF Editor";
  916. #endif
  917. #else
  918. // AppStore 付费版
  919. tAppName = @"EaseUS PDF Editor";
  920. #endif
  921. return tAppName;
  922. }
  923. @end