Skip to content
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

Merged
merged 5 commits into from
Oct 25, 2024

Conversation

daniloc
Copy link
Contributor

@daniloc daniloc commented Oct 24, 2024

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.

Screenshot 2024-10-24 at 12 01 37 PM

Copy link

vercel bot commented Oct 24, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Updated (UTC)
posthog ✅ Ready (Inspect) Visit Preview Oct 25, 2024 1:42pm

@daniloc
Copy link
Contributor Author

daniloc commented Oct 24, 2024

re: #9710

Copy link
Contributor

@ioannisj ioannisj left a 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 {
Copy link
Member

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:

Suggested change
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.

Copy link
Contributor Author

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.

Copy link
Contributor Author

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!

Copy link
Contributor

@ioannisj ioannisj Oct 25, 2024

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

Copy link
Contributor

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...

Copy link
Contributor Author

@daniloc daniloc Oct 25, 2024

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?

Copy link
Contributor

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 👍

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sold! 👨🏻‍⚖️

Thank you both!

@daniloc
Copy link
Contributor Author

daniloc commented Oct 25, 2024

LGTM!

We also planned for reworking the sample projects which we can then link in these docs

@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)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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

Copy link
Member

@marandaneto marandaneto Oct 26, 2024

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

Copy link
Contributor Author

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!

Copy link
Member

@marandaneto marandaneto left a 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!

@daniloc daniloc merged commit 58984b1 into master Oct 25, 2024
3 checks passed
@daniloc daniloc deleted the update-ios-install-switftui-lifecycle branch October 25, 2024 13:42
@daniloc daniloc restored the update-ios-install-switftui-lifecycle branch October 29, 2024 13:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants