UIWebView slow loading using NSUrlProtocol Xamarin.Forms
Asked Answered
I

2

11

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??

Imena answered 29/2, 2016 at 22:42 Comment(1)
Do you know where the extra time (the extra 7 seconds) are spent? Are they spent on the server or in the app? If you run the web application in a browser (if that is possible) and manipulating the header (e.g. in Chrome Developer Tools or Postman Chrome extension), do you also have the delay in a web browser?Lotze
R
1

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?

Rapids answered 1/4, 2016 at 6:38 Comment(0)
A
0

Just like @AndreasPaulsson and @prashant had mentioned, server might be the culprit. I would recommend testing the API with tools like Postman and check the response speed. I would also recommend you to check ModernHttpClient by Paul C Betts. In iOS the library uses NSUrlSession.

Adversaria answered 5/4, 2016 at 5:14 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.