Skip to content
Merged
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
Binary file modified Leanplum-Unity-Package/Leanplum_Unity-6.1.0.unitypackage
Binary file not shown.
23 changes: 22 additions & 1 deletion Leanplum-Unity-SDK/Assets/Editor/LeanplumApplePostProcessor.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#if UNITY_EDITOR
#if UNITY_EDITOR
using UnityEditor;
using UnityEditor.Callbacks;
using UnityEditor.iOS.Xcode;
Expand All @@ -9,6 +9,7 @@ class LeanplumApplePostProcessor
{
const string ENABLE_BITCODE = "ENABLE_BITCODE";
const string NO = "NO";
const string PREPROCESSOR_MACROS = "GCC_PREPROCESSOR_DEFINITIONS";

[PostProcessBuild]
public static void OnPostprocessBuild(BuildTarget buildTarget, string path)
Expand All @@ -17,6 +18,7 @@ public static void OnPostprocessBuild(BuildTarget buildTarget, string path)
return;

DisableBitcode(path);
DisableCleverTapUnityAppController(path);
}

private static PBXProject GetPBXProject(string path, out string pbxProjectPath)
Expand All @@ -43,6 +45,25 @@ private static void DisableBitcode(string path)

pbxProject.WriteToFile(pbxProjectPath);
}

/// <summary>
/// Set the CT_NO_APP_CONTROLLER_SUBCLASS preprocessor macro.
/// This disables CleverTap's UnityAppController subclass.
/// The CleverTap initialization is handled by the Leanplum SDK.
/// Use the LeanplumUnityAppController.
/// </summary>
/// <param name="path"></param>
private static void DisableCleverTapUnityAppController(string path)
{
PBXProject pbxProject = GetPBXProject(path, out string pbxProjectPath);
var projectTarget = pbxProject.GetUnityFrameworkTargetGuid();

// The UpdateBuildProperty set the property value if no values are present. This overrides the $(inherited) value.
// Add the $(inherited) value as a workaround.
pbxProject.UpdateBuildProperty(projectTarget, PREPROCESSOR_MACROS, new string[] { "$(inherited)", "CT_NO_APP_CONTROLLER_SUBCLASS" }, null);

pbxProject.WriteToFile(pbxProjectPath);
}
}
}
#endif
14 changes: 4 additions & 10 deletions Leanplum-Unity-SDK/Assets/LeanplumSDK/Apple/LeanplumApple.cs
Original file line number Diff line number Diff line change
Expand Up @@ -208,13 +208,13 @@ public LeanplumApple()
public override event VariablesChangedAndNoDownloadsPendingHandler VariablesChangedAndNoDownloadsPending;

private event CleverTapInstanceHandler cleverTapInstanceReady;
private string accountId;
private bool cleverTapInitialized;
public override event CleverTapInstanceHandler CleverTapInstanceReady
{
add
{
cleverTapInstanceReady += value;
if (!string.IsNullOrEmpty(accountId))
if (cleverTapInitialized)
{
value?.Invoke();
}
Expand Down Expand Up @@ -815,14 +815,8 @@ public override void NativeCallback(string message)
}
else if (message.StartsWith(CLEVERTAP_INSTANCE))
{
string id = message[CLEVERTAP_INSTANCE.Length..];
if (accountId != id)
{
accountId = id;
MigrationConfig config = MigrationConfig();
CleverTapSDK.CleverTap.LaunchWithCredentialsForRegion(config.AccountId, config.AccountToken, config.AccountRegion);
cleverTapInstanceReady?.Invoke();
}
cleverTapInitialized = true;
cleverTapInstanceReady?.Invoke();
}
else if (message.StartsWith(VARIABLE_VALUE_CHANGED))
{
Expand Down
8 changes: 5 additions & 3 deletions Leanplum-Unity-SDK/Assets/Plugins/iOS/LeanplumIOSBridge.mm
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//
// Copyright (c) 2023 Leanplum. All rights reserved.
// Copyright (c) 2025 Leanplum. All rights reserved.
//
// Licensed to the Apache Software Foundation (ASF) under one
// or more contributor license agreements. See the NOTICE file
Expand Down Expand Up @@ -28,6 +28,7 @@
#import "LeanplumUnityConstants.h"
#import <Leanplum/Leanplum-Swift.h>
#import <CleverTapSDK/CleverTap.h>
#import "CleverTapUnityManager.h"

#define LEANPLUM_CLIENT @"unity-nativeios"

Expand Down Expand Up @@ -109,7 +110,8 @@ void LeanplumSetupCallbackBlocks()
}];

