This is the javascript that will accomplish what you want:
var myCustomViewport = 'width=320px';
var viewportElement = document.querySelector('meta[name=viewport]');
if (viewportElement) {
viewportElement.content = myCustomViewport;
} else {
viewportElement = document.createElement('meta');
viewportElement.name = 'viewport';
viewportElement.content = myCustomViewport;
document.getElementsByTagName('head')[0].appendChild(viewportElement);
}
For your use case:
NSString* viewPortjs = [NSString stringWithFormat:@"var myCustomViewport = 'width=%dpx'; var viewportElement = document.querySelector('meta[name=viewport]');if (viewportElement) {viewportElement.content = myCustomViewport;} else {viewportElement = document.createElement('meta'); viewportElement.name = 'viewport'; viewportElement.content = myCustomViewport; document.getElementsByTagName('head')[0].appendChild(viewportElement);}", (int) webView.frame.size.width];