Closed dadpp closed 8 years ago
static NSString * const BCURLProtocolHandledKey = @"BCURLProtocolHandledKey";
@interface BCCustomURLProtocol ()
@property (nonatomic, strong) NSURLConnection *connection;
@end
@implementation BCCustomURLProtocol
(BOOL)canInitWithRequest:(NSURLRequest )request { // NSLog(@"request %@",request); //只处理http和https请求 NSString scheme = [[request URL] scheme]; if ( ([scheme caseInsensitiveCompare:@"http"] == NSOrderedSame || [scheme caseInsensitiveCompare:@"https"] == NSOrderedSame)) { //看看是否已经处理过了,防止无限循环 if ([NSURLProtocol propertyForKey:BCURLProtocolHandledKey inRequest:request]) { return NO; }
return YES;
} return NO; }
(void)startLoading { // NSLog(@"startLoading = %@",[NSDate date]);
NSMutableURLRequest *mutableReqeust = [[self request] mutableCopy];
//打标签,防止无限循环 [NSURLProtocol setProperty:@YES forKey:BCURLProtocolHandledKey inRequest:mutableReqeust];
self.connection = [NSURLConnection connectionWithRequest:mutableReqeust delegate:self]; }
(void)connectionDidFinishLoading:(NSURLConnection *)connection {
[self.client URLProtocolDidFinishLoading:self]; }
+(NSMutableURLRequest)redirectHostInRequset:(NSMutableURLRequest)request { if ([request.URL host].length == 0) { return request; }
NSString *originUrlString = [request.URL absoluteString];
NSString *originHostString = [request.URL host];
NSRange hostRange = [originUrlString rangeOfString:originHostString];
if (hostRange.location == NSNotFound) {
return request;
}
NSLog(@"拦截到的URL===%@",[request.URL host]);
// NSLog(@"lanjie URL===%@",request.URL.description); return request; }
@end
Can you explain what this is?
@erkanyildiz NSURLProtocol custom
I mean the issue. Can you explain what kind of problem you experience and why do you think it has something to do with Countly SDK?
If you are trying to use Countly APM feature, it has issues with AFNetworking and some other 3rd party libraries: https://github.com/Countly/countly-sdk-ios/issues/82
If something else, please explain.
Use NSURLProtocol UIWebView loading, UIWebView loading out
Duplicate of #82
This sdk with a custom NSURLProtocol conflict, use only one