KMVerificationWindowController.m 49 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063
  1. //
  2. // KMVerificationWindowController.m
  3. // PDF Reader Pro Edition
  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 LynxPDF 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(@"LynxPDF 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:@"https://www.pdfreaderpro.com/store/pdftecheditor"];
  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:@"https://www.pdfreaderpro.com/store/pdftecheditor?utm_source=app_dmg&utm_medium=dmg_puw_sec_free_trial"];
  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 LynxPDF 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 LynxPDF 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 LynxPDF 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 LynxPDF 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. [[FMTrackEventManager defaultManager] lynxTrackEventWithEvent:@"ActiveDialog" withProperties:@{@"ActiveDialog_Trig":@"ActiveDialog_Trig_Invalid_ReturnData"}];
  605. [[FMTrackEventManager defaultManager] lynxTrackEventWithEvent:@"ActiveDialog" withProperties:@{@"ActiveDialog_Trig_UUID":[VerificationManager manager].udid}];
  606. message = [NSString stringWithFormat:@"%@\n\n%@", NSLocalizedString(@"License number does not exist.", nil), @""];
  607. } else if (ActivityErrorTypeOutNumber == error.code) {
  608. NSString *tMsg0 = NSLocalizedString(@"The devices connected to the license number has outnumbered.", nil);
  609. NSString *tMsg1 = NSLocalizedString(@"Please deactivate license on one of them, to use LynxPDF Editor on this computer", nil);
  610. message = [NSString stringWithFormat:@"%@\n\n%@", tMsg0, tMsg1];
  611. } else if (ActivityErrorTypeNetworkDisable == error.code) {
  612. message = NSLocalizedString(@"The network is unavailable.", nil);
  613. } else if (ActivityErrorTypeCDKeyExpire == error.code) {
  614. message = NSLocalizedString(@"The license number expired.", nil);
  615. } else if (ActivityErrorTypeInvalidInfo == error.code) {
  616. message = NSLocalizedString(@"Activation error. Please try to input correct license, or contact us.", nil);
  617. } else if (ActivityErrorTypeNotMatchProduct == error.code) {
  618. message = NSLocalizedString(@"The license number is wrong, please input right license which is for this app.", nil);
  619. } else if (ActivityErrorTypeFormatError == error.code) {
  620. message = NSLocalizedString(@"The license format is wrong. Please input correct license.", nil);
  621. }
  622. if (error.code == ActivityErrorTypeUnknow) {
  623. [[FMTrackEventManager defaultManager] lynxTrackEventWithEvent:@"ActiveDialog" withProperties:@{@"ActiveDialog_Trig":@"ActiveDialog_Trig_Invalid_ReturnNoData"}];
  624. }
  625. if ((ActivityErrorTypeUnknow == error.code) ||
  626. (ActivityErrorTypeOutNumber == error.code) ||
  627. (ActivityErrorTypeInvalidInfo == error.code)) {
  628. NSAlert *alert = [NSAlert alertWithMessageText:NSLocalizedString(@"Activation Error", nil)
  629. defaultButton:NSLocalizedString(@"Contact Us", nil)
  630. alternateButton:NSLocalizedString(@"Try Again", nil)
  631. otherButton:nil
  632. informativeTextWithFormat:message, nil];
  633. if ([alert runModal]) {
  634. [blockSelf verificationFeedback];
  635. }
  636. } else {
  637. if (ActivityErrorTypeNetworkDisable == error.code) {
  638. NSAlert *alert = [NSAlert alertWithMessageText:NSLocalizedString(@"Connection Error", nil)
  639. defaultButton:NSLocalizedString(@"OK", nil)
  640. alternateButton:nil
  641. otherButton:nil
  642. informativeTextWithFormat:@"", nil];
  643. NSButton *accessryBtn = [[NSButton alloc] initWithFrame:CGRectMake(0, 0, 180, 44)];
  644. accessryBtn.autoresizingMask = NSViewMaxXMargin | NSViewMinYMargin | NSViewMaxYMargin;
  645. accessryBtn.bezelStyle = NSBezelStyleRegularSquare;
  646. accessryBtn.bordered = NO;
  647. accessryBtn.target = self;
  648. accessryBtn.action = @selector(accessryBtnClicked:);
  649. NSMutableAttributedString *mutAttrString = [[NSMutableAttributedString alloc] initWithString:NSLocalizedString(@"Please make sure your internet connection is available.", nil)];
  650. [mutAttrString addAttribute:NSFontAttributeName value:[NSFont systemFontOfSize:12] range:NSMakeRange(0, [mutAttrString length])];
  651. [mutAttrString addAttribute:NSUnderlineStyleAttributeName value:[NSNumber numberWithInteger:NSUnderlineStyleSingle] range:NSMakeRange(0, [mutAttrString length])];
  652. [mutAttrString addAttribute:NSForegroundColorAttributeName value:[KMAppearance KMColor_Interactive_M0] range:NSMakeRange(0, [mutAttrString length])];
  653. accessryBtn.attributedTitle = mutAttrString;
  654. NSRect rect = [mutAttrString boundingRectWithSize:CGSizeMake(180, MAXFLOAT) options:NSStringDrawingUsesLineFragmentOrigin | NSStringDrawingUsesFontLeading];
  655. CGRect frame = accessryBtn.frame;
  656. frame.size.height = rect.size.height;
  657. accessryBtn.frame = frame;
  658. alert.accessoryView = accessryBtn;
  659. [alert runModal];
  660. } else {
  661. [[FMTrackEventManager defaultManager] lynxTrackEventWithEvent:@"ActiveDialog" withProperties:@{@"ActiveDialog_Trig":@"ActiveDialog_Trig_Invalid_ReturnNoData"}];
  662. NSAlert *alert = [NSAlert alertWithMessageText:NSLocalizedString(@"Activation Error", nil)
  663. defaultButton:NSLocalizedString(@"Try Again", nil)
  664. alternateButton:nil
  665. otherButton:nil
  666. informativeTextWithFormat:message, nil];
  667. [alert runModal];
  668. }
  669. }
  670. } else {
  671. blockSelf.activityAlertViewController.alertTitle = NSLocalizedString(@"Successful Activation!", nil);
  672. blockSelf.activityAlertViewController.alertMessage = NSLocalizedString(@"Congrats! You are eligible to enjoy all advanced features in LynxPDF Editor.", nil);
  673. [blockSelf setContentView:blockSelf.activityAlertViewController.view];
  674. }
  675. }];
  676. }
  677. - (void)verificationBuy {
  678. #if VERSION_DMG
  679. NSURL *url = [NSURL URLWithString:@"https://www.pdfreaderpro.com/store/pdftecheditor?utm_source=MacAppDmg&utm_campaign=StoreLink&utm_medium=PdfStore"];
  680. [[NSWorkspace sharedWorkspace] openURL:url];
  681. // KMPurchaseCompareDMGWindowController *singleTon = [[KMPurchaseCompareDMGWindowController alloc] init];
  682. // [singleTon showWindow:nil];
  683. #endif
  684. }
  685. #pragma - 验证错误时反馈信息
  686. - (void)verificationFeedback {
  687. unsigned major, minor, bugFix;
  688. [self getSystemVersionMajor:&major minor:&minor bugFix:&bugFix];
  689. NSString *versionString = [NSString stringWithFormat:@"%@ - %u.%u.%u", [GBDeviceInfo deviceInfo].rawSystemInfoString, major, minor, bugFix];
  690. //application version (use short version preferentially)
  691. NSString *tAppVersion = [[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBundleShortVersionString"];
  692. if ([tAppVersion length] < 1) {
  693. tAppVersion = [[NSBundle mainBundle] objectForInfoDictionaryKey:(NSString *)kCFBundleVersionKey];
  694. }
  695. NSString* subjects = [[self getAppNameForSupportEmail] stringByAppendingFormat:NSLocalizedString(@" - %@;Verification Feedback;%@", nil) ,tAppVersion,versionString];
  696. [KMMailHelper newEmailWithContacts:@"support@pdfreaderpro.com" andSubjects:subjects];
  697. }
  698. - (void)unbindAction {
  699. unsigned major, minor, bugFix;
  700. [self getSystemVersionMajor:&major minor:&minor bugFix:&bugFix];
  701. NSString *versionString = [NSString stringWithFormat:@"%@ - %u.%u.%u", [GBDeviceInfo deviceInfo].rawSystemInfoString, major, minor, bugFix];
  702. //application version (use short version preferentially)
  703. NSString *tAppVersion = [[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBundleShortVersionString"];
  704. if ([tAppVersion length] < 1) {
  705. tAppVersion = [[NSBundle mainBundle] objectForInfoDictionaryKey:(NSString *)kCFBundleVersionKey];
  706. }
  707. NSString *subjects = [[self getAppNameForEmail] stringByAppendingString:[NSString stringWithFormat:@" %@",@"Verification:"]];
  708. subjects = [subjects stringByAppendingString:[NSString stringWithFormat:@"%@;",tAppVersion]];
  709. subjects = [subjects stringByAppendingString:[NSString stringWithFormat:@" %@;",versionString]];
  710. subjects = [subjects stringByAppendingString:[NSString stringWithFormat:@" %@",NSLocalizedString(@"Unbind License Code:", nil)]];
  711. subjects = [subjects stringByAppendingString:[NSString stringWithFormat:@"%@",[VerificationManager manager].detailInfo[@"device"][@"unique_sn"]?:@""]];
  712. NSString *mailtoAddress = [NSString stringWithFormat:@"mailto:%@?Subject=%@&body=%@",@"support@pdfreaderpro.com",[self URLEncodedString:subjects],[self URLEncodedString:NSLocalizedString(@"Hi PDF Technologies Team, I need to unbind my license code, thanks!\nNotice: Please do not modify the subtitle content", nil)]];
  713. [[NSWorkspace sharedWorkspace] openURL:[NSURL URLWithString:mailtoAddress]];
  714. }
  715. - (void)accessryBtnClicked:(NSButton *)btn {
  716. [[NSWorkspace sharedWorkspace] openURL:[NSURL URLWithString:@"https://www.pdfreaderpro.com/mac/help/activate-license-code-mac"]];
  717. }
  718. - (NSString *)URLEncodedString:(NSString *)string {
  719. CFStringRef stringRef = CFBridgingRetain(string);
  720. #pragma clang diagnostic push
  721. #pragma clang diagnostic ignored "-Wdeprecated-declarations"
  722. CFStringRef encoded = CFURLCreateStringByAddingPercentEscapes(kCFAllocatorDefault,
  723. stringRef,
  724. NULL,
  725. CFSTR("!*'\"();:@&=+$,/?%#[]% "),
  726. kCFStringEncodingUTF8);
  727. #pragma clang diagnostic pop
  728. CFRelease(stringRef);
  729. return CFBridgingRelease(encoded);
  730. }
  731. - (void)getSystemVersionMajor:(unsigned *)major
  732. minor:(unsigned *)minor
  733. bugFix:(unsigned *)bugFix {
  734. OSErr err;
  735. SInt32 systemVersion, versionMajor, versionMinor, versionBugFix;
  736. if ([[NSProcessInfo processInfo] respondsToSelector:@selector(operatingSystemVersion)]) {
  737. NSOperatingSystemVersion osSystemVersion = [[NSProcessInfo processInfo] operatingSystemVersion];
  738. *major = (unsigned)osSystemVersion.majorVersion;
  739. *minor = (unsigned)osSystemVersion.minorVersion;
  740. *bugFix = (unsigned)osSystemVersion.patchVersion;
  741. return;
  742. } else {
  743. #pragma clang diagnostic push
  744. #pragma clang diagnostic ignored "-Wdeprecated-declarations"
  745. if ((err = Gestalt(gestaltSystemVersion, &systemVersion)) != noErr) goto fail;
  746. if (systemVersion < 0x1040)
  747. {
  748. if (major) *major = ((systemVersion & 0xF000) >> 12) * 10 +
  749. ((systemVersion & 0x0F00) >> 8);
  750. if (minor) *minor = (systemVersion & 0x00F0) >> 4;
  751. if (bugFix) *bugFix = (systemVersion & 0x000F);
  752. }
  753. else
  754. {
  755. if ((err = Gestalt(gestaltSystemVersionMajor, &versionMajor)) != noErr) goto fail;
  756. if ((err = Gestalt(gestaltSystemVersionMinor, &versionMinor)) != noErr) goto fail;
  757. if ((err = Gestalt(gestaltSystemVersionBugFix, &versionBugFix)) != noErr) goto fail;
  758. if (major) *major = versionMajor;
  759. if (minor) *minor = versionMinor;
  760. if (bugFix) *bugFix = versionBugFix;
  761. }
  762. return;
  763. #pragma clang diagnostic pop
  764. }
  765. fail:
  766. NSLog(@"Unable to obtain system version: %ld", (long)err);
  767. if (major) *major = 10;
  768. if (minor) *minor = 0;
  769. if (bugFix) *bugFix = 0;
  770. }
  771. - (NSString *)getAppNameForEmail {
  772. NSString *tAppName = @"LynxPDF Editor Mac";
  773. return tAppName;
  774. }
  775. - (NSString *)getAppNameForSupportEmail {
  776. NSString *tAppName = @"LynxPDF Editor";
  777. #if VERSION_FREE
  778. #if VERSION_DMG
  779. // 桌机版
  780. VerificationManager *tManager = [VerificationManager manager];
  781. switch ([tManager status]) {
  782. case ActivityStatusTrial:
  783. tAppName = @"LynxPDF Editor Mac Trial";
  784. break;
  785. case ActivityStatusVerification:
  786. tAppName = @"LynxPDF Editor Mac Verification";
  787. break;
  788. case ActivityStatusTrialExpire:
  789. tAppName = @"LynxPDF Editor Mac TrialExpire";
  790. break;
  791. case ActivityStatusVerifExpire:
  792. tAppName = @"LynxPDF Editor Mac VerifExpire";
  793. break;
  794. default:
  795. break;
  796. }
  797. #else
  798. // AppStore 免费版本
  799. tAppName = @"LynxPDF Editor Lite";
  800. #endif
  801. #else
  802. // AppStore 付费版
  803. tAppName = @"LynxPDF Editor Edition";
  804. #endif
  805. return tAppName;
  806. }
  807. - (BOOL)isConnectionAvailable {
  808. BOOL isExistenceNetwork = YES;
  809. Reachability *reach = [Reachability reachabilityWithHostname:@"www.apple.com"];
  810. switch ([reach currentReachabilityStatus]) {
  811. case NotReachable:
  812. isExistenceNetwork = NO;
  813. //NSLog(@"notReachable");
  814. break;
  815. case ReachableViaWiFi:
  816. isExistenceNetwork = YES;
  817. //NSLog(@"WIFI");
  818. break;
  819. case ReachableViaWWAN:
  820. isExistenceNetwork = YES;
  821. //NSLog(@"3G");
  822. break;
  823. }
  824. if (NotReachable == [[Reachability reachabilityForInternetConnection] currentReachabilityStatus]) {
  825. return NO;
  826. }
  827. return YES;
  828. }
  829. #pragma mark - NSNotification
  830. - (void)themeChanged:(NSNotification *)notification {
  831. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.3 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
  832. [self updateViewColor];
  833. });
  834. }
  835. + (void)verificationFeedback {
  836. unsigned major, minor, bugFix;
  837. [self getSystemVersionMajor:&major minor:&minor bugFix:&bugFix];
  838. NSString *versionString = [NSString stringWithFormat:@"%@ - %u.%u.%u", [GBDeviceInfo deviceInfo].rawSystemInfoString, major, minor, bugFix];
  839. NSString *tAppVersion = [[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBundleShortVersionString"];
  840. if ([tAppVersion length] < 1)
  841. {
  842. tAppVersion = [[NSBundle mainBundle] objectForInfoDictionaryKey:(NSString *)kCFBundleVersionKey];
  843. }
  844. NSString* subjects = [[self getAppNameForSupportEmail] stringByAppendingFormat:NSLocalizedString(@" - %@;Verification Feedback;%@", nil) ,tAppVersion,versionString];
  845. [KMMailHelper newEmailWithContacts:@"support@pdfreaderpro.com" andSubjects:subjects];
  846. }
  847. + (void)getSystemVersionMajor:(unsigned *)major
  848. minor:(unsigned *)minor
  849. bugFix:(unsigned *)bugFix;
  850. {
  851. OSErr err;
  852. SInt32 systemVersion, versionMajor, versionMinor, versionBugFix;
  853. if ([[NSProcessInfo processInfo] respondsToSelector:@selector(operatingSystemVersion)]) {
  854. NSOperatingSystemVersion osSystemVersion = [[NSProcessInfo processInfo] operatingSystemVersion];
  855. *major = (unsigned)osSystemVersion.majorVersion;
  856. *minor = (unsigned)osSystemVersion.minorVersion;
  857. *bugFix = (unsigned)osSystemVersion.patchVersion;
  858. return;
  859. } else {
  860. #pragma clang diagnostic push
  861. #pragma clang diagnostic ignored "-Wdeprecated-declarations"
  862. if ((err = Gestalt(gestaltSystemVersion, &systemVersion)) != noErr) goto fail;
  863. if (systemVersion < 0x1040)
  864. {
  865. if (major) *major = ((systemVersion & 0xF000) >> 12) * 10 +
  866. ((systemVersion & 0x0F00) >> 8);
  867. if (minor) *minor = (systemVersion & 0x00F0) >> 4;
  868. if (bugFix) *bugFix = (systemVersion & 0x000F);
  869. }
  870. else
  871. {
  872. if ((err = Gestalt(gestaltSystemVersionMajor, &versionMajor)) != noErr) goto fail;
  873. if ((err = Gestalt(gestaltSystemVersionMinor, &versionMinor)) != noErr) goto fail;
  874. if ((err = Gestalt(gestaltSystemVersionBugFix, &versionBugFix)) != noErr) goto fail;
  875. if (major) *major = versionMajor;
  876. if (minor) *minor = versionMinor;
  877. if (bugFix) *bugFix = versionBugFix;
  878. }
  879. return;
  880. #pragma clang diagnostic pop
  881. }
  882. fail:
  883. NSLog(@"Unable to obtain system version: %ld", (long)err);
  884. if (major) *major = 10;
  885. if (minor) *minor = 0;
  886. if (bugFix) *bugFix = 0;
  887. }
  888. + (NSString *)getAppNameForSupportEmail
  889. {
  890. NSString *tAppName = @"LynxPDF Editor";
  891. #if VERSION_FREE
  892. #if VERSION_DMG
  893. // 桌机版
  894. VerificationManager *tManager = [VerificationManager manager];
  895. switch ([tManager status]) {
  896. case ActivityStatusTrial:
  897. tAppName = @"LynxPDF Editor Trial";
  898. break;
  899. case ActivityStatusVerification:
  900. tAppName = @"LynxPDF Editor Verification";
  901. break;
  902. case ActivityStatusTrialExpire:
  903. tAppName = @"LynxPDF Editor TrialExpire";
  904. break;
  905. case ActivityStatusVerifExpire:
  906. tAppName = @"LynxPDF Editor VerifExpire";
  907. break;
  908. default:
  909. break;
  910. }
  911. #else
  912. // AppStore 免费版本
  913. tAppName = @"LynxPDF Editor Lite";
  914. #endif
  915. #else
  916. // AppStore 付费版
  917. tAppName = @"LynxPDF Editor Edition";
  918. #endif
  919. return tAppName;
  920. }
  921. @end