// // KMVerificationWindowController.m // PDF Reader Pro Edition // // Created by 王帅 on 2018/5/8. // #import "KMVerificationWindowController.h" #import "KMVerificationViewController.h" #import "KMVerificationActivateViewController.h" #import "KMVerificationExpiredViewController.h" #import "KMVerificationTrialViewController.h" #import "KMVerificationAlertViewController.h" #import "KMActivityALertViewController.h" #import "KMVerificationInfoViewController.h" #import "VerificationManager.h" //#import "KMMailHelper.h" #import "GBDeviceInfo.h" #import "Reachability.h" //#import "SKInspectPublicTool.h" //#import "FMTrackEventManager.h" #import "KMRepeatTrialAlertController.h" #import "KMRepeatVerifyExpireController.h" #import @interface KMVerificationWindowController () @property (nonatomic, assign) KMVerificationType type; @property (nonatomic, assign) IBOutlet NSBox *box; @property (nonatomic, assign) IBOutlet NSProgressIndicator *progressIndicator; @property (nonatomic, retain) KMVerificationViewController *normalViewController; @property (nonatomic, retain) KMVerificationActivateViewController *activateViewController; @property (nonatomic, retain) KMVerificationExpiredViewController *expiredViewController; @property (nonatomic, retain) KMVerificationTrialViewController *trialViewController; @property (nonatomic, retain) KMVerificationAlertViewController *alertViewController; @property (nonatomic, retain) KMActivityALertViewController *activityAlertViewController; @property (nonatomic, retain) KMVerificationInfoViewController *infoViewController; @property (nonatomic, retain) KMRepeatTrialAlertController *repeatTrialAlertController;//二次试用提示弹窗 @property (nonatomic, retain) KMRepeatVerifyExpireController *repeatTrialExpireController;//二次试用过期弹窗 @property (nonatomic, retain) KMTrialSuccessController *trialSuccessController; @end @implementation KMVerificationWindowController + (void)launching { [VerificationManager manager]; } + (BOOL)allowsShowExpired { #if VERSION_DMG if ([VerificationManager manager].status == ActivityStatusTrialExpire && [VerificationManager manager].secondTrialEnabled == NO) { if (![[NSUserDefaults standardUserDefaults] objectForKey:@"allowTrialExpireShowKeyDMG"]) { [[NSUserDefaults standardUserDefaults] setObject:@"YES" forKey:@"allowTrialExpireShowKeyDMG"]; return YES; } } return NO; #else NSDate *lastTimeDate = [[NSUserDefaults standardUserDefaults] objectForKey:@"kVerificationExpiredShowLastTimeDateKay"]; if (lastTimeDate) { NSDate *date = [NSDate date]; NSTimeInterval time = [date timeIntervalSinceDate:lastTimeDate]; int days = ((int)time)/(3600*24); if (days < 15) { return NO; } } #endif return YES; } + (void)showExpiredInfo { if (ActivityStatusTrialExpire == [VerificationManager manager].status) { if ([KMVerificationWindowController allowsShowExpired]) { KMVerificationWindowController *vc = [KMVerificationWindowController verificationWithType:KMVerificationTypeTrialExpired]; [vc showWindow:nil]; [[NSUserDefaults standardUserDefaults] setObject:[NSDate date] forKey:@"kVerificationExpiredShowLastTimeDateKay"]; [[NSUserDefaults standardUserDefaults] synchronize]; } } else if (ActivityStatusVerifExpire == [VerificationManager manager].status) { if ([KMVerificationWindowController allowsShowExpired]) { KMVerificationWindowController *vc = [KMVerificationWindowController verificationWithType:KMVerificationTypeActivateExpired]; [vc showWindow:nil]; [[NSUserDefaults standardUserDefaults] setObject:[NSDate date] forKey:@"kVerificationExpiredShowLastTimeDateKay"]; [[NSUserDefaults standardUserDefaults] synchronize]; } } } + (BOOL)allowRepeatTrialAlertShow { //是否在开启APP时弹出二次试用弹窗提示框 if ([VerificationManager manager].secondTrialEnabled) { if (![[NSUserDefaults standardUserDefaults] objectForKey:@"allowRepeatTrialAlertShowKey"]) { return YES; } } return NO; } + (BOOL)allowRepeatTrialExpireShow { if ([VerificationManager manager].status == ActivityStatusTrialExpire && [VerificationManager manager].trialTimes == 2) { if (![[NSUserDefaults standardUserDefaults] objectForKey:@"allowRepeatTrialExpireShowKey"]) { return YES; } } return NO; } static KMVerificationWindowController *_currentWindowController = nil; + (KMVerificationWindowController *)verificationWithType:(KMVerificationType)type { if (_currentWindowController) { if (type != _currentWindowController.type) { [_currentWindowController close]; } else { return _currentWindowController; } } KMVerificationWindowController *vc = [[KMVerificationWindowController alloc] initWithType:type]; return vc; } #pragma mark Init Methods - (instancetype)initWithType:(KMVerificationType)type { if (self = [super initWithWindowNibName:@"KMVerificationWindowController"]) { _type = type; } return self; } - (void)dealloc { [NSDistributedNotificationCenter.defaultCenter removeObserver:self]; } #pragma mark - Getter Methods - (KMVerificationViewController *)normalViewController { if (!_normalViewController) { __block __typeof(self) blockSelf = self; _normalViewController = [[KMVerificationViewController alloc] init]; _normalViewController.callback = ^(NSInteger index) { if (index == 0) { [blockSelf setContentView:blockSelf.activateViewController.view]; } else if (index == 1) { if (KMVerificationTypeActivateExpired == self.type) { [blockSelf verificationFeedback]; } else { [blockSelf close]; } } else { [blockSelf verificationBuy]; } }; if (KMVerificationTypeTrialExpired == self.type) { _normalViewController.titleText = [NSString stringWithFormat: NSLocalizedString(@"Thank you for trying PDF Reader Pro", nil), Swift_oc_Tool.KMAPPNameValue_OC]; _normalViewController.messageText = NSLocalizedString(@"Your trial has expired. Buy Full version to annotate and edit PDF files.", nil); } else { _normalViewController.titleText = [NSString stringWithFormat: NSLocalizedString(@"%@ Activation", nil), Swift_oc_Tool.KMAPPNameValue_OC]; _normalViewController.messageText = NSLocalizedString(@"Buy Full Version to annotate and edit your PDF documents.", nil); } } return _normalViewController; } - (KMVerificationActivateViewController *)activateViewController { if (!_activateViewController) { __block __typeof(self) blockSelf = self; _activateViewController = [[KMVerificationActivateViewController alloc] init]; _activateViewController.callback = ^(NSInteger index, NSString *string) { if (index == 0) { if (blockSelf.callback) { blockSelf.callback(); blockSelf.callback = nil; [blockSelf close]; } else { if (KMVerificationTypeTrial == blockSelf.type) { [blockSelf setContentView:blockSelf.trialViewController.view]; } else if (KMVerificationTypeActivateExpired == blockSelf.type) { [blockSelf setContentView:blockSelf.expiredViewController.view]; } else { [blockSelf setContentView:blockSelf.normalViewController.view]; } } } else { if (blockSelf.type == KMVerificationTypeActivateAIInfo) { [blockSelf verificationActivateAIInfo:string]; } else { [blockSelf verificationActivate:string]; } } }; if (self.type == KMVerificationTypeActivateAIInfo) { _activateViewController.type = self.type; } } return _activateViewController; } - (KMVerificationExpiredViewController *)expiredViewController { if (!_expiredViewController) { __block __typeof(self) blockSelf = self; _expiredViewController = [[KMVerificationExpiredViewController alloc] init]; _expiredViewController.callback = ^(NSInteger index) { if (index == 0) { [blockSelf setContentView:blockSelf.activateViewController.view]; } else { [blockSelf verificationFeedback]; } }; } return _expiredViewController; } - (KMVerificationTrialViewController *)trialViewController { if (!_trialViewController) { __block __typeof(self) blockSelf = self; _trialViewController = [[KMVerificationTrialViewController alloc] init]; _trialViewController.callback = ^(NSInteger index, NSString *email, NSString *name) { if (index == 0) { [blockSelf setContentView:blockSelf.activateViewController.view]; } else { [blockSelf verificationTrialForEmail:email name:name]; } }; } return _trialViewController; } - (KMVerificationAlertViewController *)alertViewController { if (!_alertViewController) { __block __typeof(self) blockSelf = self; _alertViewController = [[KMVerificationAlertViewController alloc] init]; _alertViewController.callback = ^{ [blockSelf close]; }; _alertViewController.buyActionHandle = ^{ #if VERSION_DMG NSURL *url = [NSURL URLWithString:@"https://www.pdfreaderpro.com/store"]; if([SKInspectPublicTool currentisLanguageHans]) { url = [NSURL URLWithString:@"https://www.pdfreaderpro.com/zh-cn/store"]; } [[NSWorkspace sharedWorkspace] openURL:url]; #endif [[FMTrackEventManager defaultManager] trackEventWithEvent:@"PUW" withProperties:@{@"PUW_Btn":@"Btn_PUW_BuyNow-Trial"}]; [blockSelf close]; }; } return _alertViewController; } - (KMActivityALertViewController *)activityAlertViewController { if (!_activityAlertViewController) { __block __typeof(self) blockSelf = self; _activityAlertViewController = [[KMActivityALertViewController alloc] init]; _activityAlertViewController.callback = ^{ [blockSelf close]; }; } return _activityAlertViewController; } - (KMVerificationInfoViewController *)infoViewController { if (!_infoViewController) { __block __typeof(self) blockSelf = self; _infoViewController = [[KMVerificationInfoViewController alloc] init]; _infoViewController.callback = ^{ [blockSelf close]; }; _infoViewController.unbindAction = ^{ dispatch_async(dispatch_get_main_queue(), ^{ [blockSelf unbindAction]; }); }; } return _infoViewController; } - (KMRepeatTrialAlertController *)repeatTrialAlertController { if (!_repeatTrialAlertController) { __block __typeof(self) blockSelf = self; _repeatTrialAlertController = [[KMRepeatTrialAlertController alloc] init]; _repeatTrialAlertController.callback = ^(NSInteger clickIndex, KMRepeatTrialAlertController * _Nonnull tRController) { if (clickIndex == 0) { //免费试用 [blockSelf verificationTrialForEmail:[VerificationManager manager].email name:[VerificationManager manager].accountName] ; } else if (clickIndex == 1) { //了解更多 NSURL *url = [NSURL URLWithString:@"https://www.pdfreaderpro.com/store?utm_source=app_dmg&utm_medium=dmg_puw_sec_free_trial"]; if([SKInspectPublicTool currentisLanguageHans]) { url = [NSURL URLWithString:@"https://www.pdfreaderpro.com/zh-cn/store?utm_source=app_dmg&utm_medium=dmg_puw_sec_free_trial"]; } [[NSWorkspace sharedWorkspace] openURL:url]; [blockSelf close]; } else if (clickIndex == 2) { //输入序列码 KMVerificationWindowController *vc = [KMVerificationWindowController verificationWithType:KMVerificationTypeActivate]; vc.callback = ^{ }; [vc showWindow:nil]; } }; } return _repeatTrialAlertController; } - (KMRepeatVerifyExpireController *)repeatTrialExpireController { if (!_repeatTrialExpireController) { __block __typeof(self) blockSelf = self; _repeatTrialExpireController = [[KMRepeatVerifyExpireController alloc] init]; _repeatTrialExpireController.callback = ^(NSInteger clickIndex, KMRepeatVerifyExpireController * _Nonnull tRController) { if (clickIndex == 0) { [blockSelf setContentView:blockSelf.activateViewController.view]; } else if (clickIndex == 1) { [[FMTrackEventManager defaultManager] trackEventWithEvent:@"PUW" withProperties:@{@"PUW_Btn":@"Btn_PUW_SecondTrialExpire_Later"}]; [blockSelf close]; } else if (clickIndex == 2) { [[FMTrackEventManager defaultManager] trackEventWithEvent:@"PUW" withProperties:@{@"PUW_Btn":@"Btn_PUW_SecondTrialExpire_Buy"}]; [blockSelf verificationBuy]; } }; } return _repeatTrialExpireController; } - (KMTrialSuccessController *)trialSuccessController { if (!_trialSuccessController) { __block __typeof(self) blockSelf = self; _trialSuccessController = [[KMTrialSuccessController alloc] init]; _trialSuccessController.clickHandle = ^(KMTrialSuccessController * _Nonnull controller) { [blockSelf close]; }; } return _trialSuccessController; } #pragma mark Window Methods - (void)windowDidLoad { [super windowDidLoad]; // Implement this method to handle any initialization after your window controller's window has been loaded from its nib file. self.window.title = @""; [[self.window standardWindowButton:NSWindowZoomButton] setHidden:YES]; [[self.window standardWindowButton:NSWindowMiniaturizeButton] setHidden:YES]; [self updateViewInfo]; [self updateViewColor]; [NSDistributedNotificationCenter.defaultCenter addObserver:self selector:@selector(themeChanged:) name:@"AppleInterfaceThemeChangedNotification" object: nil]; } - (void)updateViewInfo { if (KMVerificationTypeNormal == self.type) { [self setContentView:self.normalViewController.view]; } else if (KMVerificationTypeActivate == self.type) { [self setContentView:self.activateViewController.view]; } else if (KMVerificationTypeTrial == self.type) { [self setContentView:self.trialViewController.view]; } else if (KMVerificationTypeActivateExpired == self.type) { [self setContentView:self.expiredViewController.view]; } else if (KMVerificationTypeTrialExpired == self.type) { [self setContentView:self.normalViewController.view]; } else if (KMVerificationTypeInfo == self.type) { [self setContentView:self.infoViewController.view]; } else if (KMVerificationTypeRepeatTrialGuide == self.type) { self.window.title = @""; [self setContentView:self.repeatTrialAlertController.view]; [[NSUserDefaults standardUserDefaults] setObject:@"YES" forKey:@"allowRepeatTrialAlertShowKey"]; [[NSUserDefaults standardUserDefaults] synchronize]; } else if (KMVerificationTypeRepeatTrialExpire == self.type) { [self setContentView:self.repeatTrialExpireController.view]; [[NSUserDefaults standardUserDefaults] setObject:@"YES" forKey:@"allowRepeatTrialExpireShowKey"]; [[NSUserDefaults standardUserDefaults] synchronize]; } else if (self.type == KMVerificationTypeTrialSuccess || self.type == KMVerificationTypeRepeatTrialSuccess) { [self setContentView:self.trialSuccessController.view]; } else if (KMVerificationTypeActivateAIInfo == self.type) { [self setContentView:self.activateViewController.view]; self.activateViewController.type = self.type; } } - (void)updateViewColor { if (KMVerificationTypeNormal == self.type) { } else if (KMVerificationTypeActivate == self.type) { } else if (KMVerificationTypeTrial == self.type) { } else if (KMVerificationTypeActivateExpired == self.type) { } else if (KMVerificationTypeTrialExpired == self.type) { } else if (KMVerificationTypeInfo == self.type) { } else if (KMVerificationTypeRepeatTrialGuide == self.type) { [self.repeatTrialAlertController updateViewColor]; } else if (KMVerificationTypeRepeatTrialExpire == self.type) { [self.repeatTrialExpireController updateViewColor]; } else if (KMVerificationTypeTrialSuccess == self.type || KMVerificationTypeRepeatTrialSuccess == self.type) { [self.trialSuccessController updateViewColor]; } } - (void)showWindow:(id)sender { if (!_currentWindowController) { _currentWindowController = self; } [super showWindow:sender]; } - (void)windowWillClose:(NSNotification *)notification { if (_currentWindowController) { _currentWindowController = nil; } } #pragma mark - Setter - (void)setContentView:(NSView *)view { NSRect frame = self.window.frame; frame.origin.y -= view.frame.size.height-frame.size.height; frame.origin.x -= (view.frame.size.width-frame.size.width)/2.0; frame.size.width = view.frame.size.width; frame.size.height = view.frame.size.height; [self.box setContentView:view]; [self.window setFrame:frame display:YES animate:YES]; } #pragma mark - Private Methods - (void)verificationTrialForEmail:(NSString *)email name:(NSString *)name { if (email.length <= 0) { return; } if (![self isConnectionAvailable]) { NSAlert *alert = [NSAlert alertWithMessageText:NSLocalizedString(@"Connection Error", nil) defaultButton:NSLocalizedString(@"OK", nil) alternateButton:nil otherButton:nil informativeTextWithFormat:NSLocalizedString(@"Please make sure your internet connection is available.", nil), nil]; [alert runModal]; return; } __block __typeof(self) blockSelf = self; self.progressIndicator.hidden = NO; [self.progressIndicator startAnimation:nil]; [self.trialViewController setEnabled:NO]; [[VerificationManager manager] trialForDays:7 email:email name:name complention:^(ActivityStatus status, NSDictionary *info, NSError *error) { blockSelf.progressIndicator.hidden = YES; [blockSelf.progressIndicator stopAnimation:nil]; [blockSelf.trialViewController setEnabled:YES]; if (error || status != ActivityStatusTrial) { NSAlert *alert = [NSAlert alertWithMessageText:NSLocalizedString(@"Activation Error", nil) defaultButton:NSLocalizedString(@"Try Again", nil) alternateButton:nil otherButton:nil informativeTextWithFormat:NSLocalizedString(@"Failed to sign up for the free trial. Please make sure your internet connection is available and try again later.", nil), nil]; [alert runModal]; } else { blockSelf.type = KMVerificationTypeTrialSuccess; [blockSelf updateViewInfo]; } }]; } - (void)verificationActivateAIInfo:(NSString *)license { if (license.length <= 0) { return; } if (![self isConnectionAvailable]) { NSAlert *alert = [NSAlert alertWithMessageText:NSLocalizedString(@"Connection Error", nil) defaultButton:NSLocalizedString(@"OK", nil) alternateButton:nil otherButton:nil informativeTextWithFormat:@"", nil]; NSButton *accessryBtn = [[NSButton alloc] initWithFrame:CGRectMake(0, 0, 180, 44)]; accessryBtn.autoresizingMask = NSViewMaxXMargin | NSViewMinYMargin | NSViewMaxYMargin; accessryBtn.bezelStyle = NSBezelStyleRegularSquare; accessryBtn.bordered = NO; accessryBtn.target = self; accessryBtn.action = @selector(accessryBtnClicked:); NSMutableAttributedString *mutAttrString = [[NSMutableAttributedString alloc] initWithString:NSLocalizedString(@"Please make sure your internet connection is available.", nil)]; [mutAttrString addAttribute:NSUnderlineStyleAttributeName value:[NSNumber numberWithInteger:NSUnderlineStyleSingle] range:NSMakeRange(0, [mutAttrString length])]; [mutAttrString addAttribute:NSFontAttributeName value:[NSFont systemFontOfSize:12] range:NSMakeRange(0, [mutAttrString length])]; [mutAttrString addAttribute:NSForegroundColorAttributeName value:[KMAppearance KMColor_Interactive_M0] range:NSMakeRange(0, [mutAttrString length])]; accessryBtn.attributedTitle = mutAttrString; NSRect rect = [mutAttrString boundingRectWithSize:CGSizeMake(180, MAXFLOAT) options:NSStringDrawingUsesLineFragmentOrigin | NSStringDrawingUsesFontLeading]; CGRect frame = accessryBtn.frame; frame.size.height = rect.size.height; accessryBtn.frame = frame; alert.accessoryView = accessryBtn; [alert runModal]; return; } __block __typeof(self) blockSelf = self; self.progressIndicator.hidden = NO; [self.progressIndicator startAnimation:nil]; [self.activateViewController setEnabled:NO]; NSDictionary *infoDic = @{@"cdkey":license}; [[AIInfoManager defaultManager] activateAIWithInfo:infoDic complention:^(NSDictionary *info, NSError *error) { blockSelf.progressIndicator.hidden = YES; [blockSelf.progressIndicator stopAnimation:nil]; [blockSelf.activateViewController setEnabled:YES]; if (error) { NSString *tTitle0 = NSLocalizedString(@"The license you have entered is not correct. Please enter valid license.", nil); NSString *tTitle1 = [NSString stringWithFormat:NSLocalizedString(@"Please confirm your %@ AI license code through the email you provided when purchasing.", nil), Swift_oc_Tool.KMAPPNameValue_OC]; NSString *message = [NSString stringWithFormat:@"%@\n\n%@", tTitle0, tTitle1]; if (ActivityErrorTypeCDKeyEmpty == error.code) { message = [NSString stringWithFormat:@"%@\n\n%@", NSLocalizedString(@"License number can not be empty.", nil), @""]; } else if (ActivityErrorTypeCDKeyNotExist == error.code) { message = [NSString stringWithFormat:@"%@\n\n%@", NSLocalizedString(@"License number does not exist.", nil), @""]; } else if (ActivityErrorTypeOutNumber == error.code) { NSString *tMsg0 = NSLocalizedString(@"The devices connected to the license number has outnumbered.", nil); NSString *tMsg1 = [NSString stringWithFormat:NSLocalizedString(@"Please deactivate license on one of them, to use %@ on this computer", nil), Swift_oc_Tool.KMAPPNameValue_OC]; message = [NSString stringWithFormat:@"%@\n\n%@", tMsg0, tMsg1]; } else if (ActivityErrorTypeNetworkDisable == error.code) { message = NSLocalizedString(@"The network is unavailable.", nil); } else if (ActivityErrorTypeCDKeyExpire == error.code) { message = NSLocalizedString(@"The license number expired.", nil); } else if (ActivityErrorTypeInvalidInfo == error.code) { message = NSLocalizedString(@"Activation error. Please try to input correct license, or contact us.", nil); } else if (ActivityErrorTypeNotMatchProduct == error.code) { message = NSLocalizedString(@"The license number is wrong, please input right license which is for this app.", nil); } else if (ActivityErrorTypeFormatError == error.code) { message = NSLocalizedString(@"Error license. Please enter an AI license.", nil); } if ((ActivityErrorTypeUnknow == error.code) || (ActivityErrorTypeOutNumber == error.code) || (ActivityErrorTypeInvalidInfo == error.code)) { NSAlert *alert = [NSAlert alertWithMessageText:NSLocalizedString(@"Activation Error", nil) defaultButton:NSLocalizedString(@"Contact Us", nil) alternateButton:NSLocalizedString(@"Try Again", nil) otherButton:nil informativeTextWithFormat:message, nil]; if ([alert runModal]) { [blockSelf verificationFeedback]; } } else { if (ActivityErrorTypeNetworkDisable == error.code) { NSAlert *alert = [NSAlert alertWithMessageText:NSLocalizedString(@"Connection Error", nil) defaultButton:NSLocalizedString(@"OK", nil) alternateButton:nil otherButton:nil informativeTextWithFormat:@"", nil]; NSButton *accessryBtn = [[NSButton alloc] initWithFrame:CGRectMake(0, 0, 180, 44)]; accessryBtn.autoresizingMask = NSViewMaxXMargin | NSViewMinYMargin | NSViewMaxYMargin; accessryBtn.bezelStyle = NSBezelStyleRegularSquare; accessryBtn.bordered = NO; accessryBtn.target = self; accessryBtn.action = @selector(accessryBtnClicked:); NSMutableAttributedString *mutAttrString = [[NSMutableAttributedString alloc] initWithString:NSLocalizedString(@"Please make sure your internet connection is available.", nil)]; [mutAttrString addAttribute:NSFontAttributeName value:[NSFont systemFontOfSize:12] range:NSMakeRange(0, [mutAttrString length])]; [mutAttrString addAttribute:NSUnderlineStyleAttributeName value:[NSNumber numberWithInteger:NSUnderlineStyleSingle] range:NSMakeRange(0, [mutAttrString length])]; [mutAttrString addAttribute:NSForegroundColorAttributeName value:[KMAppearance KMColor_Interactive_M0] range:NSMakeRange(0, [mutAttrString length])]; accessryBtn.attributedTitle = mutAttrString; NSRect rect = [mutAttrString boundingRectWithSize:CGSizeMake(180, MAXFLOAT) options:NSStringDrawingUsesLineFragmentOrigin | NSStringDrawingUsesFontLeading]; CGRect frame = accessryBtn.frame; frame.size.height = rect.size.height; accessryBtn.frame = frame; alert.accessoryView = accessryBtn; [alert runModal]; } else { NSAlert *alert = [NSAlert alertWithMessageText:NSLocalizedString(@"Activation Error", nil) defaultButton:NSLocalizedString(@"Try Again", nil) alternateButton:nil otherButton:nil informativeTextWithFormat:message, nil]; [alert runModal]; } } } else { blockSelf.activityAlertViewController.alertTitle = NSLocalizedString(@"Successful Activation!", nil); blockSelf.activityAlertViewController.alertMessage = [NSString stringWithFormat: NSLocalizedString(@"Congratulations! You can start using %@ AI features.", nil), Swift_oc_Tool.KMAPPNameValue_OC]; [blockSelf setContentView:blockSelf.activityAlertViewController.view]; } }]; } - (void)verificationActivate:(NSString *)license { if (license.length <= 0) { return; } if ([license hasPrefix:@"AI-"]) { NSAlert *alert = [NSAlert alertWithMessageText:NSLocalizedString(@"Activation Error", nil) defaultButton:NSLocalizedString(@"Try Again", nil) alternateButton:nil otherButton:nil 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]; [alert runModal]; return; } if (![self isConnectionAvailable]) { NSAlert *alert = [NSAlert alertWithMessageText:NSLocalizedString(@"Connection Error", nil) defaultButton:NSLocalizedString(@"OK", nil) alternateButton:nil otherButton:nil informativeTextWithFormat:@"", nil]; NSButton *accessryBtn = [[NSButton alloc] initWithFrame:CGRectMake(0, 0, 180, 44)]; accessryBtn.autoresizingMask = NSViewMaxXMargin | NSViewMinYMargin | NSViewMaxYMargin; accessryBtn.bezelStyle = NSBezelStyleRegularSquare; accessryBtn.bordered = NO; accessryBtn.target = self; accessryBtn.action = @selector(accessryBtnClicked:); NSMutableAttributedString *mutAttrString = [[NSMutableAttributedString alloc] initWithString:NSLocalizedString(@"Please make sure your internet connection is available.", nil)]; [mutAttrString addAttribute:NSUnderlineStyleAttributeName value:[NSNumber numberWithInteger:NSUnderlineStyleSingle] range:NSMakeRange(0, [mutAttrString length])]; [mutAttrString addAttribute:NSFontAttributeName value:[NSFont systemFontOfSize:12] range:NSMakeRange(0, [mutAttrString length])]; [mutAttrString addAttribute:NSForegroundColorAttributeName value:[KMAppearance KMColor_Interactive_M0] range:NSMakeRange(0, [mutAttrString length])]; accessryBtn.attributedTitle = mutAttrString; NSRect rect = [mutAttrString boundingRectWithSize:CGSizeMake(180, MAXFLOAT) options:NSStringDrawingUsesLineFragmentOrigin | NSStringDrawingUsesFontLeading]; CGRect frame = accessryBtn.frame; frame.size.height = rect.size.height; accessryBtn.frame = frame; alert.accessoryView = accessryBtn; [alert runModal]; return; } __block __typeof(self) blockSelf = self; self.progressIndicator.hidden = NO; [self.progressIndicator startAnimation:nil]; [self.activateViewController setEnabled:NO]; NSDictionary *infoDic = @{@"cdkey":license}; [[VerificationManager manager] activateDeviceWithInfo:infoDic complention:^(ActivityStatus status, NSDictionary *info, NSError *error) { blockSelf.progressIndicator.hidden = YES; [blockSelf.progressIndicator stopAnimation:nil]; [blockSelf.activateViewController setEnabled:YES]; if (error) { NSString *tTitle0 = NSLocalizedString(@"The license you have entered is not correct. Please enter valid license.", nil); NSString *tTitle1 = [NSString stringWithFormat: NSLocalizedString(@"If you have already purchased %@ for Mac, you should find your license in an email confirmation.", nil), Swift_oc_Tool.KMAPPNameValue_OC]; NSString *message = [NSString stringWithFormat:@"%@\n\n%@", tTitle0, tTitle1]; if (ActivityErrorTypeCDKeyEmpty == error.code) { message = [NSString stringWithFormat:@"%@\n\n%@", NSLocalizedString(@"License number can not be empty.", nil), @""]; } else if (ActivityErrorTypeCDKeyNotExist == error.code) { message = [NSString stringWithFormat:@"%@\n\n%@", NSLocalizedString(@"License number does not exist.", nil), @""]; } else if (ActivityErrorTypeOutNumber == error.code) { NSString *tMsg0 = NSLocalizedString(@"The devices connected to the license number has outnumbered.", nil); NSString *tMsg1 = [NSString stringWithFormat:NSLocalizedString(@"Please deactivate license on one of them, to use %@ on this computer", nil), Swift_oc_Tool.KMAPPNameValue_OC]; message = [NSString stringWithFormat:@"%@\n\n%@", tMsg0, tMsg1]; } else if (ActivityErrorTypeNetworkDisable == error.code) { message = NSLocalizedString(@"The network is unavailable.", nil); } else if (ActivityErrorTypeCDKeyExpire == error.code) { message = NSLocalizedString(@"The license number expired.", nil); } else if (ActivityErrorTypeInvalidInfo == error.code) { message = NSLocalizedString(@"Activation error. Please try to input correct license, or contact us.", nil); } else if (ActivityErrorTypeNotMatchProduct == error.code) { message = NSLocalizedString(@"The license number is wrong, please input right license which is for this app.", nil); } else if (ActivityErrorTypeFormatError == error.code) { message = NSLocalizedString(@"The license format is wrong. Please input correct license.", nil); } if ((ActivityErrorTypeUnknow == error.code) || (ActivityErrorTypeOutNumber == error.code) || (ActivityErrorTypeInvalidInfo == error.code)) { NSAlert *alert = [NSAlert alertWithMessageText:NSLocalizedString(@"Activation Error", nil) defaultButton:NSLocalizedString(@"Contact Us", nil) alternateButton:NSLocalizedString(@"Try Again", nil) otherButton:nil informativeTextWithFormat:message, nil]; if ([alert runModal]) { [blockSelf verificationFeedback]; } } else { if (ActivityErrorTypeNetworkDisable == error.code) { NSAlert *alert = [NSAlert alertWithMessageText:NSLocalizedString(@"Connection Error", nil) defaultButton:NSLocalizedString(@"OK", nil) alternateButton:nil otherButton:nil informativeTextWithFormat:@"", nil]; NSButton *accessryBtn = [[NSButton alloc] initWithFrame:CGRectMake(0, 0, 180, 44)]; accessryBtn.autoresizingMask = NSViewMaxXMargin | NSViewMinYMargin | NSViewMaxYMargin; accessryBtn.bezelStyle = NSBezelStyleRegularSquare; accessryBtn.bordered = NO; accessryBtn.target = self; accessryBtn.action = @selector(accessryBtnClicked:); NSMutableAttributedString *mutAttrString = [[NSMutableAttributedString alloc] initWithString:NSLocalizedString(@"Please make sure your internet connection is available.", nil)]; [mutAttrString addAttribute:NSFontAttributeName value:[NSFont systemFontOfSize:12] range:NSMakeRange(0, [mutAttrString length])]; [mutAttrString addAttribute:NSUnderlineStyleAttributeName value:[NSNumber numberWithInteger:NSUnderlineStyleSingle] range:NSMakeRange(0, [mutAttrString length])]; [mutAttrString addAttribute:NSForegroundColorAttributeName value:[KMAppearance KMColor_Interactive_M0] range:NSMakeRange(0, [mutAttrString length])]; accessryBtn.attributedTitle = mutAttrString; NSRect rect = [mutAttrString boundingRectWithSize:CGSizeMake(180, MAXFLOAT) options:NSStringDrawingUsesLineFragmentOrigin | NSStringDrawingUsesFontLeading]; CGRect frame = accessryBtn.frame; frame.size.height = rect.size.height; accessryBtn.frame = frame; alert.accessoryView = accessryBtn; [alert runModal]; } else { NSAlert *alert = [NSAlert alertWithMessageText:NSLocalizedString(@"Activation Error", nil) defaultButton:NSLocalizedString(@"Try Again", nil) alternateButton:nil otherButton:nil informativeTextWithFormat:message, nil]; [alert runModal]; } } } else { blockSelf.activityAlertViewController.alertTitle = NSLocalizedString(@"Successful Activation!", nil); blockSelf.activityAlertViewController.alertMessage = [NSString stringWithFormat: NSLocalizedString(@"Congrats! You are eligible to enjoy all advanced features (excluding AI) in %@.", nil), Swift_oc_Tool.KMAPPNameValue_OC]; [blockSelf setContentView:blockSelf.activityAlertViewController.view]; } }]; } - (void)verificationBuy { #if VERSION_DMG NSURL *url = [NSURL URLWithString:@"https://www.pdfreaderpro.com/store?utm_source=MacAppDmg&utm_campaign=StoreLink&utm_medium=PdfStore"]; if([SKInspectPublicTool currentisLanguageHans]) { url = [NSURL URLWithString:@"https://www.pdfreaderpro.com/zh-cn/store?utm_source=MacAppDmg&utm_campaign=StoreLink&utm_medium=PdfStore"]; } [[NSWorkspace sharedWorkspace] openURL:url]; #endif } #pragma - 验证错误时反馈信息 - (void)verificationFeedback { unsigned major, minor, bugFix; [self getSystemVersionMajor:&major minor:&minor bugFix:&bugFix]; NSString *versionString = [NSString stringWithFormat:@"%@ - %u.%u.%u", [GBDeviceInfo deviceInfo].rawSystemInfoString, major, minor, bugFix]; //application version (use short version preferentially) NSString *tAppVersion = [[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBundleShortVersionString"]; if ([tAppVersion length] < 1) { tAppVersion = [[NSBundle mainBundle] objectForInfoDictionaryKey:(NSString *)kCFBundleVersionKey]; } NSString* subjects = [[self getAppNameForSupportEmail] stringByAppendingFormat:NSLocalizedString(@" - %@;Verification Feedback;%@", nil) ,tAppVersion,versionString]; [KMMailHelper newEmailWithContacts:@"support@pdfreaderpro.com" andSubjects:subjects]; } - (void)unbindAction { unsigned major, minor, bugFix; [self getSystemVersionMajor:&major minor:&minor bugFix:&bugFix]; NSString *versionString = [NSString stringWithFormat:@"%@ - %u.%u.%u", [GBDeviceInfo deviceInfo].rawSystemInfoString, major, minor, bugFix]; //application version (use short version preferentially) NSString *tAppVersion = [[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBundleShortVersionString"]; if ([tAppVersion length] < 1) { tAppVersion = [[NSBundle mainBundle] objectForInfoDictionaryKey:(NSString *)kCFBundleVersionKey]; } NSString *subjects = [[self getAppNameForEmail] stringByAppendingString:[NSString stringWithFormat:@" %@",@"Verification:"]]; subjects = [subjects stringByAppendingString:[NSString stringWithFormat:@"%@;",tAppVersion]]; subjects = [subjects stringByAppendingString:[NSString stringWithFormat:@" %@;",versionString]]; subjects = [subjects stringByAppendingString:[NSString stringWithFormat:@" %@",NSLocalizedString(@"Unbind License Code:", nil)]]; subjects = [subjects stringByAppendingString:[NSString stringWithFormat:@"%@",[VerificationManager manager].detailInfo[@"device"][@"unique_sn"]?:@""]]; NSString *mailtoAddress = [NSString stringWithFormat:@"mailto:%@?Subject=%@&body=%@",@"support@pdfreaderpro.com",[self URLEncodedString:subjects],[self URLEncodedString:[NSString stringWithFormat: NSLocalizedString(@"Hi %@ Team, I need to unbind my license code, thanks!\nNotice: Please do not modify the subtitle content", nil), Swift_oc_Tool.KMAPPNameValue_OC]]]; [[NSWorkspace sharedWorkspace] openURL:[NSURL URLWithString:mailtoAddress]]; } - (void)accessryBtnClicked:(NSButton *)btn { [[NSWorkspace sharedWorkspace] openURL:[NSURL URLWithString:@"https://www.pdfreaderpro.com/mac/help/activate-license-code-mac"]]; } - (NSString *)URLEncodedString:(NSString *)string { CFStringRef stringRef = CFBridgingRetain(string); #pragma clang diagnostic push #pragma clang diagnostic ignored "-Wdeprecated-declarations" CFStringRef encoded = CFURLCreateStringByAddingPercentEscapes(kCFAllocatorDefault, stringRef, NULL, CFSTR("!*'\"();:@&=+$,/?%#[]% "), kCFStringEncodingUTF8); #pragma clang diagnostic pop CFRelease(stringRef); return CFBridgingRelease(encoded); } - (void)getSystemVersionMajor:(unsigned *)major minor:(unsigned *)minor bugFix:(unsigned *)bugFix { OSErr err; SInt32 systemVersion, versionMajor, versionMinor, versionBugFix; if ([[NSProcessInfo processInfo] respondsToSelector:@selector(operatingSystemVersion)]) { NSOperatingSystemVersion osSystemVersion = [[NSProcessInfo processInfo] operatingSystemVersion]; *major = (unsigned)osSystemVersion.majorVersion; *minor = (unsigned)osSystemVersion.minorVersion; *bugFix = (unsigned)osSystemVersion.patchVersion; return; } else { #pragma clang diagnostic push #pragma clang diagnostic ignored "-Wdeprecated-declarations" if ((err = Gestalt(gestaltSystemVersion, &systemVersion)) != noErr) goto fail; if (systemVersion < 0x1040) { if (major) *major = ((systemVersion & 0xF000) >> 12) * 10 + ((systemVersion & 0x0F00) >> 8); if (minor) *minor = (systemVersion & 0x00F0) >> 4; if (bugFix) *bugFix = (systemVersion & 0x000F); } else { if ((err = Gestalt(gestaltSystemVersionMajor, &versionMajor)) != noErr) goto fail; if ((err = Gestalt(gestaltSystemVersionMinor, &versionMinor)) != noErr) goto fail; if ((err = Gestalt(gestaltSystemVersionBugFix, &versionBugFix)) != noErr) goto fail; if (major) *major = versionMajor; if (minor) *minor = versionMinor; if (bugFix) *bugFix = versionBugFix; } return; #pragma clang diagnostic pop } fail: NSLog(@"Unable to obtain system version: %ld", (long)err); if (major) *major = 10; if (minor) *minor = 0; if (bugFix) *bugFix = 0; } - (NSString *)getAppNameForEmail { NSString *tAppName = @"PDF Reader Pro Mac"; #if VERSION_FREE #if VERSION_DMG #else // AppStore 免费版本 tAppName = @"PDF Reader Pro Lite"; #endif #else // AppStore 付费版 tAppName = @"PDF Reader Pro Edition"; #endif return tAppName; } - (NSString *)getAppNameForSupportEmail { NSString *tAppName = @"PDF Reader Pro"; #if VERSION_FREE #if VERSION_DMG // 桌机版 VerificationManager *tManager = [VerificationManager manager]; switch ([tManager status]) { case ActivityStatusTrial: tAppName = @"PDF Reader Pro Trial"; break; case ActivityStatusVerification: tAppName = @"PDF Reader Pro Verification"; break; case ActivityStatusTrialExpire: tAppName = @"PDF Reader Pro TrialExpire"; break; case ActivityStatusVerifExpire: tAppName = @"PDF Reader Pro VerifExpire"; break; default: break; } #else // AppStore 免费版本 tAppName = @"PDF Reader Pro Lite"; #endif #else // AppStore 付费版 tAppName = @"PDF Reader Pro Edition"; #endif return tAppName; } - (BOOL)isConnectionAvailable { BOOL isExistenceNetwork = YES; Reachability *reach = [Reachability reachabilityWithHostname:@"www.apple.com"]; switch ([reach currentReachabilityStatus]) { case NotReachable: isExistenceNetwork = NO; //NSLog(@"notReachable"); break; case ReachableViaWiFi: isExistenceNetwork = YES; //NSLog(@"WIFI"); break; case ReachableViaWWAN: isExistenceNetwork = YES; //NSLog(@"3G"); break; } if (NotReachable == [[Reachability reachabilityForInternetConnection] currentReachabilityStatus]) { return NO; } return YES; } #pragma mark - NSNotification - (void)themeChanged:(NSNotification *)notification { dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.3 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{ [self updateViewColor]; }); } + (void)verificationFeedback { unsigned major, minor, bugFix; [self getSystemVersionMajor:&major minor:&minor bugFix:&bugFix]; NSString *versionString = [NSString stringWithFormat:@"%@ - %u.%u.%u", [GBDeviceInfo deviceInfo].rawSystemInfoString, major, minor, bugFix]; NSString *tAppVersion = [[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBundleShortVersionString"]; if ([tAppVersion length] < 1) { tAppVersion = [[NSBundle mainBundle] objectForInfoDictionaryKey:(NSString *)kCFBundleVersionKey]; } NSString* subjects = [[self getAppNameForSupportEmail] stringByAppendingFormat:NSLocalizedString(@" - %@;Verification Feedback;%@", nil) ,tAppVersion,versionString]; [KMMailHelper newEmailWithContacts:@"support@pdfreaderpro.com" andSubjects:subjects]; } + (void)getSystemVersionMajor:(unsigned *)major minor:(unsigned *)minor bugFix:(unsigned *)bugFix; { OSErr err; SInt32 systemVersion, versionMajor, versionMinor, versionBugFix; if ([[NSProcessInfo processInfo] respondsToSelector:@selector(operatingSystemVersion)]) { NSOperatingSystemVersion osSystemVersion = [[NSProcessInfo processInfo] operatingSystemVersion]; *major = (unsigned)osSystemVersion.majorVersion; *minor = (unsigned)osSystemVersion.minorVersion; *bugFix = (unsigned)osSystemVersion.patchVersion; return; } else { #pragma clang diagnostic push #pragma clang diagnostic ignored "-Wdeprecated-declarations" if ((err = Gestalt(gestaltSystemVersion, &systemVersion)) != noErr) goto fail; if (systemVersion < 0x1040) { if (major) *major = ((systemVersion & 0xF000) >> 12) * 10 + ((systemVersion & 0x0F00) >> 8); if (minor) *minor = (systemVersion & 0x00F0) >> 4; if (bugFix) *bugFix = (systemVersion & 0x000F); } else { if ((err = Gestalt(gestaltSystemVersionMajor, &versionMajor)) != noErr) goto fail; if ((err = Gestalt(gestaltSystemVersionMinor, &versionMinor)) != noErr) goto fail; if ((err = Gestalt(gestaltSystemVersionBugFix, &versionBugFix)) != noErr) goto fail; if (major) *major = versionMajor; if (minor) *minor = versionMinor; if (bugFix) *bugFix = versionBugFix; } return; #pragma clang diagnostic pop } fail: NSLog(@"Unable to obtain system version: %ld", (long)err); if (major) *major = 10; if (minor) *minor = 0; if (bugFix) *bugFix = 0; } + (NSString *)getAppNameForSupportEmail { NSString *tAppName = @"PDF Reader Pro"; #if VERSION_FREE #if VERSION_DMG // 桌机版 VerificationManager *tManager = [VerificationManager manager]; switch ([tManager status]) { case ActivityStatusTrial: tAppName = @"PDF Reader Pro Trial"; break; case ActivityStatusVerification: tAppName = @"PDF Reader Pro Verification"; break; case ActivityStatusTrialExpire: tAppName = @"PDF Reader Pro TrialExpire"; break; case ActivityStatusVerifExpire: tAppName = @"PDF Reader Pro VerifExpire"; break; default: break; } #else // AppStore 免费版本 tAppName = @"PDF Reader Pro Lite"; #endif #else // AppStore 付费版 tAppName = @"PDF Reader Pro Edition"; #endif return tAppName; } @end