0

i try to request on my application via this url

http://reader.mac.com/mobile/v1/http%3A%2F%2Ffeeds.feedburner.com%2F9To5Mac-MacAllDay

and it also return that it available on iPhone only

how can i fix it?

mycode

NSMutableURLRequest *urlRequest = [[NSMutableURLRequest alloc] initWithURL: [NSURL URLWithString: myurl]];
    [urlRequest setValue: @"iPhone" forHTTPHeaderField: @"Mozilla/5.0 (iPhone; U; CPU iPhone OS 3_0 like Mac OS X; en-us) AppleWebKit/528.18 (KHTML, like Gecko) Version/4.0 Mobile/7A341 Safari/528.16"];
    [self.myWebView loadRequest:urlRequest];
RAGOpoR
  • 8,118
  • 19
  • 64
  • 97

2 Answers2

1

UIWebView actually resets the user agent of the request just before it loads the URL. So, you may need to do method swizzling to actually change the user agent string that UIWebView loads in. Be warned, method swizzling could be dangerous.

There's a post that has the code for this.

Community
  • 1
  • 1
William Niu
  • 15,798
  • 7
  • 53
  • 93
0

The name of the http header field is User-Agent. Try this:

    [urlRequest setValue: @"Mozilla/5.0 (iPhone; U; CPU iPhone OS 3_0 like Mac OS X; en-us) AppleWebKit/528.18 (KHTML, like Gecko) Version/4.0 Mobile/7A341 Safari/528.16" 
      forHTTPHeaderField: @"User-Agent"];
MacTouch
  • 709
  • 1
  • 9
  • 18
  • thanks MacTouch but it also not work, the url return that my request are not from iPhone. – RAGOpoR Apr 06 '10 at 13:57
  • I tried it by myself. UIWebView seems to ignore request header field changes. Setting the User-Agent-Field in the WebViewDelegate (shouldStartLoadWithRequest) or using a subclass of NSMutableURLRequest which ignores changes to User-Agent did not work. Hmmm... no idea what else to do. Maybe you could load the contents of the url into a temporary file(s) and then point UIWebView to the location where it is placed using file:// url (see UIWebView#loadHTMLString and UIWebView#loadData). – MacTouch Apr 06 '10 at 19:29
  • thanks again MacTouch, anyway i dont know why i just use FireFox it can switch user agent as iPhone and it can open that URL. – RAGOpoR Apr 07 '10 at 02:41