-
Notifications
You must be signed in to change notification settings - Fork 446
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 SwiftUI lifecycle install example code #9721
Conversation
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
re: #9710 |
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.
LGTM!
We also planned for reworking the sample projects which we can then link in these docs
import PostHog | ||
|
||
@main | ||
struct YourGreatApp: App { |
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.
There are more ways to do this, for example:
struct YourGreatApp: App { | |
struct YourGreatApp: App { | |
@UIApplicationDelegateAdaptor(AppDelegate.self) var appDelegate | |
init() {} |
and then:
class AppDelegate: NSObject, UIApplicationDelegate {
func application(_: UIApplication, didFinishLaunchingWithOptions _: [UIApplication.LaunchOptionsKey: Any]? = nil) -> Bool {
// init posthog
return true
}
}
Maybe add a comment that they can also use (or already use) the UIApplicationDelegateAdaptor
, they can place the code inside the application
method? or even another tab using the delegate?
@ioannisj might have other ideas.
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.
Oh I do like the thought of one more tab so we cover all the common cases:
- UIKit
- SwiftUI App init()
- UIApplicationDelegateAdaptor
Minimal mental friction for whichever setup you’re using.
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.
Okay I will work this up later today, test it, and add it in, tysm!
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.
I think just mentioning UIApplicationDelegate
and SwiftUI app init()
should be enough for a developer. Developers who use UIApplicationDelegate
in their SwiftUI apps already know how to connect the two - plus there are so many ways to bootstrap an iOS app that I think it's not practical to cover them all
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.
We can maybe mention that SDK init should go in your app init code, which is usually...
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.
How about amending the comment in the above screenshot to read:
// Add PostHog to your app's initializer.
// If using UIApplicationDelegateAdaptor, see the UIKit tab.
Would that get us there?
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.
Yeah, I think I prefer this alternative actually 👍
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.
Sold! 👨🏻⚖️
Thank you both!
@ioannisj hit me up if I can provide any backup there! |
// usually 'https://us.i.posthog.com' or 'https://eu.i.posthog.com' | ||
let POSTHOG_HOST = "<ph_client_api_host>" | ||
|
||
let config = PostHogConfig(apiKey: POSTHOG_API_KEY, host: POSTHOG_HOST) |
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.
let config = PostHogConfig(apiKey: POSTHOG_API_KEY, host: POSTHOG_HOST) | |
let config = PostHogConfig(apiKey: POSTHOG_API_KEY, host: POSTHOG_HOST) // TIP: host is optional if you use https://us.i.posthog.com |
docs render the TIP
nicely
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.
@daniloc I think you missed this one, one of them has the TIP and the other one not
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.
@marandaneto oop, automerge snared me before I saw this. I will fix!
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.
left a comment otherwise LGTM, thanks!
Changes
Many folks new to iOS will bypass UIKit and AppDelegate entirely, as Apple's project templates lean heavily into the SwiftUI-based lifecycle. This pull adds a tab with this variant.
Tested successfully in simulator.