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

User-Agent is localized #1269

Closed
onmyway133 opened this issue May 24, 2016 · 7 comments
Closed

User-Agent is localized #1269

onmyway133 opened this issue May 24, 2016 · 7 comments
Assignees
Milestone

Comments

@onmyway133
Copy link

onmyway133 commented May 24, 2016

Hi, I see that User-Agent in Manager https://github.com/Alamofire/Alamofire/blob/master/Source/Manager.swift#L64 is localized

because of this

let os = NSProcessInfo.processInfo().operatingSystemVersionString

The operating system version string is human readable, localized, and is appropriate for displaying to the user. This string is not appropriate for parsing.

is this good?

@cnoon
Copy link
Member

cnoon commented May 25, 2016

Great question @onmyway133! We'll have to do some investigation here and get back to you.

@cnoon
Copy link
Member

cnoon commented May 25, 2016

cc @jshier, @AnthonyMDev, @kcharwood

@jshier
Copy link
Contributor

jshier commented May 25, 2016

Probably not a good idea, as Apple's docs explicitly call out not using the value for parsing. Manually creating the version string from operatingSystemVersion seems like a better solution.

@cnoon
Copy link
Member

cnoon commented Jun 4, 2016

I agree @jshier. I'll work on putting together a fix.

@bgerstle
Copy link

bgerstle commented Jun 9, 2016

We've discovered this as well in our own internal attempts to set headers w/ the current OS version. Has anyone had success actually getting NSProcessInfo.operatingSystemVersionString to output a string with a different locale? I've tried using Xcode scheme language options and the launch arguments (-AppleLocale and -AppleLanguages) to no avail. Of course I also tried changing my Mac and iOS simulator language & region settings with no luck.

@onmyway133
Copy link
Author

This is my temp solution

public static let osInfo: (version: String, build: String) = {
    let version = UIDevice.currentDevice().systemVersion

    var build = ""
    let os = NSProcessInfo.processInfo().operatingSystemVersionString
    let regex = try? NSRegularExpression(pattern: "\\(.*\\)", options: [])
    if let range = regex?.firstMatchInString(os, options: [], range: NSRange(location: 0, length: os.characters.count))?.range {
      let parts = (os as NSString).substringWithRange(range)
        .replace("(", with: "")
        .replace(")", with: "")
        .split(" ")

      if parts.count == 2 {
        build = parts[1]
      }
    }

    return (version: version, build: build)
  }()

@cnoon
Copy link
Member

cnoon commented Jun 12, 2016

I'm going to close this issue out since @jshier has put together a fix in #1292. Please redirect all future comments to #1292.

Cheers. 🍻

@cnoon cnoon closed this as completed Jun 12, 2016
@cnoon cnoon modified the milestones: 3.5.0, 3.4.1 Jun 12, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants