Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-23623] iOS: Ti.setUserAgent() doesn't exist

GitHub Issuen/a
TypeBug
PriorityHigh
StatusClosed
ResolutionFixed
Resolution Date2016-07-12T04:23:02.000+0000
Affected Version/sRelease 5.4.0
Fix Version/sRelease 6.0.0
ComponentsiOS
Labelsparity
ReporterChristopher Williams
AssigneeHans Knöchel
Created2016-07-11T19:40:26.000+0000
Updated2017-03-23T18:09:10.000+0000

Description

The documentation says that we can set Ti.userAgent via a setter method: http://docs.appcelerator.com/platform/latest/#!/api/Titanium-property-userAgent That method does not exist on iOS.

Comments

  1. Christopher Williams 2016-07-11

    https://github.com/appcelerator/titanium-mobile-mocha-suite/blob/master/Resources/ti.test.js#L76
  2. Hans Knöchel 2016-07-11

    PR: https://github.com/appcelerator/titanium_mobile/pull/8122 The demo starts three requests: 1) Using the system-default user-agent (e.g. "Appcelerator Titanium\/0.0.0 (iPhone\/9.0; iPhone OS; en_US;\)") 2) Override the default user-agent with "my-custom-user-agent" 3) Leave the current (custom) user-agent, but se the request-header "User-Agent". It will throw a warning about duplicate user-agents and the APSHTTPClient will concatenate the user-agents. Demo:
       Ti.API.warn(Ti.getUserAgent());
       
       Ti.UI.createWindow().open();
       
       // 1 ---- Use the default Appc user agent
       
       var url = "http://hans-knoechel.de/ua.php";
       var client = Ti.Network.createHTTPClient({
       	// function called when the response data is available
       	onload : function(e) {
       		Ti.API.info("First request completed");
       		Ti.API.info("Received text: " + this.responseText);
       		
       		// 2 ---- This time, set the Ti.userAgent manually.
       		
       		Ti.setUserAgent("my-custom-user-agent");
       		Ti.API.warn(Ti.getUserAgent());
       		
       		var url2 = "http://hans-knoechel.de/ua.php";
       		var client2 = Ti.Network.createHTTPClient({
       			// function called when the response data is available
       			onload : function(e) {
       				Ti.API.info("Second request completed");
       				Ti.API.info("Received text: " + this.responseText);
       				
       				var url3 = "http://hans-knoechel.de/ua.php";
       				var client3 = Ti.Network.createHTTPClient({
       					// function called when the response data is available
       					onload : function(e) {
       						Ti.API.info("Third request completed");
       						Ti.API.info("Received text: " + this.responseText);
       					},
       					// function called when an error occurs, including a timeout
       					onerror : function(e) {
       						Ti.API.debug(e.error);
       						alert('error');
       					},
       					timeout : 5000  // in milliseconds
       				});
       				// Prepare the connection.
       				client3.open("GET", url3);
       				
       				// 3 ---- This time, override the request header inside the http client (highist prio)
       				client3.setRequestHeader('User-Agent', 'another-user-agent');
       
       				// Send the request.
       				client3.send();	
       				
       			},
       			// function called when an error occurs, including a timeout
       			onerror : function(e) {
       				Ti.API.debug(e.error);
       				alert('error');
       			},
       			timeout : 5000  // in milliseconds
       		});
       		// Prepare the connection.
       		client2.open("GET", url2);
       		// Send the request.
       		client2.send();	
       	},
       	// function called when an error occurs, including a timeout
       	onerror : function(e) {
       		Ti.API.debug(e.error);
       		alert('error');
       	},
       	timeout : 5000  // in milliseconds
       });
       
       // Prepare the connection.
       client.open("GET", url);
       // Send the request.
       client.send();
       
  3. Chee Kiat Ng 2016-07-12

    APPROVED
  4. Lee Morris 2017-03-23

    Closing ticket as fixed with reference to the above comments.

JSON Source