KMVerificationWindowController.m 50 KB

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