Files
yinmeng-ios/xplan-ios/Main/Login/View/CustomView/UserPrivacyView.m

240 lines
9.2 KiB
Mathematica
Raw Normal View History

2021-11-01 17:17:56 +08:00
//
// UserPrivacyView.m
// xplan-ios
//
// Created by on 2021/11/1.
//
#import "UserPrivacyView.h"
///Third
#import <Masonry/Masonry.h>
#import <YYText/YYText.h>
#import <AppTrackingTransparency/AppTrackingTransparency.h>
2021-12-06 17:31:52 +08:00
#import <UMCommon/UMCommon.h>
2021-11-01 17:17:56 +08:00
///Tool
2021-12-06 17:31:52 +08:00
#import "XPConstant.h"
2021-11-01 17:17:56 +08:00
#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 ()
2021-12-06 17:31:52 +08:00
///title
2021-11-01 17:17:56 +08:00
@property (nonatomic, strong) UILabel *titleLabel;
2021-12-06 17:31:52 +08:00
///
2021-11-01 17:17:56 +08:00
@property (nonatomic, strong) YYTextView *contentLabel;
2021-12-06 17:31:52 +08:00
///
@property (nonatomic,strong) UIStackView *stackView;
///
2021-11-01 17:17:56 +08:00
@property (nonatomic, strong) UIButton *confirmButton;
2021-12-06 17:31:52 +08:00
///退
@property (nonatomic, strong) UIButton *exitButton;
2021-11-01 17:17:56 +08:00
@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
2021-12-06 17:31:52 +08:00
///
[UMConfigure initWithAppkey:KeyWithType(keyType_UMengAppKey) channel:KeyWithType(keyType_UMengAppChannel)];
2021-11-01 17:17:56 +08:00
[TTPopup dismiss];
}
}
2021-12-06 17:31:52 +08:00
- (void)exitButtonClick:(UIButton *)sender {
[self exitApplication];
}
2021-11-01 17:17:56 +08:00
#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];
2021-12-06 17:31:52 +08:00
[self addSubview:self.stackView];
[self.stackView addArrangedSubview:self.exitButton];
[self.stackView addArrangedSubview:self.confirmButton];
2021-11-01 17:17:56 +08:00
}
- (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);
}];
2021-12-06 17:31:52 +08:00
[self.stackView mas_makeConstraints:^(MASConstraintMaker *make) {
2021-11-01 17:17:56 +08:00
make.bottom.mas_equalTo(-20);
2021-12-06 17:31:52 +08:00
make.left.right.mas_equalTo(self).inset(15);
2021-11-01 17:17:56 +08:00
make.height.mas_equalTo(36);
}];
2021-12-06 17:31:52 +08:00
2021-11-01 17:17:56 +08:00
}
- (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");
//1app
[ATTrackingManager requestTrackingAuthorizationWithCompletionHandler:^(ATTrackingManagerAuthorizationStatus status) {
NSLog(@"app追踪IDFA权限%lu",(unsigned long)status);
}];
}
break;
default:
break;
}
}
}
2021-12-06 17:31:52 +08:00
///退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);
}
}
2021-11-01 17:17:56 +08:00
#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;
}
2021-12-06 17:31:52 +08:00
2021-11-01 17:17:56 +08:00
- (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;
}
2021-12-06 17:31:52 +08:00
- (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;
}
2021-11-01 17:17:56 +08:00
@end