-
Notifications
You must be signed in to change notification settings - Fork 5
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
Add common headers for Platform, SDK version, Source app #455
Changes from all commits
b812ffe
ee92292
f8e5e74
616cf2a
bf618c8
e8804d9
07fa931
d22794f
2e1a915
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import Foundation | ||
|
||
#if !SWIFT_PACKAGE | ||
private class BundleFinder: NSObject {} | ||
extension Bundle { | ||
static var module: Bundle { | ||
let defaultBundle = Bundle(for: BundleFinder.self) | ||
// If installed with CocoaPods, resources will be in Gravatar.bundle | ||
// The name of the bundle "Gravatar.bundle" (without the .bundle file extension) | ||
// needs to match the key in the respective Gravatar.podspec: | ||
// `s.resource_bundles = { 'Gravatar' => ['Sources/Gravatar/Resources/*.plist'] }` | ||
if let bundleURL = defaultBundle.resourceURL, | ||
let resourceBundle = Bundle(url: bundleURL.appendingPathComponent("Gravatar.bundle")) | ||
{ | ||
return resourceBundle | ||
} | ||
// Otherwise, the default bundle is used for resources | ||
return defaultBundle | ||
} | ||
} | ||
#endif |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import Foundation | ||
|
||
enum BundleInfo { | ||
public static var sdkVersion: String? { | ||
getInfoValue(forKey: "CFBundleShortVersionString") as? String | ||
} | ||
|
||
public static var appName: String? { | ||
Bundle.main.object(forInfoDictionaryKey: "CFBundleName") as? String | ||
} | ||
|
||
private static func getInfoValue(forKey key: String) -> Any? { | ||
// Access the SDKInfo.plist using Bundle.module | ||
guard let url = Bundle.module.url(forResource: "SDKInfo", withExtension: "plist"), | ||
let data = try? Data(contentsOf: url), | ||
let plist = try? PropertyListSerialization.propertyList(from: data, options: [], format: nil) as? [String: Any] | ||
else { | ||
return nil | ||
} | ||
return plist[key] | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,6 +14,9 @@ struct URLSessionHTTPClient: HTTPClient { | |
let configuration = URLSessionConfiguration.default | ||
configuration.httpAdditionalHeaders = [ | ||
"Accept": "application/json", | ||
"X-Platform": "ios", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This reminds me of a separate question: do we want to track iOS/iPadOS? If so, I think we'd still treat them both as We could add a separate header like There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For now we don't want to track iOS/iPadOS and yes i agree that would be a separate header if needed. |
||
"X-SDK-Version": BundleInfo.sdkVersion ?? "", | ||
"X-Source": BundleInfo.appName ?? "", | ||
] | ||
self.urlSession = urlSession ?? URLSession(configuration: configuration) | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> | ||
<plist version="1.0"> | ||
<dict> | ||
<key>CFBundleShortVersionString</key> | ||
<string>2.1.1</string> | ||
</dict> | ||
</plist> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice.
For those visiting this in the future:
The name of the bundle
"Gravatar.bundle"
(without the.bundle
file extension) needs to match the key in the respectiveGravatar.podspec
:We happen to be using the same name ("Gravatar") for the module and the pod, too. So it's easier to get right. But the actual dependency is on the name of the resource bundle we define in the podspec.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for elaborating. This is valuable info so i added it in the code comment.