Does NSURLSession send user-agent automatically when user WatchKit 2.0, iOS 9.0? Is there a way to verify this within the WatchKit app?
相关问题
- Swift: Parsing JSON Dictionary Values
- WCSession Failing to Activate
- Detecting swipes on all four directions on WatchKi
- ios9 self signed certificate and app transport sec
- Wat is the difference between static notification
相关文章
- Is a unicode user agent legal inside an HTTP heade
- is there a “rails” way to redirect if mobile brows
- how to parse user agent string? python
- Using the device simulator for iOS 8 with Xcode 7
- How can I set the backgroundColor of a WKInterface
- How to avoid this error: “Took too long to show cu
- handleEventsForBackgroundURLSession never called w
- NSURLSession post : difference between uploadTask
Related to your question, note that it is possible to manually set the
User-Agent
string for yourNSURLSession
in WatchKit, using aNSURLSessionConfiguration
object and setting HTTPAdditionalHeaders.Yes, a user agent is automatically provided as part of the default session configuration.
The default
NSURLSession
request headerUser-Agent
field includes the Bundle Name (CFBundleName
) and the Build Number (CFBundleVersion
) of your watchOS app extension:Notice that your app's Version Number (
CFBundleShortVersionString
) isn't included. (See Technical Note TN2420: Version Numbers and Build Numbers for more info.)For example, for product "Foo" with the Build Number 1, your user agent would be:
How to Verify?
I don't think there's a way within your app to examine the default user agent field, as it's
nil
(unless you've set it to a custom value).But, you could use netcat to examine requests sent by the Simulator.
Run
nc -l 5678
in Terminal to have netcat listen to requests sent tolocalhost
on port5678
In your app's
Info.plist
file, add the App Transport Security Settings dictionary with the Allow Arbitrary Loads key set toYES
Add the following code to the start of
application(_:didFinishLaunchingWithOptions:)
Run your app in the Simulator and see what netcat outputs in Terminal
If your privacy is of no concern, you could use a service like user-agent.me to test on your device.
Replace
localhost:5678
above withuser-agent.me
Run your app on your device
Examine Xcode's Console output
When you're done verifying, remember to undo all of the changes above.