「这是我参与2022初次更文应战的第9天,活动详情查看:2022初次更文应战」。

前语

了解监管要求,掌握合规操作流程,避免App被降级或许下架。

需要确保App有《隐私方针》,并且在用户初次启动App时就弹出《隐私方针》取得用户赞同。

登录界面弹用户协议及隐私方针时,假如用户点击不赞同,不能停留在弹框界面,需要隐藏弹框,不然无法经过OPPO安卓应用商场。

iOS隐私安全:用户协议及隐私政策弹框(包含超链接属性、demo支持中英文切换)

《用户协议及隐私方针》 弹框的完成步骤:

1、自定义TextView,选用富文本特点进行内容设置attributedText(包括下划线NSUnderlineStyleSingle、超链接NSLinkAttributeName 、色彩NSForegroundColorAttributeName 等信息) 2、完成署理办法textView:shouldInteractWithURL:inRange,处理点击超链接的回调(打开对应URL Webview)

  • 效果图(点击demo的右上架文字进行中英文切换

iOS隐私安全:用户协议及隐私政策弹框(包含超链接属性、demo支持中英文切换)
iOS隐私安全:用户协议及隐私政策弹框(包含超链接属性、demo支持中英文切换)

  • 文本框信息对应的中英文key,用于本地化

"Explain3" = "向您说明,在运用咱们的服务时,咱们如何搜集、运用、贮存和分享这些信息,以及咱们为您供给的访问、更新、控制和保护这些信息的方式。本";
"Wemaycollect1"="您在运用咱们的服务时,咱们可能会搜集和运用您的相关信息。咱们希望经过本";
"then_click_Agree" = " ,希望您仔细阅读,充沛了解协议中的内容后再点击赞同。";
"Wemaycollect1"="We may collect and use information about you when you use our services. We hope to pass this";
"Explain3"= "Explain to you how we collect, use, store and share this information and how we provide you with access, update, control and protection when using our services. this";
"then_click_Agree"= "  , I hope you read it carefully, fully understand the content of the agreement, and then click Agree.";

从csdn资源下载demo源码:download.csdn.net/download/u0…

I、 自定义TextView: QCTTextViewHyperLink

选用富文本特点进行内容设置attributedText

从csdn资源下载demo源码:https://download.csdn.net/download/u011018979/14026773

CSDN文章:kunnan.blog.csdn.net/article/det… demo源码 : 存放在GitHub私有库房 demo源码 : csdn私有库房

1.1 选用富文本特点进行内容设置

attributedText

包括下划线NSUnderlineStyleSingle、 超链接NSLinkAttributeName 、 色彩NSForegroundColorAttributeName 等信息

  • 新增超链接特点

        [attrStr addAttribute:NSLinkAttributeName value:k_serviceAgreement_URL range:str4Range];
        [attrStr addAttribute:NSLinkAttributeName value:k_serviceAgreement_URL range:str2Range];
        tmp.editable = NO;
        tmp.attributedText = attrStr;//text
            tmp.selectedRange = NSMakeRange(attrStr.length, 0);
        tmp.delegate = self;
        tmp.userInteractionEnabled = YES;
  • 设置下划线和色彩
    [attrStr setAttributes:@{NSUnderlineStyleAttributeName : @(NSUnderlineStyleSingle)}
                     range:str4Range];
    [attrStr addAttribute:NSFontAttributeName value:kPingFangFont(13) range:str4Range];
    [attrStr addAttribute:NSForegroundColorAttributeName value:HWColor(6, 53, 253) range:str4Range];

1.2 完成署理办法

  • 处理点击超链接的回调(打开对应URL Webview)
- (BOOL)textView:(UITextView *)textView shouldInteractWithURL:(NSURL *)URL inRange:(NSRange)characterRange {

/**
 署理办法
 */
- (BOOL)textView:(UITextView *)textView shouldInteractWithURL:(NSURL *)URL inRange:(NSRange)characterRange {
    __weak __typeof__(self) weakSelf = self;
    if([URL.absoluteString isEqualToString:k_serviceAgreement_URL]){
        [self.viewModel.hiddenQCTserviceAgreementViewSubject sendNext:nil];
        void (^showQCTserviceAgreementViewBlock)(id sender) = ^void(id sender) {
            NSLog(@"nil");
            // 展现
            [weakSelf.viewModel.showQCTserviceAgreementViewSubject sendNext:nil];
        };
                                        [self.viewModel.User_Agreement_and_Privacy_PolicySubject sendNext:showQCTserviceAgreementViewBlock];
    }
//
    return NO;
}

II、封装《用户协议及隐私方针》视图

  • 获取带有富文本字符串的TextView视图
//
//  QCTTextViewHyperLink.m
//  retail
//
//  Created by mac on 2020/1/9.
//  Copyright  2020 QCT. All rights reserved.
//
#import "QCTTextViewHyperLink.h"
@implementation QCTTextViewHyperLink
/**
 获取 《用户协议及隐私方针》的数据
 @return《用户协议及隐私方针》的数据
 */
+ (instancetype)getserviceAgreemenTextView{
    QCTTextViewHyperLink * tmp  = [QCTTextViewHyperLink new];
    NSString *str1 = QCTLocal(@"Wemaycollect1");
    NSString *str2 = [NSString stringWithFormat:@"《%@》",QCTLocal(@"Service_Agreement4User")];
    NSString *str3 = QCTLocal(@"Explain3");
    NSString *str4 = [NSString stringWithFormat:@"《%@》",QCTLocal(@"Service_Agreement4User")];
    NSString *str5 = QCTLocal(@"then_click_Agree");
    NSString *str = [NSString stringWithFormat:@"%@%@%@%@%@",str1,str2,str3,str4,str5];
    //1、 设置富文本特点
    NSMutableAttributedString *attrStr = [[NSMutableAttributedString alloc] initWithString:str];
    [attrStr addAttribute:NSFontAttributeName value:kPingFangFont(13) range:NSMakeRange(0 ,attrStr.length)];
    [attrStr addAttribute:NSForegroundColorAttributeName value:HWColor(51, 51, 51) range:NSMakeRange(0 ,attrStr.length)];
// 2、设置行lineSpacing
    NSMutableParagraphStyle *paragraphStyle = [NSMutableParagraphStyle new];
    paragraphStyle.lineSpacing = 5;
    NSMutableDictionary *attributes = [NSMutableDictionary dictionary];
    [attributes setObject:paragraphStyle forKey:NSParagraphStyleAttributeName];
    [attrStr addAttributes:attributes range:NSMakeRange(0, attrStr.length)];
    //        NSParagraphStyle defaultParagraphStyle
//3、设置下划线和色彩
    NSRange str2Range = NSMakeRange(str1.length, str2.length );
    NSRange str4Range = NSMakeRange(str1.length+str2.length+str3.length, str4.length );
    [attrStr setAttributes:@{NSUnderlineStyleAttributeName : @(NSUnderlineStyleSingle)}
                     range:str2Range];
    [attrStr addAttribute:NSFontAttributeName value:kPingFangFont(13) range:str2Range];
    [attrStr addAttribute:NSForegroundColorAttributeName value:HWColor(6, 53, 253) range:str2Range];
    [attrStr setAttributes:@{NSUnderlineStyleAttributeName : @(NSUnderlineStyleSingle)}
                     range:str4Range];
    [attrStr addAttribute:NSFontAttributeName value:kPingFangFont(13) range:str4Range];
    [attrStr addAttribute:NSForegroundColorAttributeName value:HWColor(6, 53, 253) range:str4Range];
    //4、新增超链接特点
    [attrStr addAttribute:NSLinkAttributeName value:k_serviceAgreement_URL range:str4Range];
    [attrStr addAttribute:NSLinkAttributeName value:k_serviceAgreement_URL range:str2Range];
    tmp.editable = NO;
    tmp.attributedText = attrStr;//text
    tmp.selectedRange = NSMakeRange(attrStr.length, 0);
    //        tmp.userInteractionEnabled = YES;
    return tmp;
}
// 继承UITextView重写这个办法
- (BOOL)canPerformAction:(SEL)action withSender:(id)sender
{
    // 回来NO为禁用,YES为开启
    // 粘贴
    if (action == @selector(paste:)) return NO;
    // 剪切
    if (action == @selector(cut:)) return NO;
    // 仿制
    if (action == @selector(copy:)) return NO;
    // 选择
    if (action == @selector(select:)) return NO;
    // 选中全部
    if (action == @selector(selectAll:)) return NO;
    // 删除
    if (action == @selector(delete:)) return NO;
    // 分享
    if (action == @selector(share)) return NO;
    return [super canPerformAction:action withSender:sender];
}
@end

III、Q&A

因为篇幅原因,更多内容请重视 #小程序iOS逆向,只为你呈现有价值的信息,专注于移动端技术研究范畴;更多服务和咨询请重视#大众号:iOS逆向。