Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UIWebView slow loading using NSUrlProtocol Xamarin.Forms

I'm working on an iOS application using Xamarin.Forms.

This application is using UIWebView controller that shows a web application that is hosting on my server. Each time that I make a request I have to send a custom header in order to identify that this request comes to the mobile application and not from a browser, to do this I'm using an NSUrlProtocol object that overrides the method Request that inserts the custom header on each request.This is my code:

    public override NSUrlRequest Request {
        get {
            NSMutableDictionary headers = null;
            if (null == base.Request.Headers) {
                headers = new NSMutableDictionary ();
            } else {
                headers = new NSMutableDictionary (base.Request.Headers);
            }
            headers.Add(NSObject.FromObject(AppVariables.headerVariable), NSObject.FromObject (AppVariables.appVersion));
            NSMutableUrlRequest newRequest = (NSMutableUrlRequest)base.Request.MutableCopy ();
            newRequest.Headers = headers;
            return newRequest;
        }
    }

The problem that I have right now is that I noticed since I started using the NSUrlProtocol the loading time of the pages is increasing a lot. Right now the loading is taking 10 seconds, before this implementation the page took 3 seconds approximately.

Can anyone please point out some helpful direction to overcome this??

like image 943
avmauricio Avatar asked Feb 29 '16 22:02

avmauricio


1 Answers

I don't see any reasons for the delay in response time when you're using custom headers. Like Andreas mentioned in the comments, I believe it has to do with your server code. I would recommend profiling your server code.

Do you see similar results when you send the requests (with custom headers) from Fiddler or cURL?

like image 116
Prashant Cholachagudda Avatar answered Oct 16 '22 11:10

Prashant Cholachagudda