“我正在参与「启航计划」”

引言

  1. iOS webView加载的URL中不可以有中文符号的解决计划:把url中含有的中文字符转化为UTF8编码
  2. URL特别字符处理
  3. 判别是否契合数字和链接的规矩来判别是否射中淘口令的格局
  4. Url格局校验

I URL编码

1.1 UTF8编码


 url = [url stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
 WebViewController *webVC = [[WebViewController alloc] initWithAddress:url];

1.2 URL特别字符处理

/**
 iOS URL 特别字符处理: url 编码(又叫做 percentcode 百分号编码)
 URLFragmentAllowedCharacterSet  "#%<>[\]^`{|}
 URLHostAllowedCharacterSet      "#%/<>?@\^`{|}
 URLPasswordAllowedCharacterSet  "#%/:<>?@[\]^`{|}
 URLPathAllowedCharacterSet      "#%;<>?[\]^`{|}
 URLQueryAllowedCharacterSet    "#%<>[\]^`{|}
 URLUserAllowedCharacterSet      "#%/:<>?@[\]^`
 */
+ (NSString *)percentUrl:(NSString *)oriUrl {
    if (IOS_VERSION < 9) {
        if ([oriUrl isKindOfClass:[NSString class]]) {
            oriUrl = [oriUrl stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
        }
    } else {
        if ([oriUrl isKindOfClass:[NSString class]]) {
            oriUrl = [oriUrl stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet URLQueryAllowedCharacterSet]];
        }
    }
    return oriUrl;
}

II 判别剪贴板内容是否契合数字和链接的规矩

背景:在iOS14中,假如APP读取剪切版的内容时,手机会弹出提示,提示哪个APP在获取剪切板内容。

iOS小技能:URL编码

读取UIPasteboardstringstringsURLURLsimageimagescolorcolors的时分会触发体系提示。 使用hasStringshasURLshasImageshasColors等办法的时分不会触发体系提示。

2.1 弹出提示的兼容计划:尽可能少的去调用会触发体系提示的办法

iOS14剪切板适配: 计划一:先判别剪切板内容的各式,假如契合规矩采纳读取。

例如app读取口令,可以判别是否契合数字和链接的规矩

计划二:使用changeCount来记载剪切板的数据是否发生变化

完好的demo 请 重视公号:iOS逆向

2.2 检测剪切板内容是否匹配

通过判别是否契合数字和链接的规矩来判别是否射中共享内容:采用剪切板内容检测形式和iOS 14供给的API detectPatternsForPatterns:completionHandler: detectPatternsForPatterns:inItemSet:completionHandler: 进行完成。

现在UIPasteboardDetectionPattern体系供给了三种内容检测形式:

  1. 数字 UIPasteboardDetectionPatternNumber

  2. 链接 UIPasteboardDetectionPatternProbableWebURL

  3. 查找UIPasteboardDetectionPatternProbableWebSearch

// Detection
/// Detects patterns in the first pasteboard item.
///
/// @param patterns Detect only these patterns.
/// @param completionHandler Receives which patterns were detected, or an error.
- (void)detectPatternsForPatterns:(NSSet<UIPasteboardDetectionPattern> *)patterns
                completionHandler:(void(^)(NSSet<UIPasteboardDetectionPattern> * _Nullable,
                                           NSError * _Nullable))completionHandler NS_REFINED_FOR_SWIFT API_AVAILABLE(ios(14.0));

口令的组成部分:数字+文字+链接的形势


- (void)pasteBoardCheckWithText:(NSString *)text {
    UIPasteboard *board = [UIPasteboard generalPasteboard];
    if (text.length > 0) {
        [board setString:text];
    }
    [board detectPatternsForPatterns:[NSSet setWithObjects:UIPasteboardDetectionPatternProbableWebURL, UIPasteboardDetectionPatternNumber, UIPasteboardDetectionPatternProbableWebSearch, nil]
                   completionHandler:^(NSSet<UIPasteboardDetectionPattern> * _Nullable set, NSError * _Nullable error) {
        BOOL hasNumber = NO, hasURL = NO;
        for (NSString *type in set) {
            if ([type isEqualToString:UIPasteboardDetectionPatternProbableWebURL]) {
                hasURL = YES;
            } else if ([type isEqualToString:UIPasteboardDetectionPatternNumber]) {
                hasNumber = YES;
            }
        }
        if (hasNumber && hasURL) {
            dispatch_async(dispatch_get_main_queue(), ^{
                UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"tip" message:[NSString stringWithFormat:@"%@\n%@", [board string], @"契合口令的格局"] preferredStyle:UIAlertControllerStyleAlert];
                UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:@"sure" style:UIAlertActionStyleCancel handler:nil];
                [alert addAction:cancelAction];
                [self presentViewController:alert animated:YES completion:nil];
            });
        }
    }];
}

2.3 检测剪切板的数据是否发生变化

iOS小技能:URL编码

记载一下真正读取剪切板时的changeCount,假如下次读取的时分没有发生变化则不读取。 这样一来效果就好多了,应用运转生命周期内,基本上只会弹出一次提示

III Url格局校验

+(BOOL)isUrl:(NSString *)url{
    NSString *regex =@"[a-zA-z]+://[^\\s]*";
    NSPredicate *urlTest = [NSPredicate predicateWithFormat:@"SELF MATCHES %@",regex];
    return [urlTest evaluateWithObject:url];
}

blog.csdn.net/z929118967/…

see also

公号:iOS逆向