KMVerificationWindowController.m 48 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057
  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. @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 PDF Reader Pro", 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(@"PDF Reader Pro 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"];
  222. if([SKInspectPublicTool currentisLanguageHans]) {
  223. url = [NSURL URLWithString:@"https://www.pdfreaderpro.com/zh-cn/store"];
  224. }
  225. [[NSWorkspace sharedWorkspace] openURL:url];
  226. #endif
  227. [[FMTrackEventManager defaultManager] trackEventWithEvent:@"PUW" withProperties:@{@"PUW_Btn":@"Btn_PUW_BuyNow-Trial"}];
  228. [blockSelf close];
  229. };
  230. }
  231. return _alertViewController;
  232. }
  233. - (KMActivityALertViewController *)activityAlertViewController {
  234. if (!_activityAlertViewController) {
  235. __block __typeof(self) blockSelf = self;
  236. _activityAlertViewController = [[KMActivityALertViewController alloc] init];
  237. _activityAlertViewController.callback = ^{
  238. [blockSelf close];
  239. };
  240. }
  241. return _activityAlertViewController;
  242. }
  243. - (KMVerificationInfoViewController *)infoViewController {
  244. if (!_infoViewController) {
  245. __block __typeof(self) blockSelf = self;
  246. _infoViewController = [[KMVerificationInfoViewController alloc] init];
  247. _infoViewController.callback = ^{
  248. [blockSelf close];
  249. };
  250. _infoViewController.unbindAction = ^{
  251. dispatch_async(dispatch_get_main_queue(), ^{
  252. [blockSelf unbindAction];
  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?utm_source=app_dmg&utm_medium=dmg_puw_sec_free_trial"];
  270. if([SKInspectPublicTool currentisLanguageHans]) {
  271. url = [NSURL URLWithString:@"https://www.pdfreaderpro.com/zh-cn/store?utm_source=app_dmg&utm_medium=dmg_puw_sec_free_trial"];
  272. }
  273. [[NSWorkspace sharedWorkspace] openURL:url];
  274. [blockSelf close];
  275. } else if (clickIndex == 2) {
  276. //输入序列码
  277. KMVerificationWindowController *vc = [KMVerificationWindowController verificationWithType:KMVerificationTypeActivate];
  278. vc.callback = ^{
  279. };
  280. [vc showWindow:nil];
  281. }
  282. };
  283. }
  284. return _repeatTrialAlertController;
  285. }
  286. - (KMRepeatVerifyExpireController *)repeatTrialExpireController {
  287. if (!_repeatTrialExpireController) {
  288. __block __typeof(self) blockSelf = self;
  289. _repeatTrialExpireController = [[KMRepeatVerifyExpireController alloc] init];
  290. _repeatTrialExpireController.callback = ^(NSInteger clickIndex, KMRepeatVerifyExpireController * _Nonnull tRController) {
  291. if (clickIndex == 0) {
  292. [blockSelf setContentView:blockSelf.activateViewController.view];
  293. } else if (clickIndex == 1) {
  294. [[FMTrackEventManager defaultManager] trackEventWithEvent:@"PUW" withProperties:@{@"PUW_Btn":@"Btn_PUW_SecondTrialExpire_Later"}];
  295. [blockSelf close];
  296. } else if (clickIndex == 2) {
  297. [[FMTrackEventManager defaultManager] trackEventWithEvent:@"PUW" withProperties:@{@"PUW_Btn":@"Btn_PUW_SecondTrialExpire_Buy"}];
  298. [blockSelf verificationBuy];
  299. }
  300. };
  301. }
  302. return _repeatTrialExpireController;
  303. }
  304. - (KMTrialSuccessController *)trialSuccessController {
  305. if (!_trialSuccessController) {
  306. __block __typeof(self) blockSelf = self;
  307. _trialSuccessController = [[KMTrialSuccessController alloc] init];
  308. _trialSuccessController.clickHandle = ^(KMTrialSuccessController * _Nonnull controller) {
  309. [blockSelf close];
  310. };
  311. }
  312. return _trialSuccessController;
  313. }
  314. #pragma mark Window Methods
  315. - (void)windowDidLoad {
  316. [super windowDidLoad];
  317. // Implement this method to handle any initialization after your window controller's window has been loaded from its nib file.
  318. self.window.title = @"";
  319. [[self.window standardWindowButton:NSWindowZoomButton] setHidden:YES];
  320. [[self.window standardWindowButton:NSWindowMiniaturizeButton] setHidden:YES];
  321. [self updateViewInfo];
  322. [self updateViewColor];
  323. [NSDistributedNotificationCenter.defaultCenter addObserver:self selector:@selector(themeChanged:) name:@"AppleInterfaceThemeChangedNotification" object: nil];
  324. }
  325. - (void)updateViewInfo {
  326. if (KMVerificationTypeNormal == self.type) {
  327. [self setContentView:self.normalViewController.view];
  328. } else if (KMVerificationTypeActivate == self.type) {
  329. [self setContentView:self.activateViewController.view];
  330. } else if (KMVerificationTypeTrial == self.type) {
  331. [self setContentView:self.trialViewController.view];
  332. } else if (KMVerificationTypeActivateExpired == self.type) {
  333. [self setContentView:self.expiredViewController.view];
  334. } else if (KMVerificationTypeTrialExpired == self.type) {
  335. [self setContentView:self.normalViewController.view];
  336. } else if (KMVerificationTypeInfo == self.type) {
  337. [self setContentView:self.infoViewController.view];
  338. } else if (KMVerificationTypeRepeatTrialGuide == self.type) {
  339. self.window.title = @"";
  340. [self setContentView:self.repeatTrialAlertController.view];
  341. [[NSUserDefaults standardUserDefaults] setObject:@"YES" forKey:@"allowRepeatTrialAlertShowKey"];
  342. [[NSUserDefaults standardUserDefaults] synchronize];
  343. } else if (KMVerificationTypeRepeatTrialExpire == self.type) {
  344. [self setContentView:self.repeatTrialExpireController.view];
  345. [[NSUserDefaults standardUserDefaults] setObject:@"YES" forKey:@"allowRepeatTrialExpireShowKey"];
  346. [[NSUserDefaults standardUserDefaults] synchronize];
  347. } else if (self.type == KMVerificationTypeTrialSuccess ||
  348. self.type == KMVerificationTypeRepeatTrialSuccess) {
  349. [self setContentView:self.trialSuccessController.view];
  350. } else if (KMVerificationTypeActivateAIInfo == self.type) {
  351. [self setContentView:self.activateViewController.view];
  352. self.activateViewController.type = self.type;
  353. }
  354. }
  355. - (void)updateViewColor {
  356. if (KMVerificationTypeNormal == self.type) {
  357. } else if (KMVerificationTypeActivate == self.type) {
  358. } else if (KMVerificationTypeTrial == self.type) {
  359. } else if (KMVerificationTypeActivateExpired == self.type) {
  360. } else if (KMVerificationTypeTrialExpired == self.type) {
  361. } else if (KMVerificationTypeInfo == self.type) {
  362. } else if (KMVerificationTypeRepeatTrialGuide == self.type) {
  363. [self.repeatTrialAlertController updateViewColor];
  364. } else if (KMVerificationTypeRepeatTrialExpire == self.type) {
  365. [self.repeatTrialExpireController updateViewColor];
  366. } else if (KMVerificationTypeTrialSuccess == self.type ||
  367. KMVerificationTypeRepeatTrialSuccess == self.type) {
  368. [self.trialSuccessController updateViewColor];
  369. }
  370. }
  371. - (void)showWindow:(id)sender {
  372. if (!_currentWindowController) {
  373. _currentWindowController = self;
  374. }
  375. [super showWindow:sender];
  376. }
  377. - (void)windowWillClose:(NSNotification *)notification {
  378. if (_currentWindowController) {
  379. _currentWindowController = nil;
  380. }
  381. }
  382. #pragma mark - Setter
  383. - (void)setContentView:(NSView *)view {
  384. NSRect frame = self.window.frame;
  385. frame.origin.y -= view.frame.size.height-frame.size.height;
  386. frame.origin.x -= (view.frame.size.width-frame.size.width)/2.0;
  387. frame.size.width = view.frame.size.width;
  388. frame.size.height = view.frame.size.height;
  389. [self.box setContentView:view];
  390. [self.window setFrame:frame display:YES animate:YES];
  391. }
  392. #pragma mark - Private Methods
  393. - (void)verificationTrialForEmail:(NSString *)email name:(NSString *)name {
  394. if (email.length <= 0) {
  395. return;
  396. }
  397. if (![self isConnectionAvailable]) {
  398. NSAlert *alert = [NSAlert alertWithMessageText:NSLocalizedString(@"Connection Error", nil)
  399. defaultButton:NSLocalizedString(@"OK", nil)
  400. alternateButton:nil
  401. otherButton:nil
  402. informativeTextWithFormat:NSLocalizedString(@"Please make sure your internet connection is available.", nil), nil];
  403. [alert runModal];
  404. return;
  405. }
  406. __block __typeof(self) blockSelf = self;
  407. self.progressIndicator.hidden = NO;
  408. [self.progressIndicator startAnimation:nil];
  409. [self.trialViewController setEnabled:NO];
  410. [[VerificationManager manager] trialForDays:7 email:email name:name complention:^(ActivityStatus status, NSDictionary *info, NSError *error) {
  411. blockSelf.progressIndicator.hidden = YES;
  412. [blockSelf.progressIndicator stopAnimation:nil];
  413. [blockSelf.trialViewController setEnabled:YES];
  414. if (error ||
  415. status != ActivityStatusTrial) {
  416. NSAlert *alert = [NSAlert alertWithMessageText:NSLocalizedString(@"Activation Error", nil)
  417. defaultButton:NSLocalizedString(@"Try Again", nil)
  418. alternateButton:nil
  419. otherButton:nil
  420. informativeTextWithFormat:NSLocalizedString(@"Failed to sign up for the free trial. Please make sure your internet connection is available and try again later.", nil), nil];
  421. [alert runModal];
  422. } else {
  423. blockSelf.type = KMVerificationTypeTrialSuccess;
  424. [blockSelf updateViewInfo];
  425. }
  426. }];
  427. }
  428. - (void)verificationActivateAIInfo:(NSString *)license {
  429. if (license.length <= 0) {
  430. return;
  431. }
  432. if (![self isConnectionAvailable]) {
  433. NSAlert *alert = [NSAlert alertWithMessageText:NSLocalizedString(@"Connection Error", nil)
  434. defaultButton:NSLocalizedString(@"OK", nil)
  435. alternateButton:nil
  436. otherButton:nil
  437. informativeTextWithFormat:@"", nil];
  438. NSButton *accessryBtn = [[NSButton alloc] initWithFrame:CGRectMake(0, 0, 180, 44)];
  439. accessryBtn.autoresizingMask = NSViewMaxXMargin | NSViewMinYMargin | NSViewMaxYMargin;
  440. accessryBtn.bezelStyle = NSBezelStyleRegularSquare;
  441. accessryBtn.bordered = NO;
  442. accessryBtn.target = self;
  443. accessryBtn.action = @selector(accessryBtnClicked:);
  444. NSMutableAttributedString *mutAttrString = [[NSMutableAttributedString alloc] initWithString:NSLocalizedString(@"Please make sure your internet connection is available.", nil)];
  445. [mutAttrString addAttribute:NSUnderlineStyleAttributeName value:[NSNumber numberWithInteger:NSUnderlineStyleSingle] range:NSMakeRange(0, [mutAttrString length])];
  446. [mutAttrString addAttribute:NSFontAttributeName value:[NSFont systemFontOfSize:12] range:NSMakeRange(0, [mutAttrString length])];
  447. [mutAttrString addAttribute:NSForegroundColorAttributeName value:[KMAppearance KMColor_Interactive_M0] range:NSMakeRange(0, [mutAttrString length])];
  448. accessryBtn.attributedTitle = mutAttrString;
  449. NSRect rect = [mutAttrString boundingRectWithSize:CGSizeMake(180, MAXFLOAT) options:NSStringDrawingUsesLineFragmentOrigin | NSStringDrawingUsesFontLeading];
  450. CGRect frame = accessryBtn.frame;
  451. frame.size.height = rect.size.height;
  452. accessryBtn.frame = frame;
  453. alert.accessoryView = accessryBtn;
  454. [alert runModal];
  455. return;
  456. }
  457. __block __typeof(self) blockSelf = self;
  458. self.progressIndicator.hidden = NO;
  459. [self.progressIndicator startAnimation:nil];
  460. [self.activateViewController setEnabled:NO];
  461. NSDictionary *infoDic = @{@"cdkey":license};
  462. [[AIInfoManager defaultManager] activateAIWithInfo:infoDic complention:^(NSDictionary *info, NSError *error) {
  463. blockSelf.progressIndicator.hidden = YES;
  464. [blockSelf.progressIndicator stopAnimation:nil];
  465. [blockSelf.activateViewController setEnabled:YES];
  466. if (error) {
  467. NSString *tTitle0 = NSLocalizedString(@"The license you have entered is not correct. Please enter valid license.", nil);
  468. NSString *tTitle1 = NSLocalizedString(@"Please confirm your PDF Reader Pro AI license code through the email you provided when purchasing.", nil);
  469. NSString *message = [NSString stringWithFormat:@"%@\n\n%@", tTitle0, tTitle1];
  470. if (ActivityErrorTypeCDKeyEmpty == error.code) {
  471. message = [NSString stringWithFormat:@"%@\n\n%@", NSLocalizedString(@"License number can not be empty.", nil), @""];
  472. } else if (ActivityErrorTypeCDKeyNotExist == error.code) {
  473. message = [NSString stringWithFormat:@"%@\n\n%@", NSLocalizedString(@"License number does not exist.", nil), @""];
  474. } else if (ActivityErrorTypeOutNumber == error.code) {
  475. NSString *tMsg0 = NSLocalizedString(@"The devices connected to the license number has outnumbered.", nil);
  476. NSString *tMsg1 = NSLocalizedString(@"Please deactivate license on one of them, to use PDF Reader Pro on this computer", nil);
  477. message = [NSString stringWithFormat:@"%@\n\n%@", tMsg0, tMsg1];
  478. } else if (ActivityErrorTypeNetworkDisable == error.code) {
  479. message = NSLocalizedString(@"The network is unavailable.", nil);
  480. } else if (ActivityErrorTypeCDKeyExpire == error.code) {
  481. message = NSLocalizedString(@"The license number expired.", nil);
  482. } else if (ActivityErrorTypeInvalidInfo == error.code) {
  483. message = NSLocalizedString(@"Activation error. Please try to input correct license, or contact us.", nil);
  484. } else if (ActivityErrorTypeNotMatchProduct == error.code) {
  485. message = NSLocalizedString(@"The license number is wrong, please input right license which is for this app.", nil);
  486. } else if (ActivityErrorTypeFormatError == error.code) {
  487. message = NSLocalizedString(@"Error license. Please enter an AI license.", nil);
  488. }
  489. if ((ActivityErrorTypeUnknow == error.code) || (ActivityErrorTypeOutNumber == error.code) || (ActivityErrorTypeInvalidInfo == error.code)) {
  490. NSAlert *alert = [NSAlert alertWithMessageText:NSLocalizedString(@"Activation Error", nil)
  491. defaultButton:NSLocalizedString(@"Contact Us", nil)
  492. alternateButton:NSLocalizedString(@"Try Again", nil)
  493. otherButton:nil
  494. informativeTextWithFormat:message, nil];
  495. if ([alert runModal]) {
  496. [blockSelf verificationFeedback];
  497. }
  498. } else {
  499. if (ActivityErrorTypeNetworkDisable == error.code) {
  500. NSAlert *alert = [NSAlert alertWithMessageText:NSLocalizedString(@"Connection Error", nil)
  501. defaultButton:NSLocalizedString(@"OK", nil)
  502. alternateButton:nil
  503. otherButton:nil
  504. informativeTextWithFormat:@"", nil];
  505. NSButton *accessryBtn = [[NSButton alloc] initWithFrame:CGRectMake(0, 0, 180, 44)];
  506. accessryBtn.autoresizingMask = NSViewMaxXMargin | NSViewMinYMargin | NSViewMaxYMargin;
  507. accessryBtn.bezelStyle = NSBezelStyleRegularSquare;
  508. accessryBtn.bordered = NO;
  509. accessryBtn.target = self;
  510. accessryBtn.action = @selector(accessryBtnClicked:);
  511. NSMutableAttributedString *mutAttrString = [[NSMutableAttributedString alloc] initWithString:NSLocalizedString(@"Please make sure your internet connection is available.", nil)];
  512. [mutAttrString addAttribute:NSFontAttributeName value:[NSFont systemFontOfSize:12] range:NSMakeRange(0, [mutAttrString length])];
  513. [mutAttrString addAttribute:NSUnderlineStyleAttributeName value:[NSNumber numberWithInteger:NSUnderlineStyleSingle] range:NSMakeRange(0, [mutAttrString length])];
  514. [mutAttrString addAttribute:NSForegroundColorAttributeName value:[KMAppearance KMColor_Interactive_M0] range:NSMakeRange(0, [mutAttrString length])];
  515. accessryBtn.attributedTitle = mutAttrString;
  516. NSRect rect = [mutAttrString boundingRectWithSize:CGSizeMake(180, MAXFLOAT) options:NSStringDrawingUsesLineFragmentOrigin | NSStringDrawingUsesFontLeading];
  517. CGRect frame = accessryBtn.frame;
  518. frame.size.height = rect.size.height;
  519. accessryBtn.frame = frame;
  520. alert.accessoryView = accessryBtn;
  521. [alert runModal];
  522. } else {
  523. NSAlert *alert = [NSAlert alertWithMessageText:NSLocalizedString(@"Activation Error", nil)
  524. defaultButton:NSLocalizedString(@"Try Again", nil)
  525. alternateButton:nil
  526. otherButton:nil
  527. informativeTextWithFormat:message, nil];
  528. [alert runModal];
  529. }
  530. }
  531. } else {
  532. blockSelf.activityAlertViewController.alertTitle = NSLocalizedString(@"Successful Activation!", nil);
  533. blockSelf.activityAlertViewController.alertMessage = NSLocalizedString(@"Congratulations! You can start using PDF Reader Pro AI features.", nil);
  534. [blockSelf setContentView:blockSelf.activityAlertViewController.view];
  535. }
  536. }];
  537. }
  538. - (void)verificationActivate:(NSString *)license {
  539. if (license.length <= 0) {
  540. return;
  541. }
  542. if ([license hasPrefix:@"AI-"]) {
  543. NSAlert *alert = [NSAlert alertWithMessageText:NSLocalizedString(@"Activation Error", nil)
  544. defaultButton:NSLocalizedString(@"Try Again", nil)
  545. alternateButton:nil
  546. otherButton:nil
  547. 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];
  548. [alert runModal];
  549. return;
  550. }
  551. if (![self isConnectionAvailable]) {
  552. NSAlert *alert = [NSAlert alertWithMessageText:NSLocalizedString(@"Connection Error", nil)
  553. defaultButton:NSLocalizedString(@"OK", nil)
  554. alternateButton:nil
  555. otherButton:nil
  556. informativeTextWithFormat:@"", nil];
  557. NSButton *accessryBtn = [[NSButton alloc] initWithFrame:CGRectMake(0, 0, 180, 44)];
  558. accessryBtn.autoresizingMask = NSViewMaxXMargin | NSViewMinYMargin | NSViewMaxYMargin;
  559. accessryBtn.bezelStyle = NSBezelStyleRegularSquare;
  560. accessryBtn.bordered = NO;
  561. accessryBtn.target = self;
  562. accessryBtn.action = @selector(accessryBtnClicked:);
  563. NSMutableAttributedString *mutAttrString = [[NSMutableAttributedString alloc] initWithString:NSLocalizedString(@"Please make sure your internet connection is available.", nil)];
  564. [mutAttrString addAttribute:NSUnderlineStyleAttributeName value:[NSNumber numberWithInteger:NSUnderlineStyleSingle] range:NSMakeRange(0, [mutAttrString length])];
  565. [mutAttrString addAttribute:NSFontAttributeName value:[NSFont systemFontOfSize:12] range:NSMakeRange(0, [mutAttrString length])];
  566. [mutAttrString addAttribute:NSForegroundColorAttributeName value:[KMAppearance KMColor_Interactive_M0] range:NSMakeRange(0, [mutAttrString length])];
  567. accessryBtn.attributedTitle = mutAttrString;
  568. NSRect rect = [mutAttrString boundingRectWithSize:CGSizeMake(180, MAXFLOAT) options:NSStringDrawingUsesLineFragmentOrigin | NSStringDrawingUsesFontLeading];
  569. CGRect frame = accessryBtn.frame;
  570. frame.size.height = rect.size.height;
  571. accessryBtn.frame = frame;
  572. alert.accessoryView = accessryBtn;
  573. [alert runModal];
  574. return;
  575. }
  576. __block __typeof(self) blockSelf = self;
  577. self.progressIndicator.hidden = NO;
  578. [self.progressIndicator startAnimation:nil];
  579. [self.activateViewController setEnabled:NO];
  580. NSDictionary *infoDic = @{@"cdkey":license};
  581. [[VerificationManager manager] activateDeviceWithInfo:infoDic complention:^(ActivityStatus status, NSDictionary *info, NSError *error) {
  582. blockSelf.progressIndicator.hidden = YES;
  583. [blockSelf.progressIndicator stopAnimation:nil];
  584. [blockSelf.activateViewController setEnabled:YES];
  585. if (error) {
  586. NSString *tTitle0 = NSLocalizedString(@"The license you have entered is not correct. Please enter valid license.", nil);
  587. NSString *tTitle1 = NSLocalizedString(@"If you have already purchased PDF Reader Pro for Mac, you should find your license in an email confirmation.", nil);
  588. NSString *message = [NSString stringWithFormat:@"%@\n\n%@", tTitle0, tTitle1];
  589. if (ActivityErrorTypeCDKeyEmpty == error.code) {
  590. message = [NSString stringWithFormat:@"%@\n\n%@", NSLocalizedString(@"License number can not be empty.", nil), @""];
  591. } else if (ActivityErrorTypeCDKeyNotExist == error.code) {
  592. message = [NSString stringWithFormat:@"%@\n\n%@", NSLocalizedString(@"License number does not exist.", nil), @""];
  593. } else if (ActivityErrorTypeOutNumber == error.code) {
  594. NSString *tMsg0 = NSLocalizedString(@"The devices connected to the license number has outnumbered.", nil);
  595. NSString *tMsg1 = NSLocalizedString(@"Please deactivate license on one of them, to use PDF Reader Pro on this computer", nil);
  596. message = [NSString stringWithFormat:@"%@\n\n%@", tMsg0, tMsg1];
  597. } else if (ActivityErrorTypeNetworkDisable == error.code) {
  598. message = NSLocalizedString(@"The network is unavailable.", nil);
  599. } else if (ActivityErrorTypeCDKeyExpire == error.code) {
  600. message = NSLocalizedString(@"The license number expired.", nil);
  601. } else if (ActivityErrorTypeInvalidInfo == error.code) {
  602. message = NSLocalizedString(@"Activation error. Please try to input correct license, or contact us.", nil);
  603. } else if (ActivityErrorTypeNotMatchProduct == error.code) {
  604. message = NSLocalizedString(@"The license number is wrong, please input right license which is for this app.", nil);
  605. } else if (ActivityErrorTypeFormatError == error.code) {
  606. message = NSLocalizedString(@"The license format is wrong. Please input correct license.", nil);
  607. }
  608. if ((ActivityErrorTypeUnknow == error.code) || (ActivityErrorTypeOutNumber == error.code) || (ActivityErrorTypeInvalidInfo == error.code)) {
  609. NSAlert *alert = [NSAlert alertWithMessageText:NSLocalizedString(@"Activation Error", nil)
  610. defaultButton:NSLocalizedString(@"Contact Us", nil)
  611. alternateButton:NSLocalizedString(@"Try Again", nil)
  612. otherButton:nil
  613. informativeTextWithFormat:message, nil];
  614. if ([alert runModal]) {
  615. [blockSelf verificationFeedback];
  616. }
  617. } else {
  618. if (ActivityErrorTypeNetworkDisable == error.code) {
  619. NSAlert *alert = [NSAlert alertWithMessageText:NSLocalizedString(@"Connection Error", nil)
  620. defaultButton:NSLocalizedString(@"OK", nil)
  621. alternateButton:nil
  622. otherButton:nil
  623. informativeTextWithFormat:@"", nil];
  624. NSButton *accessryBtn = [[NSButton alloc] initWithFrame:CGRectMake(0, 0, 180, 44)];
  625. accessryBtn.autoresizingMask = NSViewMaxXMargin | NSViewMinYMargin | NSViewMaxYMargin;
  626. accessryBtn.bezelStyle = NSBezelStyleRegularSquare;
  627. accessryBtn.bordered = NO;
  628. accessryBtn.target = self;
  629. accessryBtn.action = @selector(accessryBtnClicked:);
  630. NSMutableAttributedString *mutAttrString = [[NSMutableAttributedString alloc] initWithString:NSLocalizedString(@"Please make sure your internet connection is available.", nil)];
  631. [mutAttrString addAttribute:NSFontAttributeName value:[NSFont systemFontOfSize:12] range:NSMakeRange(0, [mutAttrString length])];
  632. [mutAttrString addAttribute:NSUnderlineStyleAttributeName value:[NSNumber numberWithInteger:NSUnderlineStyleSingle] range:NSMakeRange(0, [mutAttrString length])];
  633. [mutAttrString addAttribute:NSForegroundColorAttributeName value:[KMAppearance KMColor_Interactive_M0] range:NSMakeRange(0, [mutAttrString length])];
  634. accessryBtn.attributedTitle = mutAttrString;
  635. NSRect rect = [mutAttrString boundingRectWithSize:CGSizeMake(180, MAXFLOAT) options:NSStringDrawingUsesLineFragmentOrigin | NSStringDrawingUsesFontLeading];
  636. CGRect frame = accessryBtn.frame;
  637. frame.size.height = rect.size.height;
  638. accessryBtn.frame = frame;
  639. alert.accessoryView = accessryBtn;
  640. [alert runModal];
  641. } else {
  642. NSAlert *alert = [NSAlert alertWithMessageText:NSLocalizedString(@"Activation Error", nil)
  643. defaultButton:NSLocalizedString(@"Try Again", nil)
  644. alternateButton:nil
  645. otherButton:nil
  646. informativeTextWithFormat:message, nil];
  647. [alert runModal];
  648. }
  649. }
  650. } else {
  651. blockSelf.activityAlertViewController.alertTitle = NSLocalizedString(@"Successful Activation!", nil);
  652. blockSelf.activityAlertViewController.alertMessage = NSLocalizedString(@"Congrats! You are eligible to enjoy all advanced features (excluding AI) in PDF Reader Pro.", nil);
  653. [blockSelf setContentView:blockSelf.activityAlertViewController.view];
  654. }
  655. }];
  656. }
  657. - (void)verificationBuy {
  658. #if VERSION_DMG
  659. NSURL *url = [NSURL URLWithString:@"https://www.pdfreaderpro.com/store?utm_source=MacAppDmg&utm_campaign=StoreLink&utm_medium=PdfStore"];
  660. if([SKInspectPublicTool currentisLanguageHans]) {
  661. url = [NSURL URLWithString:@"https://www.pdfreaderpro.com/zh-cn/store?utm_source=MacAppDmg&utm_campaign=StoreLink&utm_medium=PdfStore"];
  662. }
  663. [[NSWorkspace sharedWorkspace] openURL:url];
  664. #endif
  665. }
  666. #pragma - 验证错误时反馈信息
  667. - (void)verificationFeedback {
  668. unsigned major, minor, bugFix;
  669. [self getSystemVersionMajor:&major minor:&minor bugFix:&bugFix];
  670. NSString *versionString = [NSString stringWithFormat:@"%@ - %u.%u.%u", [GBDeviceInfo deviceInfo].rawSystemInfoString, major, minor, bugFix];
  671. //application version (use short version preferentially)
  672. NSString *tAppVersion = [[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBundleShortVersionString"];
  673. if ([tAppVersion length] < 1) {
  674. tAppVersion = [[NSBundle mainBundle] objectForInfoDictionaryKey:(NSString *)kCFBundleVersionKey];
  675. }
  676. NSString* subjects = [[self getAppNameForSupportEmail] stringByAppendingFormat:NSLocalizedString(@" - %@;Verification Feedback;%@", nil) ,tAppVersion,versionString];
  677. [KMMailHelper newEmailWithContacts:@"support@pdfreaderpro.com" andSubjects:subjects];
  678. }
  679. - (void)unbindAction {
  680. unsigned major, minor, bugFix;
  681. [self getSystemVersionMajor:&major minor:&minor bugFix:&bugFix];
  682. NSString *versionString = [NSString stringWithFormat:@"%@ - %u.%u.%u", [GBDeviceInfo deviceInfo].rawSystemInfoString, major, minor, bugFix];
  683. //application version (use short version preferentially)
  684. NSString *tAppVersion = [[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBundleShortVersionString"];
  685. if ([tAppVersion length] < 1) {
  686. tAppVersion = [[NSBundle mainBundle] objectForInfoDictionaryKey:(NSString *)kCFBundleVersionKey];
  687. }
  688. NSString *subjects = [[self getAppNameForEmail] stringByAppendingString:[NSString stringWithFormat:@" %@",@"Verification:"]];
  689. subjects = [subjects stringByAppendingString:[NSString stringWithFormat:@"%@;",tAppVersion]];
  690. subjects = [subjects stringByAppendingString:[NSString stringWithFormat:@" %@;",versionString]];
  691. subjects = [subjects stringByAppendingString:[NSString stringWithFormat:@" %@",NSLocalizedString(@"Unbind License Code:", nil)]];
  692. subjects = [subjects stringByAppendingString:[NSString stringWithFormat:@"%@",[VerificationManager manager].detailInfo[@"device"][@"unique_sn"]?:@""]];
  693. 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)]];
  694. [[NSWorkspace sharedWorkspace] openURL:[NSURL URLWithString:mailtoAddress]];
  695. }
  696. - (void)accessryBtnClicked:(NSButton *)btn {
  697. [[NSWorkspace sharedWorkspace] openURL:[NSURL URLWithString:@"https://www.pdfreaderpro.com/mac/help/activate-license-code-mac"]];
  698. }
  699. - (NSString *)URLEncodedString:(NSString *)string {
  700. CFStringRef stringRef = CFBridgingRetain(string);
  701. #pragma clang diagnostic push
  702. #pragma clang diagnostic ignored "-Wdeprecated-declarations"
  703. CFStringRef encoded = CFURLCreateStringByAddingPercentEscapes(kCFAllocatorDefault,
  704. stringRef,
  705. NULL,
  706. CFSTR("!*'\"();:@&=+$,/?%#[]% "),
  707. kCFStringEncodingUTF8);
  708. #pragma clang diagnostic pop
  709. CFRelease(stringRef);
  710. return CFBridgingRelease(encoded);
  711. }
  712. - (void)getSystemVersionMajor:(unsigned *)major
  713. minor:(unsigned *)minor
  714. bugFix:(unsigned *)bugFix {
  715. OSErr err;
  716. SInt32 systemVersion, versionMajor, versionMinor, versionBugFix;
  717. if ([[NSProcessInfo processInfo] respondsToSelector:@selector(operatingSystemVersion)]) {
  718. NSOperatingSystemVersion osSystemVersion = [[NSProcessInfo processInfo] operatingSystemVersion];
  719. *major = (unsigned)osSystemVersion.majorVersion;
  720. *minor = (unsigned)osSystemVersion.minorVersion;
  721. *bugFix = (unsigned)osSystemVersion.patchVersion;
  722. return;
  723. } else {
  724. #pragma clang diagnostic push
  725. #pragma clang diagnostic ignored "-Wdeprecated-declarations"
  726. if ((err = Gestalt(gestaltSystemVersion, &systemVersion)) != noErr) goto fail;
  727. if (systemVersion < 0x1040)
  728. {
  729. if (major) *major = ((systemVersion & 0xF000) >> 12) * 10 +
  730. ((systemVersion & 0x0F00) >> 8);
  731. if (minor) *minor = (systemVersion & 0x00F0) >> 4;
  732. if (bugFix) *bugFix = (systemVersion & 0x000F);
  733. }
  734. else
  735. {
  736. if ((err = Gestalt(gestaltSystemVersionMajor, &versionMajor)) != noErr) goto fail;
  737. if ((err = Gestalt(gestaltSystemVersionMinor, &versionMinor)) != noErr) goto fail;
  738. if ((err = Gestalt(gestaltSystemVersionBugFix, &versionBugFix)) != noErr) goto fail;
  739. if (major) *major = versionMajor;
  740. if (minor) *minor = versionMinor;
  741. if (bugFix) *bugFix = versionBugFix;
  742. }
  743. return;
  744. #pragma clang diagnostic pop
  745. }
  746. fail:
  747. NSLog(@"Unable to obtain system version: %ld", (long)err);
  748. if (major) *major = 10;
  749. if (minor) *minor = 0;
  750. if (bugFix) *bugFix = 0;
  751. }
  752. - (NSString *)getAppNameForEmail {
  753. NSString *tAppName = @"PDF Reader Pro Mac";
  754. #if VERSION_FREE
  755. #if VERSION_DMG
  756. #else
  757. // AppStore 免费版本
  758. tAppName = @"PDF Reader Pro Lite";
  759. #endif
  760. #else
  761. // AppStore 付费版
  762. tAppName = @"PDF Reader Pro Edition";
  763. #endif
  764. return tAppName;
  765. }
  766. - (NSString *)getAppNameForSupportEmail {
  767. NSString *tAppName = @"PDF Reader Pro";
  768. #if VERSION_FREE
  769. #if VERSION_DMG
  770. // 桌机版
  771. VerificationManager *tManager = [VerificationManager manager];
  772. switch ([tManager status]) {
  773. case ActivityStatusTrial:
  774. tAppName = @"PDF Reader Pro Trial";
  775. break;
  776. case ActivityStatusVerification:
  777. tAppName = @"PDF Reader Pro Verification";
  778. break;
  779. case ActivityStatusTrialExpire:
  780. tAppName = @"PDF Reader Pro TrialExpire";
  781. break;
  782. case ActivityStatusVerifExpire:
  783. tAppName = @"PDF Reader Pro VerifExpire";
  784. break;
  785. default:
  786. break;
  787. }
  788. #else
  789. // AppStore 免费版本
  790. tAppName = @"PDF Reader Pro Lite";
  791. #endif
  792. #else
  793. // AppStore 付费版
  794. tAppName = @"PDF Reader Pro Edition";
  795. #endif
  796. return tAppName;
  797. }
  798. - (BOOL)isConnectionAvailable {
  799. BOOL isExistenceNetwork = YES;
  800. Reachability *reach = [Reachability reachabilityWithHostname:@"www.apple.com"];
  801. switch ([reach currentReachabilityStatus]) {
  802. case NotReachable:
  803. isExistenceNetwork = NO;
  804. //NSLog(@"notReachable");
  805. break;
  806. case ReachableViaWiFi:
  807. isExistenceNetwork = YES;
  808. //NSLog(@"WIFI");
  809. break;
  810. case ReachableViaWWAN:
  811. isExistenceNetwork = YES;
  812. //NSLog(@"3G");
  813. break;
  814. }
  815. if (NotReachable == [[Reachability reachabilityForInternetConnection] currentReachabilityStatus]) {
  816. return NO;
  817. }
  818. return YES;
  819. }
  820. #pragma mark - NSNotification
  821. - (void)themeChanged:(NSNotification *)notification {
  822. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.3 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
  823. [self updateViewColor];
  824. });
  825. }
  826. + (void)verificationFeedback {
  827. unsigned major, minor, bugFix;
  828. [self getSystemVersionMajor:&major minor:&minor bugFix:&bugFix];
  829. NSString *versionString = [NSString stringWithFormat:@"%@ - %u.%u.%u", [GBDeviceInfo deviceInfo].rawSystemInfoString, major, minor, bugFix];
  830. NSString *tAppVersion = [[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBundleShortVersionString"];
  831. if ([tAppVersion length] < 1)
  832. {
  833. tAppVersion = [[NSBundle mainBundle] objectForInfoDictionaryKey:(NSString *)kCFBundleVersionKey];
  834. }
  835. NSString* subjects = [[self getAppNameForSupportEmail] stringByAppendingFormat:NSLocalizedString(@" - %@;Verification Feedback;%@", nil) ,tAppVersion,versionString];
  836. [KMMailHelper newEmailWithContacts:@"support@pdfreaderpro.com" andSubjects:subjects];
  837. }
  838. + (void)getSystemVersionMajor:(unsigned *)major
  839. minor:(unsigned *)minor
  840. bugFix:(unsigned *)bugFix;
  841. {
  842. OSErr err;
  843. SInt32 systemVersion, versionMajor, versionMinor, versionBugFix;
  844. if ([[NSProcessInfo processInfo] respondsToSelector:@selector(operatingSystemVersion)]) {
  845. NSOperatingSystemVersion osSystemVersion = [[NSProcessInfo processInfo] operatingSystemVersion];
  846. *major = (unsigned)osSystemVersion.majorVersion;
  847. *minor = (unsigned)osSystemVersion.minorVersion;
  848. *bugFix = (unsigned)osSystemVersion.patchVersion;
  849. return;
  850. } else {
  851. #pragma clang diagnostic push
  852. #pragma clang diagnostic ignored "-Wdeprecated-declarations"
  853. if ((err = Gestalt(gestaltSystemVersion, &systemVersion)) != noErr) goto fail;
  854. if (systemVersion < 0x1040)
  855. {
  856. if (major) *major = ((systemVersion & 0xF000) >> 12) * 10 +
  857. ((systemVersion & 0x0F00) >> 8);
  858. if (minor) *minor = (systemVersion & 0x00F0) >> 4;
  859. if (bugFix) *bugFix = (systemVersion & 0x000F);
  860. }
  861. else
  862. {
  863. if ((err = Gestalt(gestaltSystemVersionMajor, &versionMajor)) != noErr) goto fail;
  864. if ((err = Gestalt(gestaltSystemVersionMinor, &versionMinor)) != noErr) goto fail;
  865. if ((err = Gestalt(gestaltSystemVersionBugFix, &versionBugFix)) != noErr) goto fail;
  866. if (major) *major = versionMajor;
  867. if (minor) *minor = versionMinor;
  868. if (bugFix) *bugFix = versionBugFix;
  869. }
  870. return;
  871. #pragma clang diagnostic pop
  872. }
  873. fail:
  874. NSLog(@"Unable to obtain system version: %ld", (long)err);
  875. if (major) *major = 10;
  876. if (minor) *minor = 0;
  877. if (bugFix) *bugFix = 0;
  878. }
  879. + (NSString *)getAppNameForSupportEmail
  880. {
  881. NSString *tAppName = @"PDF Reader Pro";
  882. #if VERSION_FREE
  883. #if VERSION_DMG
  884. // 桌机版
  885. VerificationManager *tManager = [VerificationManager manager];
  886. switch ([tManager status]) {
  887. case ActivityStatusTrial:
  888. tAppName = @"PDF Reader Pro Trial";
  889. break;
  890. case ActivityStatusVerification:
  891. tAppName = @"PDF Reader Pro Verification";
  892. break;
  893. case ActivityStatusTrialExpire:
  894. tAppName = @"PDF Reader Pro TrialExpire";
  895. break;
  896. case ActivityStatusVerifExpire:
  897. tAppName = @"PDF Reader Pro VerifExpire";
  898. break;
  899. default:
  900. break;
  901. }
  902. #else
  903. // AppStore 免费版本
  904. tAppName = @"PDF Reader Pro Lite";
  905. #endif
  906. #else
  907. // AppStore 付费版
  908. tAppName = @"PDF Reader Pro Edition";
  909. #endif
  910. return tAppName;
  911. }
  912. @end