CleverTapInstanceCallback *callback = [[CleverTapInstanceCallback alloc] initWithCallback:^(CleverTap * _Nonnull instance) {
[LeanplumIOSBridge sendMessageToUnity:@"CleverTapInstance:" withKey:[instance getAccountID]];
[LeanplumIOSBridge sendMessageToUnity:@"CleverTapInstance:"];
[[CleverTapUnityManager sharedInstance] setCleverTapInstance:instance];
}];
[Leanplum addCleverTapInstanceCallback:callback];

Expand Down Expand Up @@ -882,4 +884,4 @@ void lp_inbox_disableImagePrefetching()
{
[[Leanplum inbox] disableImagePrefetching];
}
} // extern "C"
} // extern "C"
39 changes: 39 additions & 0 deletions Leanplum-Unity-SDK/Assets/Plugins/iOS/LeanplumUnityAppController.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
//
// Copyright (c) 2025 Leanplum. All rights reserved.
//
// Licensed to the Apache Software Foundation (ASF) under one
// or more contributor license agreements. See the NOTICE file
// distributed with this work for additional information
// regarding copyright ownership. The ASF licenses this file
// to you under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing,
// software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the License for the
// specific language governing permissions and limitations
// under the License.

#import <Foundation/Foundation.h>
#import "UnityAppController.h"
#import <UserNotifications/UserNotifications.h>

NS_ASSUME_NONNULL_BEGIN

/**
* Leanplum class that subclasses UnityAppController.
* Calls CleverTapUnityManager to send messages to CleverTap Unity when in migration.
*/
@interface LeanplumUnityAppController : UnityAppController <UNUserNotificationCenterDelegate>

@end

#if !LP_NO_APP_CONTROLLER_SUBCLASS
IMPL_APP_CONTROLLER_SUBCLASS(LeanplumUnityAppController)
#endif

NS_ASSUME_NONNULL_END

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

119 changes: 119 additions & 0 deletions Leanplum-Unity-SDK/Assets/Plugins/iOS/LeanplumUnityAppController.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
//
// Copyright (c) 2025 Leanplum. All rights reserved.
//
// Licensed to the Apache Software Foundation (ASF) under one
// or more contributor license agreements. See the NOTICE file
// distributed with this work for additional information
// regarding copyright ownership. The ASF licenses this file
// to you under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing,
// software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the License for the
// specific language governing permissions and limitations
// under the License.

#import "LeanplumUnityAppController.h"
#import "CleverTapUnityManager.h"
#import "CleverTapCustomTemplates.h"
#import <Leanplum/LeanplumInternal.h>
#import <Leanplum/Leanplum-Swift.h>

@implementation LeanplumUnityAppController

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// Register Custom Templates and App Functions in CleverTap.
// The CleverTap TemplateProducer is called when CleverTap instance is created.
[CleverTapCustomTemplates registerCustomTemplates];

[UNUserNotificationCenter currentNotificationCenter].delegate = (id <UNUserNotificationCenterDelegate>)self;

return [super application:application didFinishLaunchingWithOptions:launchOptions];
}

- (BOOL)application:(UIApplication *)app openURL:(NSURL *)url options:(NSDictionary<UIApplicationOpenURLOptionsKey,id> *)options {
// Call the CleverTapUnityManager to handle the URL if in Migration
[self handleWithCleverTapInstance:^{
[[CleverTapUnityManager sharedInstance] handleOpenURL:url];
}];
return [super application:app openURL:url options:options];
}

- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo fetchCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler {
// Check if the push notification is sent from CleverTap.
// Call CleverTapUnityManager if in Migration.
if ([self isCleverTapPushNotification:userInfo]) {
[self handleWithCleverTapInstance:^{
BOOL isOpen = application.applicationState == UIApplicationStateActive ? NO : YES;
[[CleverTapUnityManager sharedInstance] sendRemoteNotificationCallbackToUnity:userInfo isOpen:isOpen];
}];
}

[super application:application didReceiveRemoteNotification:userInfo fetchCompletionHandler:completionHandler];
}

- (void)userNotificationCenter:(UNUserNotificationCenter *)center didReceiveNotificationResponse:(UNNotificationResponse *)response withCompletionHandler:(void (^)(void))completionHandler {
NSDictionary *userInfo = response.notification.request.content.userInfo;
// Check if the push notification is sent from CleverTap.
// Call CleverTapUnityManager if in Migration.
if ([self isCleverTapPushNotification:userInfo]) {
[self handleWithCleverTapInstance:^{
[[CleverTapUnityManager sharedInstance]
sendRemoteNotificationCallbackToUnity:userInfo isOpen:YES];
}];
}
completionHandler();
}

- (void)userNotificationCenter:(UNUserNotificationCenter *)center willPresentNotification:(UNNotification *)notification withCompletionHandler:(void (^)(UNNotificationPresentationOptions))completionHandler {
NSDictionary *userInfo = notification.request.content.userInfo;
// Check if the push notification is sent from CleverTap.
// Call CleverTapUnityManager if in Migration.
if ([self isCleverTapPushNotification:userInfo]) {
[self handleWithCleverTapInstance:^{
[[CleverTapUnityManager sharedInstance] didReceiveRemoteNotification:userInfo isOpen:YES openInForeground:YES];
}];
}
completionHandler(UNNotificationPresentationOptionNone);
}

/**
* Call a block if app is in Migration.
* If CleverTap instance has launched, call the block,
* otherwise wait for Leanplum start and check if in Migration.
* @param block The block to execute.
* @remark Copies LPCTNotificationManager.handleWithCleverTapInstance logic
* which requires casting the notifications manager to LPCTNotificationManager.
*/
- (void)handleWithCleverTapInstance:(void (^)(void))block {
if ([[MigrationManager shared] hasLaunched]) {
block();
} else {
[Leanplum onStartIssued:^{
if ([[MigrationManager shared] useCleverTap]) {
block();
}
}];
}
}

/**
* Checks if a push notification is sent from CleverTap.
* @param notification The push notification user info.
* @remark Copies CleverTap:isCTPushNotification: which requires a CleverTap instance.
*/
- (BOOL)isCleverTapPushNotification:(NSDictionary *)notification {
for (NSString *key in [notification allKeys]) {
if ([key hasPrefix:@"W$"] || [key hasPrefix:@"wzrk_"]) {
return YES;
}
}
return NO;
}

@end

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

19 changes: 16 additions & 3 deletions Leanplum-Unity-SDK/Assets/Plugins/iOS/LeanplumUnityConstants.h
Original file line number Diff line number Diff line change
@@ -1,9 +1,22 @@
//
// LeanplumUnityConstants.h
// UnityFramework
// Copyright (c) 2025 Leanplum. All rights reserved.
//
// Created by Nikola Zagorchev on 29.11.22.
// Licensed to the Apache Software Foundation (ASF) under one
// or more contributor license agreements. See the NOTICE file
// distributed with this work for additional information
// regarding copyright ownership. The ASF licenses this file
// to you under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing,
// software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the License for the
// specific language governing permissions and limitations
// under the License.

#import <Foundation/Foundation.h>

Expand Down
19 changes: 16 additions & 3 deletions Leanplum-Unity-SDK/Assets/Plugins/iOS/LeanplumUnityConstants.m
Original file line number Diff line number Diff line change
@@ -1,9 +1,22 @@
//
// LeanplumUnityConstants.m
// UnityFramework
// Copyright (c) 2025 Leanplum. All rights reserved.
//
// Created by Nikola Zagorchev on 29.11.22.
// Licensed to the Apache Software Foundation (ASF) under one
// or more contributor license agreements. See the NOTICE file
// distributed with this work for additional information
// regarding copyright ownership. The ASF licenses this file
// to you under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing,
// software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the License for the
// specific language governing permissions and limitations
// under the License.

#import "LeanplumUnityConstants.h"

Expand Down