zoukankan      html  css  js  c++  java
  • Main Thread Checker 问题解决

    1. without a return value

    https://developer.apple.com/documentation/code_diagnostics/main_thread_checker

    NSURLSessionTask *task = [[NSURLSession sharedSession] dataTaskWithURL:url completionHandler:^(NSData * _Nullable data, NSURLResponse * _Nullable response, NSError * _Nullable error) {
        dispatch_async(dispatch_get_main_queue(), ^{ // Correct
            self.label.text = [NSString stringWithFormat:@"%lu bytes downloaded", data.length];
        });
    }];
    [task resume];
    

      

    let task = URLSession.shared.dataTask(with: url) { (data, response, error) in
       if let data = data {
          DispatchQueue.main.async { // Correct
             self.label.text = "(data.count) bytes downloaded"
          }
       }
    }
    task.resume()
    

      

    2. with a return value

    https://stackoverflow.com/questions/45832155/how-do-i-refactor-my-code-to-call-appdelegate-on-the-main-thread

    static var realDelegate: AppDelegate?;
    
    static var appDelegate: AppDelegate {
        if Thread.isMainThread{
            return UIApplication.shared.delegate as! AppDelegate;
        }
        let dg = DispatchGroup();
        dg.enter()
        DispatchQueue.main.async{
            realDelegate = UIApplication.shared.delegate as? AppDelegate;
            dg.leave();
        }
        dg.wait();
        return realDelegate!;
    }
  • 相关阅读:
    利用加载模块之外的地址绕过SafeSEH
    C++ 单实例运行
    添加程序以DLL函数
    HOOK地址还原
    利用未启用SafeSEH模块绕过SafeSEH
    SafeSEH基本概念+ 从堆区绕过SafeSEH学习
    替换.DATA的COOKIE突破GS
    虚函数绕过 GS保护 学习
    攻击虚函数学习
    虚函数学习
  • 原文地址:https://www.cnblogs.com/willbin/p/7883724.html
Copyright © 2011-2022 走看看