Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
newmediaone opened this issue Sep 13, 2016 · 4 comments · Fixed by #2769
Assignees
Milestone

Comments

@newmediaone
Copy link

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!

@NickIliev
Copy link
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

@NickIliev
Copy link
Contributor

@enchev enchev added this to the 2.4.0 milestone Sep 20, 2016
@E-Mwaurer
Copy link

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

@lock
Copy link

lock bot commented Jun 24, 2020

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.

@lock lock bot locked and limited conversation to collaborators Jun 24, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants