This repository has been archived by the owner on Mar 22, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
Add new reserved subscriber attribute $onesignalUserId and add deprecation note to $onesignalId #408
Closed
Raquel10-RevenueCat
wants to merge
4
commits into
main
from
raquel10/fia-1538-onesignal-integration-changes
Closed
Add new reserved subscriber attribute $onesignalUserId and add deprecation note to $onesignalId #408
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
1dd36da
Add new reserved subscriber attribute and add deprecation note to
Raquel10-RevenueCat 8af99d7
Attempt to fix linter
Raquel10-RevenueCat 38386cb
Updated docs (WIP)
Raquel10-RevenueCat e7aed7e
Merge remote-tracking branch 'origin/main' into raquel10/fia-1538-one…
vegaro File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
32 changes: 32 additions & 0 deletions
32
code_blocks/🔌 Integrations & Events/third-party-integrations/onesignal_2.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -0,0 +1,32 @@ | ||||||
class AppDelegate: UIResponder, UIApplicationDelegate, OSSubscriptionObserver { | ||||||
|
||||||
var window: UIWindow? | ||||||
|
||||||
func application(_ application: UIApplication, | ||||||
didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool { | ||||||
|
||||||
Purchases.configure(withAPIKey: "<revenuecat_api_key>", appUserID: nil) | ||||||
|
||||||
OneSignal.initialize("<onesignal_app_id>", withLaunchOptions: launchOptions) | ||||||
OneSignal.add(self as OSSubscriptionObserver) | ||||||
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. I don't think this is required since
Suggested change
|
||||||
|
||||||
// If you've already set up OneSignal, then users should already have | ||||||
// a OneSignal Id. We can check if it's available and send it to RevenueCat | ||||||
if let onesignalUserId = OneSignal.User.onesignal_id { | ||||||
Purchases.shared.attribution.setOnesignalUserID(onesignalUserId) | ||||||
} | ||||||
|
||||||
return true | ||||||
} | ||||||
|
||||||
// Add this method to update the $onesignalUserId in RevenueCat whenever it changes | ||||||
// This code should be sufficient to capture all new users if you're setting | ||||||
// up OneSignal for the first time. | ||||||
func onOSSubscriptionChanged(_ stateChanges: OSSubscriptionStateChanges!) { | ||||||
if !stateChanges.from.subscribed && stateChanges.to.subscribed { | ||||||
// The user is subscribed | ||||||
// Either the user subscribed for the first time | ||||||
Purchases.shared.attribution.setOnesignalUserID(stateChanges.to.userId) | ||||||
} | ||||||
} | ||||||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 we try to not have this in quotes to force users to add the api key since that would fail to compile otherwise: