KMVerificationWindowController.m 35 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809
  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. + (instancetype)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. [blockSelf verificationActivate:string];
  172. }
  173. };
  174. }
  175. return _activateViewController;
  176. }
  177. - (KMVerificationExpiredViewController *)expiredViewController {
  178. if (!_expiredViewController) {
  179. __block __typeof(self) blockSelf = self;
  180. _expiredViewController = [[KMVerificationExpiredViewController alloc] init];
  181. _expiredViewController.callback = ^(NSInteger index) {
  182. if (index == 0) {
  183. [blockSelf setContentView:blockSelf.activateViewController.view];
  184. } else {
  185. [blockSelf verificationFeedback];
  186. }
  187. };
  188. }
  189. return _expiredViewController;
  190. }
  191. - (KMVerificationTrialViewController *)trialViewController {
  192. if (!_trialViewController) {
  193. __block __typeof(self) blockSelf = self;
  194. _trialViewController = [[KMVerificationTrialViewController alloc] init];
  195. _trialViewController.callback = ^(NSInteger index, NSString *email, NSString *name) {
  196. if (index == 0) {
  197. [blockSelf setContentView:blockSelf.activateViewController.view];
  198. } else {
  199. [blockSelf verificationTrialForEmail:email name:name];
  200. }
  201. };
  202. }
  203. return _trialViewController;
  204. }
  205. - (KMVerificationAlertViewController *)alertViewController {
  206. if (!_alertViewController) {
  207. __block __typeof(self) blockSelf = self;
  208. _alertViewController = [[KMVerificationAlertViewController alloc] init];
  209. _alertViewController.callback = ^{
  210. [blockSelf close];
  211. };
  212. _alertViewController.buyActionHandle = ^{
  213. #if VERSION_DMG
  214. NSURL *url = [NSURL URLWithString:@"https://www.pdfreaderpro.com/store"];
  215. if([SKInspectPublicTool currentisLanguageHans]) {
  216. url = [NSURL URLWithString:@"https://www.pdfreaderpro.com/zh-cn/store"];
  217. }
  218. [[NSWorkspace sharedWorkspace] openURL:url];
  219. #endif
  220. // [[FMTrackEventManager manager] trackEvent:@"PUW" withProperties:@{@"PUW_Btn":@"Btn_PUW_BuyNow-Trial"}];
  221. [blockSelf close];
  222. };
  223. }
  224. return _alertViewController;
  225. }
  226. - (KMActivityALertViewController *)activityAlertViewController {
  227. if (!_activityAlertViewController) {
  228. __block __typeof(self) blockSelf = self;
  229. _activityAlertViewController = [[KMActivityALertViewController alloc] init];
  230. _activityAlertViewController.callback = ^{
  231. [blockSelf close];
  232. };
  233. }
  234. return _activityAlertViewController;
  235. }
  236. - (KMVerificationInfoViewController *)infoViewController {
  237. if (!_infoViewController) {
  238. __block __typeof(self) blockSelf = self;
  239. _infoViewController = [[KMVerificationInfoViewController alloc] init];
  240. _infoViewController.callback = ^{
  241. [blockSelf close];
  242. };
  243. _infoViewController.unbindAction = ^{
  244. dispatch_async(dispatch_get_main_queue(), ^{
  245. [blockSelf unbindAction];
  246. });
  247. };
  248. }
  249. return _infoViewController;
  250. }
  251. - (KMRepeatTrialAlertController *)repeatTrialAlertController {
  252. if (!_repeatTrialAlertController) {
  253. __block __typeof(self) blockSelf = self;
  254. _repeatTrialAlertController = [[KMRepeatTrialAlertController alloc] init];
  255. _repeatTrialAlertController.callback = ^(NSInteger clickIndex, KMRepeatTrialAlertController * _Nonnull tRController) {
  256. if (clickIndex == 0) {
  257. //免费试用
  258. [blockSelf verificationTrialForEmail:[VerificationManager manager].email
  259. name:[VerificationManager manager].accountName] ;
  260. } else if (clickIndex == 1) {
  261. //了解更多
  262. NSURL *url = [NSURL URLWithString:@"https://www.pdfreaderpro.com/store?utm_source=app_dmg&utm_medium=dmg_puw_sec_free_trial"];
  263. if([SKInspectPublicTool currentisLanguageHans]) {
  264. url = [NSURL URLWithString:@"https://www.pdfreaderpro.com/zh-cn/store?utm_source=app_dmg&utm_medium=dmg_puw_sec_free_trial"];
  265. }
  266. [[NSWorkspace sharedWorkspace] openURL:url];
  267. [blockSelf close];
  268. } else if (clickIndex == 2) {
  269. //输入序列码
  270. KMVerificationWindowController *vc = [KMVerificationWindowController verificationWithType:KMVerificationTypeActivate];
  271. vc.callback = ^{
  272. };
  273. [vc showWindow:nil];
  274. }
  275. };
  276. }
  277. return _repeatTrialAlertController;
  278. }
  279. - (KMRepeatVerifyExpireController *)repeatTrialExpireController {
  280. if (!_repeatTrialExpireController) {
  281. __block __typeof(self) blockSelf = self;
  282. _repeatTrialExpireController = [[KMRepeatVerifyExpireController alloc] init];
  283. _repeatTrialExpireController.callback = ^(NSInteger clickIndex, KMRepeatVerifyExpireController * _Nonnull tRController) {
  284. if (clickIndex == 0) {
  285. [blockSelf setContentView:blockSelf.activateViewController.view];
  286. } else if (clickIndex == 1) {
  287. // [[FMTrackEventManager manager] trackEvent:@"PUW" withProperties:@{@"PUW_Btn":@"Btn_PUW_SecondTrialExpire_Later"}];
  288. [blockSelf close];
  289. } else if (clickIndex == 2) {
  290. // [[FMTrackEventManager manager] trackEvent:@"PUW" withProperties:@{@"PUW_Btn":@"Btn_PUW_SecondTrialExpire_Buy"}];
  291. [blockSelf verificationBuy];
  292. }
  293. };
  294. }
  295. return _repeatTrialExpireController;
  296. }
  297. - (KMTrialSuccessController *)trialSuccessController {
  298. if (!_trialSuccessController) {
  299. __block __typeof(self) blockSelf = self;
  300. _trialSuccessController = [[KMTrialSuccessController alloc] init];
  301. _trialSuccessController.clickHandle = ^(KMTrialSuccessController * _Nonnull controller) {
  302. [blockSelf close];
  303. };
  304. }
  305. return _trialSuccessController;
  306. }
  307. #pragma mark Window Methods
  308. - (void)windowDidLoad {
  309. [super windowDidLoad];
  310. // Implement this method to handle any initialization after your window controller's window has been loaded from its nib file.
  311. self.window.title = @"";
  312. [[self.window standardWindowButton:NSWindowZoomButton] setHidden:YES];
  313. [[self.window standardWindowButton:NSWindowMiniaturizeButton] setHidden:YES];
  314. [self updateViewInfo];
  315. [self updateViewColor];
  316. [NSDistributedNotificationCenter.defaultCenter addObserver:self selector:@selector(themeChanged:) name:@"AppleInterfaceThemeChangedNotification" object: nil];
  317. }
  318. - (void)updateViewInfo {
  319. if (KMVerificationTypeNormal == self.type) {
  320. [self setContentView:self.normalViewController.view];
  321. } else if (KMVerificationTypeActivate == self.type) {
  322. [self setContentView:self.activateViewController.view];
  323. } else if (KMVerificationTypeTrial == self.type) {
  324. [self setContentView:self.trialViewController.view];
  325. } else if (KMVerificationTypeActivateExpired == self.type) {
  326. [self setContentView:self.expiredViewController.view];
  327. } else if (KMVerificationTypeTrialExpired == self.type) {
  328. [self setContentView:self.normalViewController.view];
  329. } else if (KMVerificationTypeInfo == self.type) {
  330. [self setContentView:self.infoViewController.view];
  331. } else if (KMVerificationTypeRepeatTrialGuide == self.type) {
  332. self.window.title = @"";
  333. [self setContentView:self.repeatTrialAlertController.view];
  334. [[NSUserDefaults standardUserDefaults] setObject:@"YES" forKey:@"allowRepeatTrialAlertShowKey"];
  335. [[NSUserDefaults standardUserDefaults] synchronize];
  336. } else if (KMVerificationTypeRepeatTrialExpire == self.type) {
  337. [self setContentView:self.repeatTrialExpireController.view];
  338. [[NSUserDefaults standardUserDefaults] setObject:@"YES" forKey:@"allowRepeatTrialExpireShowKey"];
  339. [[NSUserDefaults standardUserDefaults] synchronize];
  340. } else if (self.type == KMVerificationTypeTrialSuccess ||
  341. self.type == KMVerificationTypeRepeatTrialSuccess) {
  342. [self setContentView:self.trialSuccessController.view];
  343. }
  344. }
  345. - (void)updateViewColor {
  346. if (KMVerificationTypeNormal == self.type) {
  347. } else if (KMVerificationTypeActivate == self.type) {
  348. } else if (KMVerificationTypeTrial == self.type) {
  349. } else if (KMVerificationTypeActivateExpired == self.type) {
  350. } else if (KMVerificationTypeTrialExpired == self.type) {
  351. } else if (KMVerificationTypeInfo == self.type) {
  352. } else if (KMVerificationTypeRepeatTrialGuide == self.type) {
  353. [self.repeatTrialAlertController updateViewColor];
  354. } else if (KMVerificationTypeRepeatTrialExpire == self.type) {
  355. [self.repeatTrialExpireController updateViewColor];
  356. } else if (KMVerificationTypeTrialSuccess == self.type ||
  357. KMVerificationTypeRepeatTrialSuccess == self.type) {
  358. [self.trialSuccessController updateViewColor];
  359. }
  360. }
  361. - (void)showWindow:(id)sender {
  362. if (!_currentWindowController) {
  363. _currentWindowController = self;
  364. }
  365. [super showWindow:sender];
  366. }
  367. - (void)windowWillClose:(NSNotification *)notification {
  368. if (_currentWindowController) {
  369. _currentWindowController = nil;
  370. }
  371. }
  372. #pragma mark - Setter
  373. - (void)setContentView:(NSView *)view {
  374. NSRect frame = self.window.frame;
  375. frame.origin.y -= view.frame.size.height-frame.size.height;
  376. frame.origin.x -= (view.frame.size.width-frame.size.width)/2.0;
  377. frame.size.width = view.frame.size.width;
  378. frame.size.height = view.frame.size.height;
  379. [self.box setContentView:view];
  380. [self.window setFrame:frame display:YES animate:YES];
  381. }
  382. #pragma mark - Private Methods
  383. - (void)verificationTrialForEmail:(NSString *)email name:(NSString *)name {
  384. if (email.length <= 0) {
  385. return;
  386. }
  387. if (![self isConnectionAvailable]) {
  388. NSAlert *alert = [NSAlert alertWithMessageText:NSLocalizedString(@"Connection Error", nil)
  389. defaultButton:NSLocalizedString(@"OK", nil)
  390. alternateButton:nil
  391. otherButton:nil
  392. informativeTextWithFormat:NSLocalizedString(@"Please make sure your internet connection is available.", nil), nil];
  393. [alert runModal];
  394. return;
  395. }
  396. __block __typeof(self) blockSelf = self;
  397. self.progressIndicator.hidden = NO;
  398. [self.progressIndicator startAnimation:nil];
  399. [self.trialViewController setEnabled:NO];
  400. [[VerificationManager manager] trialForDays:7 email:email name:name complention:^(ActivityStatus status, NSDictionary *info, NSError *error) {
  401. blockSelf.progressIndicator.hidden = YES;
  402. [blockSelf.progressIndicator stopAnimation:nil];
  403. [blockSelf.trialViewController setEnabled:YES];
  404. if (error ||
  405. status != ActivityStatusTrial) {
  406. NSAlert *alert = [NSAlert alertWithMessageText:NSLocalizedString(@"Activation Error", nil)
  407. defaultButton:NSLocalizedString(@"Try Again", nil)
  408. alternateButton:nil
  409. otherButton:nil
  410. informativeTextWithFormat:NSLocalizedString(@"Failed to sign up for the free trial. Please make sure your internet connection is available and try again later.", nil), nil];
  411. [alert runModal];
  412. } else {
  413. blockSelf.type = KMVerificationTypeTrialSuccess;
  414. [blockSelf updateViewInfo];
  415. }
  416. }];
  417. }
  418. - (void)verificationActivate:(NSString *)license {
  419. if (license.length <= 0) {
  420. return;
  421. }
  422. if (![self isConnectionAvailable]) {
  423. NSAlert *alert = [NSAlert alertWithMessageText:NSLocalizedString(@"Connection Error", nil)
  424. defaultButton:NSLocalizedString(@"OK", nil)
  425. alternateButton:nil
  426. otherButton:nil
  427. informativeTextWithFormat:@"", nil];
  428. NSButton *accessryBtn = [[NSButton alloc] initWithFrame:CGRectMake(0, 0, 180, 44)];
  429. accessryBtn.autoresizingMask = NSViewMaxXMargin | NSViewMinYMargin | NSViewMaxYMargin;
  430. accessryBtn.bezelStyle = NSBezelStyleRegularSquare;
  431. accessryBtn.bordered = NO;
  432. accessryBtn.target = self;
  433. accessryBtn.action = @selector(accessryBtnClicked:);
  434. NSMutableAttributedString *mutAttrString = [[NSMutableAttributedString alloc] initWithString:NSLocalizedString(@"Please make sure your internet connection is available.", nil)];
  435. [mutAttrString addAttribute:NSUnderlineStyleAttributeName value:[NSNumber numberWithInteger:NSUnderlineStyleSingle] range:NSMakeRange(0, [mutAttrString length])];
  436. [mutAttrString addAttribute:NSFontAttributeName value:[NSFont systemFontOfSize:12] range:NSMakeRange(0, [mutAttrString length])];
  437. [mutAttrString addAttribute:NSForegroundColorAttributeName value:[KMAppearance KMColor_Interactive_M0] range:NSMakeRange(0, [mutAttrString length])];
  438. accessryBtn.attributedTitle = mutAttrString;
  439. NSRect rect = [mutAttrString boundingRectWithSize:CGSizeMake(180, MAXFLOAT) options:NSStringDrawingUsesLineFragmentOrigin | NSStringDrawingUsesFontLeading];
  440. CGRect frame = accessryBtn.frame;
  441. frame.size.height = rect.size.height;
  442. accessryBtn.frame = frame;
  443. alert.accessoryView = accessryBtn;
  444. [alert runModal];
  445. return;
  446. }
  447. __block __typeof(self) blockSelf = self;
  448. self.progressIndicator.hidden = NO;
  449. [self.progressIndicator startAnimation:nil];
  450. [self.activateViewController setEnabled:NO];
  451. NSDictionary *infoDic = @{@"cdkey":license};
  452. [[VerificationManager manager] activateDeviceWithInfo:infoDic complention:^(ActivityStatus status, NSDictionary *info, NSError *error) {
  453. blockSelf.progressIndicator.hidden = YES;
  454. [blockSelf.progressIndicator stopAnimation:nil];
  455. [blockSelf.activateViewController setEnabled:YES];
  456. if (error) {
  457. NSString *tTitle0 = NSLocalizedString(@"The license you have entered is not correct. Please enter valid license.", nil);
  458. NSString *tTitle1 = NSLocalizedString(@"If you have already purchased PDF Reader Pro for Mac, you should find your license in an email confirmation.", nil);
  459. NSString *message = [NSString stringWithFormat:@"%@\n\n%@", tTitle0, tTitle1];
  460. if (ActivityErrorTypeCDKeyEmpty == error.code) {
  461. message = [NSString stringWithFormat:@"%@\n\n%@", NSLocalizedString(@"License number can not be empty.", nil), @""];
  462. } else if (ActivityErrorTypeCDKeyNotExist == error.code) {
  463. message = [NSString stringWithFormat:@"%@\n\n%@", NSLocalizedString(@"License number does not exist.", nil), @""];
  464. } else if (ActivityErrorTypeOutNumber == error.code) {
  465. NSString *tMsg0 = NSLocalizedString(@"The devices connected to the license number has outnumbered.", nil);
  466. NSString *tMsg1 = NSLocalizedString(@"Please deactivate license on one of them, to use PDF Reader Pro on this computer", nil);
  467. message = [NSString stringWithFormat:@"%@\n\n%@", tMsg0, tMsg1];
  468. } else if (ActivityErrorTypeNetworkDisable == error.code) {
  469. message = NSLocalizedString(@"The network is unavailable.", nil);
  470. } else if (ActivityErrorTypeCDKeyExpire == error.code) {
  471. message = NSLocalizedString(@"The license number expired.", nil);
  472. } else if (ActivityErrorTypeInvalidInfo == error.code) {
  473. message = NSLocalizedString(@"Activation error. Please try to input correct license, or contact us.", nil);
  474. } else if (ActivityErrorTypeNotMatchProduct == error.code) {
  475. message = NSLocalizedString(@"The license number is wrong, please input right license which is for this app.", nil);
  476. } else if (ActivityErrorTypeFormatError == error.code) {
  477. message = NSLocalizedString(@"The license format is wrong. Please input correct license.", nil);
  478. }
  479. if ((ActivityErrorTypeUnknow == error.code) || (ActivityErrorTypeOutNumber == error.code) || (ActivityErrorTypeInvalidInfo == error.code)) {
  480. NSAlert *alert = [NSAlert alertWithMessageText:NSLocalizedString(@"Activation Error", nil)
  481. defaultButton:NSLocalizedString(@"Contact Us", nil)
  482. alternateButton:NSLocalizedString(@"Try Again", nil)
  483. otherButton:nil
  484. informativeTextWithFormat:message, nil];
  485. if ([alert runModal]) {
  486. [blockSelf verificationFeedback];
  487. }
  488. } else {
  489. if (ActivityErrorTypeNetworkDisable == error.code) {
  490. NSAlert *alert = [NSAlert alertWithMessageText:NSLocalizedString(@"Connection Error", nil)
  491. defaultButton:NSLocalizedString(@"OK", nil)
  492. alternateButton:nil
  493. otherButton:nil
  494. informativeTextWithFormat:@"", nil];
  495. NSButton *accessryBtn = [[NSButton alloc] initWithFrame:CGRectMake(0, 0, 180, 44)];
  496. accessryBtn.autoresizingMask = NSViewMaxXMargin | NSViewMinYMargin | NSViewMaxYMargin;
  497. accessryBtn.bezelStyle = NSBezelStyleRegularSquare;
  498. accessryBtn.bordered = NO;
  499. accessryBtn.target = self;
  500. accessryBtn.action = @selector(accessryBtnClicked:);
  501. NSMutableAttributedString *mutAttrString = [[NSMutableAttributedString alloc] initWithString:NSLocalizedString(@"Please make sure your internet connection is available.", nil)];
  502. [mutAttrString addAttribute:NSFontAttributeName value:[NSFont systemFontOfSize:12] range:NSMakeRange(0, [mutAttrString length])];
  503. [mutAttrString addAttribute:NSUnderlineStyleAttributeName value:[NSNumber numberWithInteger:NSUnderlineStyleSingle] range:NSMakeRange(0, [mutAttrString length])];
  504. [mutAttrString addAttribute:NSForegroundColorAttributeName value:[KMAppearance KMColor_Interactive_M0] range:NSMakeRange(0, [mutAttrString length])];
  505. accessryBtn.attributedTitle = mutAttrString;
  506. NSRect rect = [mutAttrString boundingRectWithSize:CGSizeMake(180, MAXFLOAT) options:NSStringDrawingUsesLineFragmentOrigin | NSStringDrawingUsesFontLeading];
  507. CGRect frame = accessryBtn.frame;
  508. frame.size.height = rect.size.height;
  509. accessryBtn.frame = frame;
  510. alert.accessoryView = accessryBtn;
  511. [alert runModal];
  512. } else {
  513. NSAlert *alert = [NSAlert alertWithMessageText:NSLocalizedString(@"Activation Error", nil)
  514. defaultButton:NSLocalizedString(@"Try Again", nil)
  515. alternateButton:nil
  516. otherButton:nil
  517. informativeTextWithFormat:message, nil];
  518. [alert runModal];
  519. }
  520. }
  521. } else {
  522. blockSelf.activityAlertViewController.alertTitle = NSLocalizedString(@"Successful activation!", nil);
  523. blockSelf.activityAlertViewController.alertMessage = NSLocalizedString(@"Congrats! You can start enjoying the advanced features of PDF Reader Pro.", nil);
  524. [blockSelf setContentView:blockSelf.activityAlertViewController.view];
  525. }
  526. }];
  527. }
  528. - (void)verificationBuy {
  529. #if VERSION_DMG
  530. NSURL *url = [NSURL URLWithString:@"https://www.pdfreaderpro.com/store?utm_source=MacAppDmg&utm_campaign=StoreLink&utm_medium=PdfStore"];
  531. if([SKInspectPublicTool currentisLanguageHans]) {
  532. url = [NSURL URLWithString:@"https://www.pdfreaderpro.com/zh-cn/store?utm_source=MacAppDmg&utm_campaign=StoreLink&utm_medium=PdfStore"];
  533. }
  534. [[NSWorkspace sharedWorkspace] openURL:url];
  535. #endif
  536. }
  537. #pragma - 验证错误时反馈信息
  538. - (void)verificationFeedback {
  539. unsigned major, minor, bugFix;
  540. [self getSystemVersionMajor:&major minor:&minor bugFix:&bugFix];
  541. NSString *versionString = [NSString stringWithFormat:@"%@ - %u.%u.%u", [GBDeviceInfo deviceInfo].rawSystemInfoString, major, minor, bugFix];
  542. //application version (use short version preferentially)
  543. NSString *tAppVersion = [[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBundleShortVersionString"];
  544. if ([tAppVersion length] < 1) {
  545. tAppVersion = [[NSBundle mainBundle] objectForInfoDictionaryKey:(NSString *)kCFBundleVersionKey];
  546. }
  547. NSString* subjects = [[self getAppNameForSupportEmail] stringByAppendingFormat:NSLocalizedString(@" - %@;Verification Feedback;%@", nil) ,tAppVersion,versionString];
  548. // [KMMailHelper newEmailWithContacts:@"support@pdfreaderpro.com" andSubjects:subjects];
  549. }
  550. - (void)unbindAction {
  551. unsigned major, minor, bugFix;
  552. [self getSystemVersionMajor:&major minor:&minor bugFix:&bugFix];
  553. NSString *versionString = [NSString stringWithFormat:@"%@ - %u.%u.%u", [GBDeviceInfo deviceInfo].rawSystemInfoString, major, minor, bugFix];
  554. //application version (use short version preferentially)
  555. NSString *tAppVersion = [[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBundleShortVersionString"];
  556. if ([tAppVersion length] < 1) {
  557. tAppVersion = [[NSBundle mainBundle] objectForInfoDictionaryKey:(NSString *)kCFBundleVersionKey];
  558. }
  559. NSString *subjects = [[self getAppNameForEmail] stringByAppendingString:[NSString stringWithFormat:@" %@",@"Verification:"]];
  560. subjects = [subjects stringByAppendingString:[NSString stringWithFormat:@"%@;",tAppVersion]];
  561. subjects = [subjects stringByAppendingString:[NSString stringWithFormat:@" %@;",versionString]];
  562. subjects = [subjects stringByAppendingString:[NSString stringWithFormat:@" %@",NSLocalizedString(@"Unbind License Code:", nil)]];
  563. subjects = [subjects stringByAppendingString:[NSString stringWithFormat:@"%@",[VerificationManager manager].detailInfo[@"device"][@"unique_sn"]?:@""]];
  564. 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)]];
  565. [[NSWorkspace sharedWorkspace] openURL:[NSURL URLWithString:mailtoAddress]];
  566. }
  567. - (void)accessryBtnClicked:(NSButton *)btn {
  568. [[NSWorkspace sharedWorkspace] openURL:[NSURL URLWithString:@"https://www.pdfreaderpro.com/mac/help/activate-license-code-mac"]];
  569. }
  570. - (NSString *)URLEncodedString:(NSString *)string {
  571. CFStringRef stringRef = CFBridgingRetain(string);
  572. #pragma clang diagnostic push
  573. #pragma clang diagnostic ignored "-Wdeprecated-declarations"
  574. CFStringRef encoded = CFURLCreateStringByAddingPercentEscapes(kCFAllocatorDefault,
  575. stringRef,
  576. NULL,
  577. CFSTR("!*'\"();:@&=+$,/?%#[]% "),
  578. kCFStringEncodingUTF8);
  579. #pragma clang diagnostic pop
  580. CFRelease(stringRef);
  581. return CFBridgingRelease(encoded);
  582. }
  583. - (void)getSystemVersionMajor:(unsigned *)major
  584. minor:(unsigned *)minor
  585. bugFix:(unsigned *)bugFix {
  586. OSErr err;
  587. SInt32 systemVersion, versionMajor, versionMinor, versionBugFix;
  588. if ([[NSProcessInfo processInfo] respondsToSelector:@selector(operatingSystemVersion)]) {
  589. NSOperatingSystemVersion osSystemVersion = [[NSProcessInfo processInfo] operatingSystemVersion];
  590. *major = (unsigned)osSystemVersion.majorVersion;
  591. *minor = (unsigned)osSystemVersion.minorVersion;
  592. *bugFix = (unsigned)osSystemVersion.patchVersion;
  593. return;
  594. } else {
  595. #pragma clang diagnostic push
  596. #pragma clang diagnostic ignored "-Wdeprecated-declarations"
  597. if ((err = Gestalt(gestaltSystemVersion, &systemVersion)) != noErr) goto fail;
  598. if (systemVersion < 0x1040)
  599. {
  600. if (major) *major = ((systemVersion & 0xF000) >> 12) * 10 +
  601. ((systemVersion & 0x0F00) >> 8);
  602. if (minor) *minor = (systemVersion & 0x00F0) >> 4;
  603. if (bugFix) *bugFix = (systemVersion & 0x000F);
  604. }
  605. else
  606. {
  607. if ((err = Gestalt(gestaltSystemVersionMajor, &versionMajor)) != noErr) goto fail;
  608. if ((err = Gestalt(gestaltSystemVersionMinor, &versionMinor)) != noErr) goto fail;
  609. if ((err = Gestalt(gestaltSystemVersionBugFix, &versionBugFix)) != noErr) goto fail;
  610. if (major) *major = versionMajor;
  611. if (minor) *minor = versionMinor;
  612. if (bugFix) *bugFix = versionBugFix;
  613. }
  614. return;
  615. #pragma clang diagnostic pop
  616. }
  617. fail:
  618. NSLog(@"Unable to obtain system version: %ld", (long)err);
  619. if (major) *major = 10;
  620. if (minor) *minor = 0;
  621. if (bugFix) *bugFix = 0;
  622. }
  623. - (NSString *)getAppNameForEmail {
  624. NSString *tAppName = @"PDF Reader Pro Mac";
  625. #if VERSION_FREE
  626. #if VERSION_DMG
  627. #else
  628. // AppStore 免费版本
  629. tAppName = @"PDF Reader Pro Lite";
  630. #endif
  631. #else
  632. // AppStore 付费版
  633. tAppName = @"PDF Reader Pro Edition";
  634. #endif
  635. return tAppName;
  636. }
  637. - (NSString *)getAppNameForSupportEmail {
  638. NSString *tAppName = @"PDF Reader Pro";
  639. #if VERSION_FREE
  640. #if VERSION_DMG
  641. // 桌机版
  642. VerificationManager *tManager = [VerificationManager manager];
  643. switch ([tManager status]) {
  644. case ActivityStatusTrial:
  645. tAppName = @"PDF Reader Pro Trial";
  646. break;
  647. case ActivityStatusVerification:
  648. tAppName = @"PDF Reader Pro Verification";
  649. break;
  650. case ActivityStatusTrialExpire:
  651. tAppName = @"PDF Reader Pro TrialExpire";
  652. break;
  653. case ActivityStatusVerifExpire:
  654. tAppName = @"PDF Reader Pro VerifExpire";
  655. break;
  656. default:
  657. break;
  658. }
  659. #else
  660. // AppStore 免费版本
  661. tAppName = @"PDF Reader Pro Lite";
  662. #endif
  663. #else
  664. // AppStore 付费版
  665. tAppName = @"PDF Reader Pro Edition";
  666. #endif
  667. return tAppName;
  668. }
  669. - (BOOL)isConnectionAvailable {
  670. BOOL isExistenceNetwork = YES;
  671. Reachability *reach = [Reachability reachabilityWithHostname:@"www.apple.com"];
  672. switch ([reach currentReachabilityStatus]) {
  673. case NotReachable:
  674. isExistenceNetwork = NO;
  675. //NSLog(@"notReachable");
  676. break;
  677. case ReachableViaWiFi:
  678. isExistenceNetwork = YES;
  679. //NSLog(@"WIFI");
  680. break;
  681. case ReachableViaWWAN:
  682. isExistenceNetwork = YES;
  683. //NSLog(@"3G");
  684. break;
  685. }
  686. if (NotReachable == [[Reachability reachabilityForInternetConnection] currentReachabilityStatus]) {
  687. return NO;
  688. }
  689. return YES;
  690. }
  691. #pragma mark - NSNotification
  692. - (void)themeChanged:(NSNotification *)notification {
  693. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.3 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
  694. [self updateViewColor];
  695. });
  696. }
  697. @end