// // UserPrivacyView.m // xplan-ios // // Created by 冯硕 on 2021/11/1. // #import "UserPrivacyView.h" ///Third #import #import #import #import ///Tool #import "XPConstant.h" #import "ThemeColor.h" #import "XPMacro.h" #import "XPHtmlUrl.h" #import "TTPopup.h" #import "UIImage+Utils.h" ///VC #import "XPWebViewController.h" NSString * const kYinyouPrivateKey = @"kYinyouPrivateKey"; @interface UserPrivacyView () ///title @property (nonatomic, strong) UILabel *titleLabel; ///内容 @property (nonatomic, strong) YYTextView *contentLabel; ///容器 @property (nonatomic,strong) UIStackView *stackView; ///确认 @property (nonatomic, strong) UIButton *confirmButton; ///退出 @property (nonatomic, strong) UIButton *exitButton; @end @implementation UserPrivacyView - (instancetype)initWithFrame:(CGRect)frame { self = [super initWithFrame:frame]; if (self) { [self initSubViews]; [self initSubViewConstraints]; } return self; } #pragma mark - Response - (void)onAgreementButtonClick:(UIButton *)sender { if (sender == self.confirmButton) { NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults]; [defaults setObject:@"isShow" forKey:kYinyouPrivateKey]; [defaults synchronize]; [self getAdvertisingTrackingAuthority];//请求idfa权限 ///初始化友盟 [UMConfigure initWithAppkey:KeyWithType(keyType_UMengAppKey) channel:KeyWithType(keyType_UMengAppChannel)]; [TTPopup dismiss]; } } - (void)exitButtonClick:(UIButton *)sender { [self exitApplication]; } #pragma mark - Private Method - (void)initSubViews { self.backgroundColor = [UIColor whiteColor]; self.layer.masksToBounds = YES; self.layer.cornerRadius = 10; [self addSubview:self.titleLabel]; [self addSubview:self.contentLabel]; [self addSubview:self.stackView]; [self.stackView addArrangedSubview:self.exitButton]; [self.stackView addArrangedSubview:self.confirmButton]; } - (void)initSubViewConstraints { [self mas_makeConstraints:^(MASConstraintMaker *make) { make.width.mas_equalTo(KScreenWidth - 38 * 2); make.height.mas_equalTo(424); }]; [self.titleLabel mas_makeConstraints:^(MASConstraintMaker *make) { make.top.mas_equalTo(18); make.centerX.mas_equalTo(self); }]; [self.contentLabel mas_makeConstraints:^(MASConstraintMaker *make) { make.top.mas_equalTo(55); make.left.mas_equalTo(28); make.right.mas_equalTo(-28); make.bottom.mas_equalTo(-68); }]; [self.stackView mas_makeConstraints:^(MASConstraintMaker *make) { make.bottom.mas_equalTo(-20); make.left.right.mas_equalTo(self).inset(15); make.height.mas_equalTo(36); }]; } - (void)getAdvertisingTrackingAuthority { if (@available(iOS 14, *)) { ATTrackingManagerAuthorizationStatus status = ATTrackingManager.trackingAuthorizationStatus; switch (status) { case ATTrackingManagerAuthorizationStatusDenied: NSLog(@"用户拒绝IDFA"); break; case ATTrackingManagerAuthorizationStatusAuthorized: NSLog(@"用户允许IDFA"); break; case ATTrackingManagerAuthorizationStatusNotDetermined: { NSLog(@"用户未做选择或未弹窗IDFA"); //请求弹出用户授权框,只会在程序运行是弹框1次,除非卸载app重装,通地图、相机等权限弹框一样 [ATTrackingManager requestTrackingAuthorizationWithCompletionHandler:^(ATTrackingManagerAuthorizationStatus status) { NSLog(@"app追踪IDFA权限:%lu",(unsigned long)status); }]; } break; default: break; } } } ///退出app - (void)exitApplication { [TTPopup dismiss]; [UIView beginAnimations:@"exitApplication" context:nil]; [UIView setAnimationDuration:0.5]; [UIView setAnimationDelegate:self]; [UIView setAnimationTransition:UIViewAnimationTransitionCurlUp forView:self cache:NO]; [UIView setAnimationDidStopSelector:@selector(animationFinished:finished:context:)]; [UIView commitAnimations]; } - (void)animationFinished:(NSString *)animationID finished:(NSNumber *)finished context:(void *)context { if ([animationID compare:@"exitApplication"] == 0) { exit(0); } } #pragma mark - getters and setters - (UILabel *)titleLabel { if (!_titleLabel) { _titleLabel = [[UILabel alloc] init]; _titleLabel.font = [UIFont systemFontOfSize:16.f weight:UIFontWeightMedium]; _titleLabel.textColor = [ThemeColor alertTitleColor]; _titleLabel.text = [NSString stringWithFormat:@"“%@”隐私政策", AppName]; } return _titleLabel; } - (YYTextView *)contentLabel { if (!_contentLabel) { _contentLabel = [[YYTextView alloc]init]; _contentLabel.editable = NO; _contentLabel.showsVerticalScrollIndicator = NO; _contentLabel.showsHorizontalScrollIndicator = NO; NSMutableParagraphStyle *paragraphStyle = [NSMutableParagraphStyle new]; paragraphStyle.lineSpacing = 4; NSString * agreement = [NSString stringWithFormat:@"欢迎您使用%@。我们将通过《隐私政策》和《用户协议》帮助您了解我们收集、使用、存储和共享个人信息的情况,特别是我们所采集的个人信息类型与用途的对应关系。\n\n为了保障产品的正常运行,我们会收集您的部分必要信息。我们可能会收集联络方式等个人敏感信息,您有权拒绝向我们提供这些信息。我们不会向第三方共享、提供、转让或者从第三方获取您的个人信息,除非经过您的同意。\n\n", AppName]; NSMutableAttributedString *attStr = [[NSMutableAttributedString alloc] init]; NSAttributedString *att1 = [[NSAttributedString alloc] initWithString:agreement attributes:@{NSFontAttributeName : [UIFont systemFontOfSize:14], NSForegroundColorAttributeName : [ThemeColor textThirdColor], NSParagraphStyleAttributeName : paragraphStyle, NSKernAttributeName : @(1.0)}]; NSMutableAttributedString *att2 = [[NSMutableAttributedString alloc] initWithString:@"您可以查看完整的《隐私政策》和《用户协议》,如果您同意,请点击下方同意按钮开始接受我们的服务。" attributes:@{NSFontAttributeName : [UIFont systemFontOfSize:14 weight:UIFontWeightMedium], NSForegroundColorAttributeName : [ThemeColor textThirdColor], NSParagraphStyleAttributeName : paragraphStyle, NSKernAttributeName : @(1.0)}]; @kWeakify(self); [att2 yy_setTextHighlightRange:NSMakeRange(8, 6) color:[ThemeColor appMainColor] backgroundColor:[UIColor clearColor] tapAction:^(UIView * _Nonnull containerView, NSAttributedString * _Nonnull text, NSRange range, CGRect rect) { @kStrongify(self); [TTPopup dismiss]; XPWebViewController *web = [[XPWebViewController alloc] init]; web.url = URLWithType(kPrivacyURL); [self.controller.navigationController pushViewController:web animated:YES]; }]; [att2 yy_setTextHighlightRange:NSMakeRange(15, 6) color:[ThemeColor appMainColor] backgroundColor:[UIColor clearColor] tapAction:^(UIView * _Nonnull containerView, NSAttributedString * _Nonnull text, NSRange range, CGRect rect) { @kStrongify(self); [TTPopup dismiss]; XPWebViewController *web = [[XPWebViewController alloc] init]; web.url = URLWithType(kUserProtocalURL); [self.controller.navigationController pushViewController:web animated:YES]; }]; [attStr appendAttributedString:att1]; [attStr appendAttributedString:att2]; _contentLabel.attributedText = attStr; } return _contentLabel; } - (UIButton *)confirmButton { if (!_confirmButton) { _confirmButton = [[UIButton alloc]init]; [_confirmButton setTitle:@"同意" forState:UIControlStateNormal]; _confirmButton.titleLabel.font = [UIFont systemFontOfSize:15]; [_confirmButton setTitleColor:[ThemeColor mainTextColor] forState:UIControlStateNormal]; UIImage *image = [UIImage gradientColorImageFromColors:@[[ThemeColor confirmButtonGradientStartColor],[ThemeColor confirmButtonGradientEndColor]] gradientType:GradientTypeLeftToRight imgSize:CGSizeMake(10, 10)]; [_confirmButton setBackgroundImage:image forState:UIControlStateNormal]; _confirmButton.layer.cornerRadius = 18; _confirmButton.layer.masksToBounds = YES; [_confirmButton addTarget:self action:@selector(onAgreementButtonClick:) forControlEvents:UIControlEventTouchUpInside]; } return _confirmButton; } - (UIButton *)exitButton { if (!_exitButton) { _exitButton = [[UIButton alloc]init]; [_exitButton setTitle:@"不同意并退出" forState:UIControlStateNormal]; _exitButton.titleLabel.font = [UIFont systemFontOfSize:15]; [_exitButton setTitleColor:[ThemeColor cancelButtonTextColor] forState:UIControlStateNormal]; UIImage *image = [UIImage gradientColorImageFromColors:@[[ThemeColor cancelButtonGradientStartColor],[ThemeColor cancelButtonGradientEndColor]] gradientType:GradientTypeLeftToRight imgSize:CGSizeMake(10, 10)]; [_exitButton setBackgroundImage:image forState:UIControlStateNormal]; _exitButton.layer.cornerRadius = 18; _exitButton.layer.masksToBounds = YES; [_exitButton addTarget:self action:@selector(exitButtonClick:) forControlEvents:UIControlEventTouchUpInside]; } return _exitButton; } - (UIStackView *)stackView { if (!_stackView) { _stackView = [[UIStackView alloc] init]; _stackView.axis = UILayoutConstraintAxisHorizontal; _stackView.distribution = UIStackViewDistributionFillEqually; _stackView.alignment = UIStackViewAlignmentFill; _stackView.spacing = 20; } return _stackView; } @end