Skip to content

NativeScript IOS Apps Broadcast as iPad in UserAgent String EVEN on iPhone Using http.getJSON() #2714

Closed

Description

@newmediaone

When using http.getJSON() in a mobile app on IOS, the app sends a UserAgent of "iPad", even from an iPhone.

Which platform(s) does your issue occur on?

iOS

Please provide the following version numbers that your issue occurs with:

  • CLI: 2.1.1
  • Cross-platform modules: 2.2.0
  • Runtime(s): 2.2.1
  • Plugin(s):
    "dependencies": {
    "moment": "^2.14.1",
    "nativescript-collapsing-header": "^2.0.0",
    "nativescript-floatingactionbutton": "^2.2.4",
    "nativescript-fresco": "^1.0.5",
    "nativescript-google-analytics": "^0.2.9",
    "nativescript-pulltorefresh": "^1.1.6",
    "nativescript-snackbar": "^1.1.2",
    "nativescript-social-share": "^1.3.0",
    "tns-core-modules": "^2.2.1"
    }

Please tell us how to recreate the issue in as much detail as possible.

RUN:
http.getJSON("http://exmplesite.com") in the app code, run it on an iPhone device or IOS iPHone simulator.
Look at the access log of exmplesite.com, you'll see the UserAgent String looks something like:
"Mozilla/5.0 (iPad; CPU OS 6_0 like Mac OS X) AppleWebKit/536.26 (KHTML, like Gecko) Version/6.0 Mobile/10A5355d Safari/8536.25""Mozilla/5.0 (iPad; CPU OS 6_0 like Mac OS X) AppleWebKit/536.26 (KHTML, like Gecko) Version/6.0 Mobile/10A5355d Safari/8536.25"

Where "iPad" is shown, this should be "iPhone". (When loading a webview, the user agent string is correct from an iPhone, so it appears the issue is NOT happen on a webview, but IS happening using the http.getJSON() function.)

THANKS!

Activity

  1. NickIliev commented on Sep 14, 2016

    @NickIliev
    Contributor

    Hello @newmediaone

    Indeed the http module is setting the user-agent as iPad.
    You can however, send your own custom user agent.

    e.g.

        http.request({
            url: "https://httpbin.org/user-agent",
            method: "GET",
            headers: { "Content-Type": "application/json", "User-Agent": "My-Custom-User-Agent" },
            content: JSON.stringify({ MyVariableOne: "ValueOne", MyVariableTwo: "ValueTwo" })
        }).then(function (response) {
            var result = response.content.toJSON();
            console.log(result["user-agent"]); // My-Custom-User-Agent
        }, function (e) {
            // console.log("Error occurred " + e);
        });   
    

    Of course, you can provide some meaningful information in your user-agent string using this

  2. self-assigned this
    on Sep 14, 2016
  3. added this to the 2.4.0 milestone on Sep 20, 2016
  4. E-Mwaurer commented on Jun 25, 2019

    @E-Mwaurer

    How do i get the user agent details of my cross platform app built with nativescript. Any help is highly appreciated

  5. lock commented on Jun 24, 2020

    @lock

    This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

  6. locked and limited conversation to collaborators on Jun 24, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions