Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
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: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ DerivedData
*.xcuserstate
project.xcworkspace
.xcode.env.local
GoogleService-info.plist

# Android/IJ
#
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=rel~4.2.0-SNAPSHOT
KlaviyoReactNativeSdk_kotlinVersion=1.8.0
KlaviyoReactNativeSdk_minSdkVersion=23
KlaviyoReactNativeSdk_targetSdkVersion=36
Expand Down
1 change: 1 addition & 0 deletions android/settings.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ if (localPropertiesFile.exists() && localPropertiesFile.canRead()) {
substitute module("com.github.klaviyo.klaviyo-android-sdk:core") using project(":sdk:core")
substitute module("com.github.klaviyo.klaviyo-android-sdk:analytics") using project(":sdk:analytics")
substitute module("com.github.klaviyo.klaviyo-android-sdk:forms") using project(":sdk:forms")
substitute module("com.github.klaviyo.klaviyo-android-sdk:location") using project(":sdk:location")
substitute module("com.github.klaviyo.klaviyo-android-sdk:push-fcm") using project(":sdk:push-fcm")
}
}
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 @@ -300,6 +300,7 @@ function configure_pods() {
sed -i '' "/pod 'KlaviyoCore'/d" "$podfile"
sed -i '' "/pod 'KlaviyoSwift'/d" "$podfile"
sed -i '' "/pod 'KlaviyoForms'/d" "$podfile"
sed -i '' "/pod 'KlaviyoLocation'/d" "$podfile"

# Restore podspec
sed -i '' 's/\(s\.dependency "KlaviyoSwift"\) ##, "\([^"]*\)"/\1, "\2"/' "$podspec"
Expand All @@ -316,7 +317,7 @@ function configure_pods() {
echo "Commented out version constraints in $podspec for local development"

# 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
1 change: 1 addition & 0 deletions example/android/settings.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ if (localPropertiesFile.exists() && localPropertiesFile.canRead()) {
substitute module("com.github.klaviyo.klaviyo-android-sdk:core") using project(":sdk:core")
substitute module("com.github.klaviyo.klaviyo-android-sdk:analytics") using project(":sdk:analytics")
substitute module("com.github.klaviyo.klaviyo-android-sdk:forms") using project(":sdk:forms")
substitute module("com.github.klaviyo.klaviyo-android-sdk:location") using project(":sdk:location")
substitute module("com.github.klaviyo.klaviyo-android-sdk:push-fcm") using project(":sdk:push-fcm")
}
}
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"];

// 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')

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