KMVerificationWindowController.m 49 KB

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