Recently, bloggers found a strange problem in weex projects. They reported the following errors:

1.[__NSPlaceholderDictionary initWithObjects:forKeys:count:]: attempt to insert nil object from objects[0]
2.<Weex>[info]WXBridgeContext.m:552, No send queue for instance:<WXSDKInstance: 0x7ff1645261d0; id = 0; rootView = (null); url= (null)>, may it has been destroyed so method:fireEvent is ignored
3.<Weex>[error]WXSDKInstance.m:149, Url must be passed if you use renderWithURL
Copy the code

The code for loading index.js looks like this:

WXDemoViewController *demo = [[WXDemoViewController alloc] init]; demo.url = [NSURL URLWithString:[NSString stringWithFormat:@"file://%@/index.js",[NSBundle mainBundle].bundlePath]]; UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:demo]; [[UIApplication sharedApplication] delegate].window.rootViewController = nav; AbsoluteString = [self testURL: [self. URL absoluteString]]; NSString *randomURL = [NSString stringWithFormat:@"%@%@random=%d",URL.absoluteString,URL.query?@"&":@"?",arc4random()]; [_instance renderWithURL:[NSURL URLWithString:randomURL] options:@{@"bundleUrl":randomURL} data:nil];Copy the code

Weex Platform add ios to add, Weex run ios to view, you can also open target in the generated project to run view.

Weex Platform Add ios = weeX Platform add ios = WEEX Platform add ios = WEEX Platform add ios

[_instance renderWithURL:[NSURL URLWithString:self.url] options:@{@"bundleUrl":self.url.absoluteString} data:nil]; //urlStr = [NSString stringWithFormat:@"file://%@/index.js",[NSBundle mainBundle]. BundlePath]; [_instance renderWithURL:[NSURL URLWithString:urlStr] options:@{@"bundleUrl":urlStr} data:nil];Copy the code

[NSURL URLWithString:urlStr] [NSURL URLWithString:urlStr] [NSURL URLWithString:urlStr] [NSURL URLWithString:urlStr] [NSURL URLWithString:urlStr] You can see that the culprit is url=nil. But obviously the URL shouldn’t be empty, so that’s weird.

Void renderWithURL:(NSURL *)url options:(NSDictionary *)options data:(id)data {if (! url) { WXLogError(@"Url must be passed if you use renderWithURL"); return; } self.needValidate = [[WXHandlerFactory handlerForProtocol:@protocol(WXValidateProtocol)] needValidate:url]; WXResourceRequest *request = [WXResourceRequest requestWithURL:url resourceType:WXResourceTypeMainBundle referrer:@"" cachePolicy:NSURLRequestUseProtocolCachePolicy]; [self _renderWithRequest:request options:options data:data]; [WXTracingManager startTracingWithInstanceId:self.instanceId ref:nil className:nil name:WXTNetworkHanding phase:WXTracingBegin functionName:@"renderWithURL" options:@{@"bundleUrl":url?[url absoluteString]:@"",@"threadName":WXTMainThread}]; - (void)executeJsMethod:(WXCallJSMethod *)method {WXAssertBridgeThread(); if (! method.instance) { WXLogError(@"Instance doesn't exist!" ); return; } NSMutableArray *sendQueue = self.sendQueue[method.instance.instanceId]; //sendQueue became nil for no reason at all. sendQueue) { WXLogInfo(@"No send queue for instance:%@, may it has been destroyed so method:%@ is ignored", method.instance, method.methodName); return; } [sendQueue addObject:method]; [self performSelector:@selector(_sendQueueLoop) withObject:nil]; }Copy the code

After the above exploration, it seems to be related to instance and URL, so try to write the URL directly in the loading place:

    NSString *bundleUrl = [NSURL fileURLWithPath:[NSString stringWithFormat:@"%@/index.js",[NSBundle mainBundle].bundlePath]].absoluteString;
    [_instance renderWithURL:[NSURL URLWithString:bundleUrl] options:@{@"bundleUrl":bundleUrl} data:nil];
Copy the code

Found the question that has baffled blogger fast two days so resolved, the final conclusion is that there is no conclusion, may when initializing the SDK has a time lag, some things not good initialization, absolutely impossible because property values become nil ah, maybe this writing is only an expedient measure, but it really solved the problem, Let’s keep it that way until we hear back from the authorities. We will update as soon as we know.

In addition, there is another cause of this problem, your URL has Chinese, need to transcode:

[urlStr stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
Copy the code