You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hello
In Manager.defaultHTTPHeaders print out the userAgent
// User-Agent Header; see https://tools.ietf.org/html/rfc7231#section-5.5.3
let userAgent: String = {
if let info = NSBundle.mainBundle().infoDictionary {
let executable = info[kCFBundleExecutableKey as String] ?? "Unknown"
let bundle = info[kCFBundleIdentifierKey as String] ?? "Unknown"
let version = info[kCFBundleVersionKey as String] ?? "Unknown"
let os = NSProcessInfo.processInfo().operatingSystemVersionString ?? "Unknown"
var mutableUserAgent = NSMutableString(string: "\(executable)/\(bundle) (\(version); OS \(os))") as CFMutableString
let transform = NSString(string: "Any-Latin; Latin-ASCII; [:^ASCII:] Remove") as CFString
if CFStringTransform(mutableUserAgent, UnsafeMutablePointer<CFRange>(nil), transform, false) {
return mutableUserAgent as String
}
}
return "Alamofire"
}()
print("useragent__\(userAgent)")
return ["Accept-Encoding": acceptEncoding, "Accept-Language": acceptLanguage, "User-Agent": userAgent]
the output useragent__Optional(Hello)/Optional(com.test.Hello) (Optional(1); OS Version 9.2 (Build 13C75))
It turns out that the executable, bundle, version is Optional info[kCFBundleExecutableKey as String] as? String ?? "Unknown"
will be ok
xcode 7.2.1 iOS 9.2.1
ignore me if you already know that^^
The text was updated successfully, but these errors were encountered:
Hmmmm...doesn't seem possible @shlowdy. The type on userAgent is String, not String?. Also, I haven't seen the optional arguments in the User-Agent header before.
Sorry about the title.
The userAgent is String indeed.
What I mean is these three let executable = info[kCFBundleExecutableKey as String] ?? "Unknown" let bundle = info[kCFBundleIdentifierKey as String] ?? "Unknown" let version = info[kCFBundleVersionKey as String] ?? "Unknown"
they are optional
If you do this let executable: String = info[kCFBundleExecutableKey as String] ?? "Unknown"
you will get a error
Ah...thanks for clarifying @shlowdy. I definitely see what you mean. The logic works fine as is, since it's using either the AnyObject coming from the dictionary or defaulting to a String which is then stored as a String. Then, when substituting into the new mutable string, each AnyObject's `description is used to build the final String. All this logic works correctly, but can be a bit misleading.
In order to simplify, I just pushed 3052587 to make things a bit easier to digest. Hopefully that helps clarify things.
Hello
In Manager.defaultHTTPHeaders print out the userAgent
the output
useragent__Optional(Hello)/Optional(com.test.Hello) (Optional(1); OS Version 9.2 (Build 13C75))
It turns out that the executable, bundle, version is Optional
info[kCFBundleExecutableKey as String] as? String ?? "Unknown"
will be ok
xcode 7.2.1 iOS 9.2.1
ignore me if you already know that^^
The text was updated successfully, but these errors were encountered: