KMVerificationWindowController.m 49 KB

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