Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
b56cadd
Modify permissions library
belleklaviyo Sep 2, 2025
9c2f5b3
Add bridging to test mock API call
belleklaviyo Sep 2, 2025
d04d131
Removed unused react-native-permissions library
belleklaviyo Sep 2, 2025
635a2da
Oh we don't need react-native-geolocation-service either
belleklaviyo Sep 2, 2025
5ed098c
Merge branch 'master' into bl/spike/geofencing-bridging
belleklaviyo Oct 31, 2025
a2baba4
Merge branch 'feat/geofencing' into bl/spike/geofencing-bridging
belleklaviyo Nov 3, 2025
98624f8
Rename registerForGeofences to registerGeofencing
belleklaviyo Nov 3, 2025
7c61165
Bridge unregister method
belleklaviyo Nov 3, 2025
d7ae33d
Add permission prompting through react-native-permissions, add to exa…
belleklaviyo Nov 4, 2025
96d7dc2
Support location services in terminated state
belleklaviyo Nov 4, 2025
b96670e
Only bridge background monitor method to objc, not RN
belleklaviyo Nov 4, 2025
2363dcb
Point to swift SDK feat/geofencing
belleklaviyo Nov 4, 2025
01de64b
Remove duplicate setup_permissions
belleklaviyo Nov 4, 2025
685595d
Bridged android methods (#283)
evan-masseau Nov 12, 2025
4ace88a
dispatch to main thread, update pods
belleklaviyo Nov 12, 2025
9168d24
Remove permissions from Android manifest
belleklaviyo Nov 12, 2025
620887c
Add dispatch to main
belleklaviyo Nov 12, 2025
4274a7d
Remove redundant script loading
belleklaviyo Nov 12, 2025
bcf9559
Unversion dependencies
belleklaviyo Nov 13, 2025
cb840f7
Point to updated feat/geofencing swift branch
belleklaviyo Nov 17, 2025
62809aa
fix path for CI
belleklaviyo Nov 17, 2025
03bbef6
Use Task in KlaviyoBridge async calls
belleklaviyo Nov 17, 2025
f4f7221
Bridge getCurrentGeofences
belleklaviyo Nov 18, 2025
0a9bed4
Point pods to feat/geofencing
belleklaviyo Nov 19, 2025
fca51fc
Fix async calls
belleklaviyo Nov 19, 2025
066427c
Fix getCurrentGeofences in KlaviyoBridge
belleklaviyo Nov 20, 2025
3cd9544
Added android "getCurrentGeofences" bridge function, tagged it internal
Nov 20, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -407,7 +407,6 @@ native code. Note that either of these approaches is sufficient to inform the Kl

2. **Native Notification Permission**:
Follow instructions from our native SDK documentation to request permission from native code:

- [Android](https://github.com/klaviyo/klaviyo-android-sdk#collecting-push-tokens)
- [iOS](https://github.com/klaviyo/klaviyo-swift-sdk?tab=readme-ov-file#request-push-notification-permission)

Expand Down
1 change: 1 addition & 0 deletions android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ dependencies {
api "com.github.klaviyo.klaviyo-android-sdk:analytics:$klaviyoAndroidSdkVersion"
api "com.github.klaviyo.klaviyo-android-sdk:push-fcm:$klaviyoAndroidSdkVersion"
api "com.github.klaviyo.klaviyo-android-sdk:forms:$klaviyoAndroidSdkVersion"
api "com.github.klaviyo.klaviyo-android-sdk:location:$klaviyoAndroidSdkVersion"
implementation "com.github.klaviyo.klaviyo-android-sdk:core:$klaviyoAndroidSdkVersion"

// We used reflection to enumerate keywords in the Klaviyo Android SDK dynamically
Expand Down
2 changes: 1 addition & 1 deletion android/gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryErro
# http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
# org.gradle.parallel=true
#Tue Dec 19 15:08:27 EST 2023
KlaviyoReactNativeSdk_klaviyoAndroidSdkVersion=4.1.0
KlaviyoReactNativeSdk_klaviyoAndroidSdkVersion=68d7123
KlaviyoReactNativeSdk_kotlinVersion=1.8.0
KlaviyoReactNativeSdk_minSdkVersion=23
KlaviyoReactNativeSdk_targetSdkVersion=36
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.klaviyoreactnativesdk

import com.facebook.react.bridge.Arguments
import com.facebook.react.bridge.Callback
import com.facebook.react.bridge.ReactApplicationContext
import com.facebook.react.bridge.ReactContextBaseJavaModule
Expand All @@ -20,6 +21,9 @@ import com.klaviyo.core.utils.AdvancedAPI
import com.klaviyo.forms.InAppFormsConfig
import com.klaviyo.forms.registerForInAppForms
import com.klaviyo.forms.unregisterFromInAppForms
import com.klaviyo.location.LocationManager
import com.klaviyo.location.registerGeofencing
import com.klaviyo.location.unregisterGeofencing
import java.io.Serializable
import kotlin.reflect.KVisibility
import kotlin.time.Duration.Companion.seconds
Expand Down Expand Up @@ -87,6 +91,41 @@ class KlaviyoReactNativeSdkModule(
}
}

@ReactMethod
fun registerGeofencing() {
Klaviyo.registerGeofencing()
}

@ReactMethod
fun unregisterGeofencing() {
Klaviyo.unregisterGeofencing()
}

@ReactMethod
fun getCurrentGeofences(callback: Callback) {
// Note: in the future, we may be storing more fences than we are observing, so we'd have to update this
val geofencesArray = Arguments.createArray()
Registry.getOrNull<LocationManager>()?.getStoredGeofences()?.forEach { geofence ->
geofencesArray.pushMap(
Arguments.createMap().apply {
putString("identifier", geofence.id)
putDouble("latitude", geofence.latitude)
putDouble("longitude", geofence.longitude)
putDouble("radius", geofence.radius.toDouble())
},
)
} ?: run {
Registry.log.wtf("Geofencing is not yet registered")
}

val resultMap =
Arguments.createMap().apply {
putArray("geofences", geofencesArray)
}

callback.invoke(resultMap)
}

@ReactMethod
fun setProfile(profile: ReadableMap) {
val parsedProfile = Profile()
Expand Down
3 changes: 2 additions & 1 deletion configure-sdk.sh
Original file line number Diff line number Diff line change
Expand Up @@ -50,14 +50,15 @@ function configure_podfile() {
sed -i '' "/pod 'KlaviyoCore'/d" "$podfile"
sed -i '' "/pod 'KlaviyoSwift'/d" "$podfile"
sed -i '' "/pod 'KlaviyoForms'/d" "$podfile"
sed -i '' "/pod 'KlaviyoLocation'/d" "$podfile"

if [[ -z "$swift_sdk_version" || "$swift_sdk_version" == "podspec" ]]; then
echo "Skipping Swift SDK version update."
return
fi

# List of dependencies
dependencies=("KlaviyoCore" "KlaviyoSwift" "KlaviyoForms")
dependencies=("KlaviyoCore" "KlaviyoSwift" "KlaviyoForms" "KlaviyoLocation")

# Find the line number of the target block
target_line=$(grep -n "# Insert override klaviyo-swift-sdk pods below this line when needed" "$podfile" | cut -d: -f1)
Expand Down
5 changes: 5 additions & 0 deletions example/ios/KlaviyoReactNativeSdkExample/AppDelegate.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@
#import <UIKit/UIKit.h>
#import <UserNotifications/UserNotifications.h>
#import "KlaviyoReactNativeSdkExample-Swift.h"
#if __has_include(<klaviyo_react_native_sdk/klaviyo_react_native_sdk-Swift.h>)
#import <klaviyo_react_native_sdk/klaviyo_react_native_sdk-Swift.h>
#else
#import "klaviyo_react_native_sdk-Swift.h"
#endif

// iOS Installation Step 1: Conform AppDelegate to UNUserNotificationCenterDelegate
@interface AppDelegate: RCTAppDelegate <UNUserNotificationCenterDelegate>
Expand Down
7 changes: 6 additions & 1 deletion example/ios/KlaviyoReactNativeSdkExample/AppDelegate.mm
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ - (BOOL)application:(UIApplication *)application
// iOS Installation Step 3: Initialize the SDK with public key, if
// initializing from native code Exclude if initializing from react native
// layer
[PushNotificationsHelper initializeSDK:@"Xr5bFG"];
[PushNotificationsHelper initializeSDK:@"YOUR_KLAVIYO_PUBLIC_API_KEY"];
Copy link
Contributor Author

Choose a reason for hiding this comment

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

just cleaning this up, guess this has been in here for a while

Copy link
Contributor

Choose a reason for hiding this comment

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

Lol, @ajaysubra maybe that's why your company had so many profiles...

Copy link
Collaborator

Choose a reason for hiding this comment

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

🤦🏽‍♂️

Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe a github action or pre-commit rule could help us avoid doing that again


// iOS Installation Step 4: Request notification permission from the user
// Exclude if handling permissions from react native layer
Expand All @@ -33,6 +33,11 @@ - (BOOL)application:(UIApplication *)application
// Initialize cross-platform push library, e.g. Firebase
}

// Start monitoring geofences from background
dispatch_async(dispatch_get_main_queue(), ^{
[KlaviyoBridge monitorGeofencesFromBackground];
});

// refer to installation step 16 below
NSMutableDictionary *launchOptionsWithURL =
[self getLaunchOptionsWithURL:launchOptions];
Expand Down
11 changes: 10 additions & 1 deletion example/ios/KlaviyoReactNativeSdkExample/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,19 @@
<key>NSAllowsLocalNetworking</key>
<true/>
</dict>
<key>NSLocationAlwaysAndWhenInUseUsageDescription</key>
<string>We need access to your location at all times to provide geofencing features, including when the app is in the background.</string>
<key>NSLocationAlwaysUsageDescription</key>
<string>We need access to your location at all times to provide geofencing features, including when the app is in the background.</string>
<key>NSLocationWhenInUseUsageDescription</key>
<string></string>
<string>We use your location to provide location-based features and geofencing.</string>
<key>RCTNewArchEnabled</key>
<true/>
<key>UIBackgroundModes</key>
<array>
<string>location</string>
<string>fetch</string>
</array>
<key>UILaunchStoryboardName</key>
<string>LaunchScreen</string>
<key>UIRequiredDeviceCapabilities</key>
Expand Down
28 changes: 21 additions & 7 deletions example/ios/Podfile
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
# Resolve react_native_pods.rb with node to allow for hoisting
require Pod::Executable.execute_command('node', ['-p',
'require.resolve(
"react-native/scripts/react_native_pods.rb",
{paths: [process.argv[1]]},
)', __dir__]).strip
def node_require(script)
require Pod::Executable.execute_command('node', ['-p',
"require.resolve(
'#{script}',
{paths: [process.argv[1]]},
)", __dir__]).strip
end

node_require('react-native/scripts/react_native_pods.rb')
node_require('react-native-permissions/scripts/setup.rb')
Copy link
Contributor Author

Choose a reason for hiding this comment

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

these podfile changes were necessary for the react-native-permissions library per this documentation

Copy link
Contributor

Choose a reason for hiding this comment

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

Wonder if we should update the example app to use this for push permissions too. Not blocking for this PR though. Maybe I could take a look at it in the UI overhaul branch I have in draft.


platform :ios, min_ios_version_supported
prepare_react_native_project!


linkage = ENV['USE_FRAMEWORKS']
if linkage != nil
Pod::UI.puts "Configuring Pod with #{linkage}ally linked Frameworks".green
Expand All @@ -21,6 +24,17 @@ target 'KlaviyoReactNativeSdkExample' do
use_frameworks! :linkage => :static

# Insert override klaviyo-swift-sdk pods below this line when needed
# Using remote branch feat/geofencing from GitHub
pod 'KlaviyoCore', :git => 'https://github.com/klaviyo/klaviyo-swift-sdk.git', :branch => 'feat/geofencing'
pod 'KlaviyoSwift', :git => 'https://github.com/klaviyo/klaviyo-swift-sdk.git', :branch => 'feat/geofencing'
pod 'KlaviyoForms', :git => 'https://github.com/klaviyo/klaviyo-swift-sdk.git', :branch => 'feat/geofencing'
pod 'KlaviyoLocation', :git => 'https://github.com/klaviyo/klaviyo-swift-sdk.git', :branch => 'feat/geofencing'

# Setup permissions for react-native-permissions
setup_permissions([
'LocationWhenInUse',
'LocationAlways',
])

use_react_native!(
:path => config[:reactNativePath],
Expand Down
Loading
Loading