展开

关键词

AFNetworking源码探究(六) —— AFURLSessionManager(2)

:(void (^)(NSURLRequest *))completionHandler首先看一下系统的API接口* An HTTP request is attempting to perform a :(void (^)(NSURLRequest * _Nullable))completionHandler;下面看一下AFN中该代理方法的实现- (void)URLSession:(NSURLSession ) { completionHandler(redirectRequest); }}这里,主要做了下面几个逻辑:如果有对应的block taskWillPerformHTTPRedirection,那么就调用 接着就是利用生成的request重新请求if (completionHandler) { completionHandler(redirectRequest); }这个方法是在服务器去重定向的时候,才会被调用 ) { completionHandler(inputStream); }}该代理方法会在下面两种情况被调用如果task是由uploadTaskWithStreamedRequest:创建的,那么提供初始的

11330

iOS 使用WKWebView

{ 页面加载完成时 webView.evaluateJavaScript( document.documentElement.style.webkitUserSelect=none;, completionHandler : nil ); webView.evaluateJavaScript( document.documentElement.style.webkitTouchCallout=none;, completionHandler message: String, initiatedByFrame frame: WKFrameInfo, completionHandler: @escaping (Bool) -> Void) { , initiatedByFrame frame: WKFrameInfo, completionHandler: @escaping (String?) -> Void) { JS端调用prompt函数时,会触发此方法 要求输入一段文本 在原生输入得到文本内容后,通过completionHandler回调给JS let alertTextField

40910
  • 广告
    关闭

    云产品限时秒杀

    云服务器1核2G首年38元,还有多款热门云产品满足您的上云需求

  • 您找到你想要的搜索结果了吗?
    是的
    没有找到

    从AFNetworking源码分析到应用全解 原

    :(void (^)(NSURLRequest *))completionHandler{ NSURLRequest *redirectRequest = request; 这里会执行用户自定义的重定向 ) { completionHandler(redirectRequest); }}接收到安全认证挑战的回调- (void)URLSession:(NSURLSession *)session task :(NSURLSessionTask *)taskdidReceiveChallenge:(NSURLAuthenticationChallenge *)challenge completionHandler task:(NSURLSessionTask *)task needNewBodyStream:(void (^)(NSInputStream *bodyStream))completionHandler :(void (^)(NSCachedURLResponse *cachedResponse))completionHandler{ NSCachedURLResponse *cachedResponse

    1.5K50

    AFNetworking源码探究(七) —— AFURLSessionManager(3)

    :(void (^)(NSURLSessionResponseDisposition disposition))completionHandler;首先看一下苹果该方法的API* The task has :(void (^)(NSURLSessionResponseDisposition disposition))completionHandler;看一下AFN中该方法的实现- (void)URLSession :(void (^)(NSURLSessionResponseDisposition disposition))completionHandler{ NSURLSessionResponseDisposition :(void (^)(NSCachedURLResponse *cachedResponse))completionHandler{ NSCachedURLResponse *cachedResponse ) { completionHandler(cachedResponse); }}该方法的作用就是询问data task或上传任务(upload task)是否缓存response。

    12240

    WKWebView不显示JS的Alert,Confirm,TextInput弹框解决方法

    webView runJavaScriptAlertPanelWithMessage:(NSString *)message initiatedByFrame:(WKFrameInfo *)frame completionHandler :(void (^)(void))completionHandler { UIAlertController * alertController = ; UIAlertAction * action = webView runJavaScriptConfirmPanelWithMessage:(NSString *)message initiatedByFrame:(WKFrameInfo *)frame completionHandler :(void (^)(BOOL))completionHandler { UIAlertController *alertController = ; UIAlertAction * cancelAction :(void (^)(NSString * _Nullable))completionHandler { UIAlertController * alertController = ; ; UIAlertAction

    1.4K30

    WKWebView的使用与JS交互详细解读

    3.在原生得到结果后,需要回调给JS,通过completionHandler 回调给JS4.completionHandler 回调的参数和返回值都是空**下面这三个方法根据前面的字面意思就能区分记住! 在原生得到结果后,需要回调给JS,通过completionHandler 回调给JS completionHandler 回调的参数和返回值都是空-(void)webView:(WKWebView *) 注意点1.要求用户输入一段文字3.在原生输入得到文本内容后,通过completionHandler回调给JS 4.大家注意这个回调的completionHandler参数是字符串 runJavaScriptTextInput 要求用户输入一段文本 在原生输入得到文本内容后,通过completionHandler回调给JS 大家注意这个回调的completionHandler参数是字符串-(void)webView:(WKWebView :(NSString *)message initiatedByFrame:(WKFrameInfo *)frame completionHandler:(void (^)(BOOL))completionHandler

    98470

    Kingfisher源码阅读(二)

    : { (cacheImage, cacheType) -> () in completionHandler? options.cacheMemoryOnly, completionHandler: nil) } completionHandler? : completionHandler, forURL: request.URL!) : completionHandler, forURL: request.URL!) completionHandler(.UseCredential, credential) return } } 默认处理 completionHandler(.PerformDefaultHandling

    30850

    Kingfisher源码阅读(一)

    , completionHandler: CompletionHandler?) , completionHandler: CompletionHandler?) 第四个参数类型CompletionHandler也一样是个闭包类型的别名:public typealias CompletionHandler = ((image: UIImage? , completionHandler: CompletionHandler?) , completionHandler: CompletionHandler?

    90720

    SDWebImage 添加 token

    *)task willPerformHTTPRedirection:(NSHTTPURLResponse *)response newRequest:(NSURLRequest *)request completionHandler :(void (^)(NSURLRequest * _Nullable))completionHandler方法如下: - (void)URLSession:(NSURLSession *)session *)task willPerformHTTPRedirection:(NSHTTPURLResponse *)response newRequest:(NSURLRequest *)request completionHandler :(void (^)(NSURLRequest * _Nullable))completionHandler { Identify the operation that runs this task ) { completionHandler(customRequest); } }} 原理:简单的说是把 重定向的request 变为 CustomRequest, 然后给 CustomRequest

    7930

    iOS网络——AFNetworking AFURLSessionManager源码解析

    :(void (^)(NSURLRequest *))completionHandler{ 套路就是执行用户自定义的回调块,执行完成回调块 NSURLRequest *redirectRequest = ) { completionHandler(redirectRequest); }} 同前面一样,处理https链接- (void)URLSession:(NSURLSession *)session ) { completionHandler(disposition, credential); }}处理需要一个新的流- (void)URLSession:(NSURLSession *)session task:(NSURLSessionTask *)task needNewBodyStream:(void (^)(NSInputStream *bodyStream))completionHandler :(void (^)(NSCachedURLResponse *cachedResponse))completionHandler{ NSCachedURLResponse *cachedResponse

    76270

    iOS开发中的WKWebView与JS的交互

    webView runJavaScriptAlertPanelWithMessage:(NSString *)message initiatedByFrame:(WKFrameInfo *)frame completionHandler :(void (^)(void))completionHandler{     completionHandler(); NSLog(@3-----%@,message); }输出的message就是JS :(void (^)(BOOL result))completionHandler{     completionHandler(YES); NSLog(@-----%@,message); } 输出的 NSString *)prompt defaultText:(nullableNSString *)defaultText initiatedByFrame:(WKFrameInfo *)frame completionHandler :(void (^)(NSString *__nullable result))completionHandler{     completionHandler(@http); NSLog(@-----

    62120

    Kingfisher源码阅读(三)

    , completionHandler: CompletionHandler? options.cacheMemoryOnly, completionHandler: nil) } completionHandler? Not start working and early return.guard let completionHandler = completionHandler else { return nil} , forKey: key, toDisk: false, completionHandler: nil) dispatch_async(options.queue, { () -> Void in completionHandler = completionHandler { completionHandler() }})缓存模块的主要内容就这些了,其他还有一些辅助方法像计算缓存尺寸啊、图片的排序啊、把图片URL进行MD5加密作为缓存文件名啊等等

    31840

    iOS开发·网络请求方法总结复习(NSURLConnection,NSURLSession,AFNetworking)

    .+ (void)sendAsynchronousRequest:(NSURLRequest*) request queue:(NSOperationQueue*) queue completionHandler :(void (^)(NSURLSessionResponseDisposition))completionHandler{ 2.接收到服务器返回数据的时候会调用该方法,如果数据较大那么该方法可能会调用多次 --%@,); 注意:需要使用completionHandler回调告诉系统应该如何处理服务器返回的数据 默认是取消的 * NSURLSessionResponseCancel = 0, 默认的处理方式 NSURLSession的API是这样的:- (NSURLSessionDataTask *)dataTaskWithRequest:(NSURLRequest *)request completionHandler :(void (^)(NSURLResponse *response, id responseObject, NSError *error))completionHandler{ return ;}-

    93630

    使用WKWebView替换UIWebView

    WKWebView, runJavaScriptAlertPanelWithMessage message: String, initiatedByFrame frame: WKFrameInfo, completionHandler : @escaping () -> Void) { self.showNoticeText(message, time: 1.2) completionHandler();}确认弹窗func webView WKWebView, runJavaScriptConfirmPanelWithMessage message: String, initiatedByFrame frame: WKFrameInfo, completionHandler , initiatedByFrame frame: WKFrameInfo, completionHandler: @escaping (String?) -> Void) { completionHandler(哈哈);}交互Swift调用JS方法self.webview.evaluateJavaScript(loadData(123)) { (obj,

    1K10

    iOS HTTPS 请求 Code=-999 cancelled

    void)URLSession:(NSURLSession *)session didReceiveChallenge:(NSURLAuthenticationChallenge *)challenge completionHandler :(void (^)(NSURLSessionAuthChallengeDisposition, NSURLCredential * _Nullable))completionHandler { 不校验证书 - 信任所有证书 completionHandler(NSURLSessionAuthChallengeUseCredential, initWithTrust:challenge.protectionSpace.serverTrust public override func urlSession(_ session: URLSession, didReceive challenge: URLAuthenticationChallenge, completionHandler -> Void) { 不校验证书 - 信任所有证书 completionHandler(.useCredential, URLCredential(trust: challenge.protectionSpace.serverTrust

    1.3K20

    WKWebView

    :(void (^ __nullable)(__nullable id, NSError * __nullable error))completionHandler; 标识是否支持左、右swipe手势是否可以前进 :(NSArray *)dataRecords completionHandler:(void (^)(void))completionHandler; 删除某些指定类型的数据且修改日期是指定的日期- (void)removeDataOfTypes:(NSSet *)websiteDataTypes modifiedSince:(NSDate *)date completionHandler:(void :(NSString *)message initiatedByFrame:(WKFrameInfo *)frame completionHandler:(void (^)(BOOL result))completionHandler :(void (^)(NSString * __nullable result))completionHandler; @end```` ## WKBackForwardList WKBackForwardList

    44110

    AFNetworking源码探究(五) —— AFURLSessionManager

    void)URLSession:(NSURLSession *)sessiondidReceiveChallenge:(NSURLAuthenticationChallenge *)challenge completionHandler :(void (^)(NSURLSessionAuthChallengeDisposition disposition, NSURLCredential *credential))completionHandler :(void (^)(NSURLSessionAuthChallengeDisposition disposition, NSURLCredential *credential))completionHandler ) { completionHandler(disposition, credential); }}这里其实就是HTTPS认证,服务器向客户端进行质询和挑战。 最后调用completionHandler回应服务器端的挑战。

    5730

    WKWebView 那些坑

    ;completionHandler没有执行导致的。 WKWebView is visible*) ; else completionHandler(); } 确保上面两种情况下completionHandler都能被执行,消除了WKWebView下弹alert WKWebView退出并被释放后导致completionHandler变成野指针,而此时javaScript Core还在执行JS代码,待javaScript Core执行完毕后会执行completionHandler : https:trac.webkit.orgchangeset179160); 对于IOS8系统,可以通过在completionHandler里retain WKWebView防止completionHandler :(void (^)(id, NSError *))completionHandler { id strongSelf = self; ; if (completionHandler) { completionHandler

    11.5K21

    AVKit框架详细解析(三) —— 基于视频播放器的画中画实现(二)

    : @escaping (Bool) -> Void ) { restore(playerViewController: playerViewController, completionHandler: completionHandler) }} extension CategoryListViewController: CustomPlayerViewControllerDelegate { func : @escaping (Bool) -> Void ) { restore(playerViewController: playerViewController, completionHandler: , completionHandler: @escaping (Bool) -> Void) { if let presentedViewController = presentedViewController , animated: false) { completionHandler(true) } } }}8.

    8310

    iOS的WebView——WKWebView

    NSString *)prompt defaultText:(nullable NSString *)defaultText initiatedByFrame:(WKFrameInfo *)frame completionHandler :(void (^)(NSString * __nullable result))completionHandler{ completionHandler(@http);} 确认框- (void)webView :(void (^)(BOOL result))completionHandler{ completionHandler(YES);} 警告框- (void)webView:(WKWebView *)webView runJavaScriptAlertPanelWithMessage:(NSString *)message initiatedByFrame:(WKFrameInfo *)frame completionHandler :(void (^)(void))completionHandler{ NSLog(@%@,message); completionHandler();}----js调用原生方法拦截url此方法的本质是

    96420

    扫码关注云+社区

    领取腾讯云代金券