[TIMOB-7406] iOS: Set a user-agent for a webview
GitHub Issue | n/a |
Type | New Feature |
Priority | Low |
Status | Closed |
Resolution | Fixed |
Resolution Date | 2017-02-08T06:10:10.000+0000 |
Affected Version/s | Release 1.8.0.1, Release 2.1.3, Release 3.0.0 |
Fix Version/s | Release 6.1.0 |
Components | iOS |
Labels | n/a |
Reporter | Mauro Parra-Miranda |
Assignee | Vijay Singh |
Created | 2012-01-25T15:35:31.000+0000 |
Updated | 2017-02-08T21:50:31.000+0000 |
Description
PROBLEM DESCRIPTION
Some people are interested in being able to set the user-agent for the webview, just like the way we do with the HTTPClient. The usage will be similar to the HTTPClient's modification of the user-agent, but will allow more developers to connect webviews to special content, like twitter that recently doesn't allow you to create a webview of a timeline from our implementation (looks like they identify the agent as mobile, but since doesn't know which one is, it just breaks).
MORE INFO
I have seen this request often in the community.
Comments
JSON Source
Would be very useful.
Need to use this on iOS too. Perhaps this could help to fix this issue: http://stackoverflow.com/questions/8487581/uiwebview-ios5-changing-user-agent I'm testing the module from the marketplace at the moment but a native version would be nice and since its available on android it would close this gap.
It seems we can't find a way to do this that is exposed in iOS (changing NSUserDefaults isn't recommended). Has anyone been able to locate native functionality for doing so?
So here is what I would suggest: We could set the webview user-agent as part of the
Ti.setUserAgent()
method. The method is global, so it's also used for HTTP-requests and geolocation-requests. Setting it per webview would create the major problem that different webviews could have different user-agents, which is not possible, since the only way to set the user-agent in an iOS-webview is by changing the defaults for that. Let me know your thoughts on that.The only question I have is that perhaps you would need to set it differently for a webview than an HTTP request, since you might need to emulate a browser. I would be fine if it was the same for all webviews (so not per-webview, but webview is different than HTTP request).
Sure, it would just the same method in which the configuration per API is made (basically around [here](https://github.com/appcelerator/titanium_mobile/blob/master/iphone/Classes/TopTiModule.m#L49). Will propose something in the next sprint.
PR: https://github.com/appcelerator/titanium_mobile/pull/8746 I have created the property in TiUIWebView, to make parity with android. We can change the user agent with creation of new webview as in example code. In doc we can mention that this property is not per-webview (different from android). [~hansknoechel] Let me know your thought.
FR approved by [~htbryant], verified in SDK build 6.1.0.v20170206114448. Closing as fixed.