On Oct 20, 2014, at 6:47 PM, Daryle Walker <dary...@mac.com> wrote:

> Over the weekend, I read the Programming Guide corresponding to NSThread. I 
> just used one of the -performSelector: APIs. Easier than I anticipated, 
> except for the fact the code isn’t working right now. (That’s on the general 
> Cocoa list. Should I ask here too?)

Here’s a copy of that post, called “Can't get first try of NSURLProtocol 
subclass to work.”:

> I entered a URL that triggers my handler, but I get this from the Xcode debug 
> log:
> 
>> 2014-10-20 07:42:08.968 MyApp[94134:303] *** Assertion failure in -[NSWindow 
>> setTitle:], /SourceCache/AppKit/AppKit-1265.21/AppKit.subproj/NSWindow.m:2901
>> 2014-10-20 07:42:08.972 MyApp[94134:303] *** WebKit discarded an uncaught 
>> exception in the webView:didFinishLoadForFrame: delegate: 
>> <NSInternalInconsistencyException> Invalid parameter not satisfying: aString 
>> != nil
> 
> Here’s my -startLoading method. I tried “about:”, which is the only URL I 
> handle directly in the method.
> 
>> - (void)startLoading {
>>    NSAssert([self.class canInitWithRequest:self.request], @"Inappropriate 
>> request.");
>>    NSAssert(!self.processing, @"Receiving new protocol request while 
>> processing another.");
>> 
>>    // Handle the blank "about:" URL.
>>    NSString * const  path = self.request.URL.path;
>>    NSString * const  query = self.request.URL.query;
>> 
>>    if (!path || [path isEqualToString:@""]) {
>>        if (query) goto error;
>>        NSStringEncoding const  encoding = NSUTF8StringEncoding;
>>        NSData * const         aboutData = 
>> [@"<html><head><title>about</title></head><body>about:</body></html>" 
>> dataUsingEncoding:encoding];
>> 
>>        [self.client URLProtocol:self didReceiveResponse:[[NSURLResponse 
>> alloc] initWithURL:self.request.URL MIMEType:@"text/html" 
>> expectedContentLength:aboutData.length 
>> textEncodingName:nil/*(__bridge_transfer NSString 
>> *)CFStringConvertEncodingToIANACharSetName(CFStringConvertNSStringEncodingToEncoding(encoding))*/]
>>  cacheStoragePolicy:NSURLCacheStorageNotAllowed];
>>        [self.client URLProtocol:self didLoadData:aboutData];
>>        [self.client URLProtocolDidFinishLoading:self];
>>    } else {
>>        NSString * const  handler = AboutKeyToSelectorMap()[path];
>> 
>>        if (handler) {
>>            self.processing = [NSThread currentThread];
>>            self.cancelled = NO;
>>            [self performSelector:NSSelectorFromString(handler) 
>> withObject:query afterDelay:0.0 inModes:@[[NSRunLoop 
>> currentRunLoop].currentMode, NSDefaultRunLoopMode]];
>>        } else {
>>            goto error;
>>        }
>>    }
>>    return;
>> 
>> error:
>>    // Bad response.
>>    [self.client URLProtocol:self didFailWithError:[NSError 
>> errorWithDomain:NSURLErrorDomain code:NSURLErrorResourceUnavailable 
>> userInfo:nil]];
>> }
> 
> I thought using “nil” instead of the big expression calculating the encoding 
> string would make a difference. It didn’t.

— 
Daryle Walker
Mac, Internet, and Video Game Junkie
darylew AT mac DOT com 


 _______________________________________________
Do not post admin requests to the list. They will be ignored.
Macnetworkprog mailing list      (Macnetworkprog@lists.apple.com)
Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/macnetworkprog/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to