TelemetryDeck / SwiftSDK

Swift SDK for TelemetryDeck, a privacy-conscious analytics service for apps and websites.
https://telemetrydeck.com/
Other
149 stars 31 forks source link

Can `TelemetryManager` detect when running in iOS Widget? #29

Closed mflint closed 1 year ago

mflint commented 3 years ago

Description

I have code which is shared between iOS app, iOS Widget and WatchOS app - but I can't see how to differentiate between the code running as an iOS process, or an iOS Widget process.

(The same probably applies to WatchOS or WatchOS Complication)

Can something be added to the standard payload dictionary, to help?

Possible solution 1

Change the platform property to (somehow!) detect when running in an iOS Widget or WatchOS Complication.

Possible solution 2

Include the bundle identifier (Bundle.main.bundleIdentifier) in the payload dictionary.

winsmith commented 3 years ago

Thanks for the suggestion :) While this is not implemented, you can work around this by adding custom keys to .send calls from your widget code.

(And maybe there should be a like, a delegate or something that TelemetryManager can ask for a default payload)

winsmith commented 3 years ago

Created ticket #30 which will deal with default payload

Sherlouk commented 1 year ago

It is possible to detect whether code is being run from an extension by checking for Bundle.main.infoDictionary?["NSExtension"]. The contents of that object includes "NSExtensionPointIdentifier" which defines which kind of extension it is (for example "com.apple.widgetkit-extension" is for a home screen widget!)

If we sent up the extension type as part of the default payload, would/could the TelemetryDeck backend enrich this with prettified names to keep the SDK clean and future proofed?

com.apple.widgetkit-extension > WidgetKit

List of all available identifiers: https://developer.apple.com/documentation/bundleresources/information_property_list/nsextension/nsextensionpointidentifier